The KPI detect phase dropped 1-2.6k events in 2 of 3 runs: each correlation pass computed findings over every indicator (300+ ms with ~20k indicators) while holding the pipeline lock, so the exec worker stalled until its queue (4096) overflowed. Correlation now snapshots the indicators under the lock, computes findings without it (CorrelationEngine::build_findings), and takes the lock again only to store them in one transaction. "Scanning process" and "New process detected" were logged for every exec on the host; they now need STRAWBERRY_TRACE_EXECS=1. Detections, errors and state changes are still logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
2.6 KiB
C++
81 lines
2.6 KiB
C++
#include "strawberry/daemon_states.hpp"
|
|
#include "strawberry/log_flags.hpp"
|
|
#include <iostream>
|
|
|
|
namespace strawberry {
|
|
|
|
// IdleState implementation
|
|
void IdleState::entry() {
|
|
std::cout << "[Daemon] Entered Idle state" << std::endl;
|
|
}
|
|
|
|
void IdleState::react(StartEvent const & event) {
|
|
std::cout << "[Daemon] Starting daemon with config: " << event.config_path << std::endl;
|
|
transit<InitializingState>();
|
|
}
|
|
|
|
// InitializingState implementation
|
|
void InitializingState::entry() {
|
|
std::cout << "[Daemon] Entered Initializing state" << std::endl;
|
|
std::cout << "[Daemon] Loading configuration and initializing components..." << std::endl;
|
|
}
|
|
|
|
void InitializingState::react(MonitorEvent const &) {
|
|
std::cout << "[Daemon] Initialization complete, starting monitoring" << std::endl;
|
|
transit<MonitoringState>();
|
|
}
|
|
|
|
void InitializingState::react(StopEvent const &) {
|
|
std::cout << "[Daemon] Stop requested during initialization" << std::endl;
|
|
transit<ShutdownState>();
|
|
}
|
|
|
|
// MonitoringState implementation
|
|
void MonitoringState::entry() {
|
|
std::cout << "[Daemon] Entered Monitoring state" << std::endl;
|
|
std::cout << "[Daemon] Actively monitoring system processes..." << std::endl;
|
|
}
|
|
|
|
void MonitoringState::react(ScanEvent const & event) {
|
|
if (trace_execs()) {
|
|
std::cout << "[Daemon] Scanning process PID: " << event.pid << " (" << event.process_path << ")" << std::endl;
|
|
}
|
|
// Process scanning logic would be handled by scanner components
|
|
}
|
|
|
|
void MonitoringState::react(UpdateRulesEvent const & event) {
|
|
std::cout << "[Daemon] Updating YARA rules from: " << event.rules_path << std::endl;
|
|
transit<UpdatingState>();
|
|
}
|
|
|
|
void MonitoringState::react(StopEvent const &) {
|
|
std::cout << "[Daemon] Stop requested, shutting down" << std::endl;
|
|
transit<ShutdownState>();
|
|
}
|
|
|
|
// UpdatingState implementation
|
|
void UpdatingState::entry() {
|
|
std::cout << "[Daemon] Entered Updating state" << std::endl;
|
|
std::cout << "[Daemon] Reloading YARA rules..." << std::endl;
|
|
}
|
|
|
|
void UpdatingState::react(MonitorEvent const &) {
|
|
std::cout << "[Daemon] Rules updated, resuming monitoring" << std::endl;
|
|
transit<MonitoringState>();
|
|
}
|
|
|
|
void UpdatingState::react(StopEvent const &) {
|
|
std::cout << "[Daemon] Stop requested during update" << std::endl;
|
|
transit<ShutdownState>();
|
|
}
|
|
|
|
// ShutdownState implementation
|
|
void ShutdownState::entry() {
|
|
std::cout << "[Daemon] Entered Shutdown state" << std::endl;
|
|
std::cout << "[Daemon] Cleaning up resources and exiting..." << std::endl;
|
|
}
|
|
|
|
// Define initial state
|
|
FSM_INITIAL_STATE(DaemonStateMachine, IdleState)
|
|
|
|
} // namespace strawberry
|