Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
detector_stream.cpp File Reference
#include "detector_stream.h"
#include "pano_log.h"
#include <algorithm>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <deque>
#include <mutex>
#include <unordered_set>

Go to the source code of this file.

Classes

struct  DetectorSubscriberState

Macros

#define PANO_DETECTOR_QUEUE_MAX   16384
#define PANO_MAX_DETECTOR_SUBSCRIBERS   4

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.

Macro Definition Documentation

◆ PANO_DETECTOR_QUEUE_MAX

#define PANO_DETECTOR_QUEUE_MAX   16384

Definition at line 13 of file detector_stream.cpp.

◆ PANO_MAX_DETECTOR_SUBSCRIBERS

#define PANO_MAX_DETECTOR_SUBSCRIBERS   4

Definition at line 17 of file detector_stream.cpp.

Referenced by DetectorSubscription::Open().

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().