Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
detector_stream.h
Go to the documentation of this file.
1#pragma once
2#include <Windows.h>
3#include <memory>
4#include <string>
5#include <vector>
6#include <nlohmann/json.hpp>
7
8// Fan-out of logged events to PanoptesDetector over the SubscribeEvents RPC.
9//
10// The driver and hook event threads log through RecordEvent, which numbers each event, writes
11// it to pano.log and queues it for every subscriber. Each subscriber has a bounded queue; when
12// it is full the event is dropped for that subscriber rather than blocking the event threads,
13// and the gap in the sequence numbers tells the detector events were lost.
14//
15// The sequence number is the event's "Seq" in pano.log, so a detection's EventSequences name
16// the exact log lines it matched. It starts at the service's start time in microseconds since
17// 1970 and then counts up by one per event, so numbers keep increasing across restarts and a
18// Seq names one line across every pano.log file. It stays below 2^53, so JSON readers that
19// parse numbers as doubles read it exactly.
20
23 UINT64 Sequence; // the event's Seq in pano.log
24 INT64 Timestamp; // FILETIME, UTC
25 std::string Json; // the line written to pano.log, without the newline
26};
27
33std::string RecordEvent(nlohmann::ordered_json& event, const FILETIME& time);
34
36
39public:
43 static std::unique_ptr<DetectorSubscription> Open(const std::vector<std::string>& eventNames);
45
48 bool Wait(std::vector<DetectorEventRecord>& out, DWORD timeoutMs);
49
52
53private:
54 explicit DetectorSubscription(std::shared_ptr<DetectorSubscriberState> state);
55 std::shared_ptr<DetectorSubscriberState> m_state;
56};
57
59FILETIME CurrentFileTime();
60
static std::unique_ptr< DetectorSubscription > Open(const std::vector< std::string > &eventNames)
Registers a subscriber. Returns nullptr when the service is stopping or too many subscribers are conn...
DetectorSubscription & operator=(const DetectorSubscription &)=delete
DetectorSubscription(const DetectorSubscription &)=delete
bool Wait(std::vector< DetectorEventRecord > &out, DWORD timeoutMs)
Waits up to timeoutMs for events and moves the queued ones into out (which it clears first)....
void StopDetectorStreams()
Wakes every subscriber's Wait with false and refuses new subscribers, so the SubscribeEvents calls re...
std::string RecordEvent(nlohmann::ordered_json &event, const FILETIME &time)
Gives event the next sequence number (appended as "Seq"), writes it to pano.log and queues it for eve...
FILETIME CurrentFileTime()
The current time as a FILETIME, for events that carry no timestamp of their own.
One event as sent to the detector (a DetectorEvent message).