Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
detector_stream.h File Reference
#include <Windows.h>
#include <memory>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>

Go to the source code of this file.

Classes

struct  DetectorEventRecord
 One event as sent to the detector (a DetectorEvent message). More...
class  DetectorSubscription
 A registered subscriber. Unregisters when destroyed. More...

Functions

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 every subscriber that wants it, in that order for every event, so Seq increases down the log.
FILETIME CurrentFileTime ()
 The current time as a FILETIME, for events that carry no timestamp of their own.
void StopDetectorStreams ()
 Wakes every subscriber's Wait with false and refuses new subscribers, so the SubscribeEvents calls return before the server shuts down.

Function Documentation

◆ CurrentFileTime()

FILETIME CurrentFileTime ( )

The current time as a FILETIME, for events that carry no timestamp of their own.

Definition at line 124 of file detector_stream.cpp.

125{
126 FILETIME now;
127 GetSystemTimeAsFileTime(&now);
128 return now;
129}

◆ RecordEvent()

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 every subscriber that wants it, in that order for every event, so Seq increases down the log.

Parameters
timeWhen the event happened, at full resolution, for the detector
Returns
The line written, without the newline

Definition at line 113 of file detector_stream.cpp.

114{
115 std::lock_guard<std::mutex> guard(g_RecordLock);
116 UINT64 sequence = g_NextSequence++;
117 event["Seq"] = sequence;
118 std::string line = event.dump();
119 WriteToLogFile(line + "\n");
120 PublishDetectorEvent(event.value("Event", ""), sequence, line, time);
121 return line;
122}
void WriteToLogFile(const std::string &message)
Appends a line to the event log: LOG_FOLDER\pano.log, continuing in pano1.log, pano2....
Definition pano_log.cpp:72

References WriteToLogFile().

◆ StopDetectorStreams()

void StopDetectorStreams ( )

Wakes every subscriber's Wait with false and refuses new subscribers, so the SubscribeEvents calls return before the server shuts down.

Definition at line 131 of file detector_stream.cpp.

132{
133 std::lock_guard<std::mutex> guard(g_SubscribersLock);
134 g_Stopping = true;
135 for (auto& subscriber : g_Subscribers) {
136 {
137 std::lock_guard<std::mutex> lock(subscriber->Lock);
138 subscriber->Stopping = true;
139 }
140 subscriber->Wake.notify_all();
141 }
142}

Referenced by StopServiceServer().