Skip to main content

CorrelationEngine

Struct CorrelationEngine 

Source
pub struct CorrelationEngine { /* private fields */ }
Expand description

Stateful correlation engine.

Wraps the stateless Engine for detection rules and adds time-windowed correlation on top. Supports all 7 Sigma correlation types and chaining.

Implementations§

Source§

impl CorrelationEngine

Source

pub fn new(config: CorrelationConfig) -> Self

Create a new correlation engine with the given configuration.

Source

pub fn add_pipeline(&mut self, pipeline: Pipeline)

Add a pipeline to the engine.

Pipelines are applied to rules during add_rule / add_collection.

Source

pub fn set_include_event(&mut self, include: bool)

Set global include_event on the inner detection engine.

Source

pub fn set_correlation_event_mode(&mut self, mode: CorrelationEventMode)

Set the global correlation event mode.

  • None: no event storage (default)
  • Full: compressed event bodies
  • Refs: lightweight timestamp + ID references
Source

pub fn set_max_correlation_events(&mut self, max: usize)

Set the maximum number of events to store per correlation window group. Only meaningful when correlation_event_mode is not None.

Source

pub fn add_rule(&mut self, rule: &SigmaRule) -> Result<()>

Add a single detection rule.

If pipelines are set, the rule is cloned and transformed before compilation. The inner engine receives the already-transformed rule directly (not through its own pipeline, to avoid double transformation).

Source

pub fn add_correlation(&mut self, corr: &CorrelationRule) -> Result<()>

Add a single correlation rule.

Source

pub fn add_collection(&mut self, collection: &SigmaCollection) -> Result<()>

Add all rules and correlations from a parsed collection.

Detection rules are added first (so they’re available for correlation references), then correlation rules.

Source

pub fn process_event(&mut self, event: &Event<'_>) -> ProcessResult

Process an event, extracting the timestamp from configured event fields.

When no timestamp field is found, the timestamp_fallback policy applies:

  • WallClock: use Utc::now() (good for real-time streaming)
  • Skip: return detections only, skip correlation state updates
Source

pub fn process_event_at( &mut self, event: &Event<'_>, timestamp_secs: i64, ) -> ProcessResult

Process an event with an explicit Unix epoch timestamp (seconds).

The timestamp is clamped to [0, i64::MAX / 2] to prevent overflow when adding timespan durations internally.

Source

pub fn evict_expired(&mut self, now_secs: i64)

Manually evict all expired state entries.

Source

pub fn state_count(&self) -> usize

Number of active state entries (for monitoring).

Source

pub fn detection_rule_count(&self) -> usize

Number of detection rules loaded.

Source

pub fn correlation_rule_count(&self) -> usize

Number of correlation rules loaded.

Source

pub fn event_buffer_count(&self) -> usize

Number of active event buffers (for monitoring).

Source

pub fn event_buffer_bytes(&self) -> usize

Total compressed bytes across all event buffers (for monitoring).

Source

pub fn event_ref_buffer_count(&self) -> usize

Number of active event ref buffers — Refs mode (for monitoring).

Source

pub fn engine(&self) -> &Engine

Access the inner stateless engine.

Source

pub fn export_state(&self) -> CorrelationSnapshot

Export all mutable correlation state as a serializable snapshot.

The snapshot uses stable correlation identifiers (id > name > title) instead of internal indices, so it survives rule reloads as long as the correlation rules keep the same identifiers.

Source

pub fn import_state(&mut self, snapshot: CorrelationSnapshot) -> bool

Import previously exported state, mapping stable identifiers back to current correlation indices. Entries whose identifiers no longer match any loaded correlation are silently dropped.

Returns false (and imports nothing) if the snapshot version is incompatible with the current schema.

Trait Implementations§

Source§

impl Default for CorrelationEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.