Skip to main content

CorrelationEngine

Struct CorrelationEngine 

Source
pub struct CorrelationEngine<L = LogSourceExtractor> { /* 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.

Generic over the inner engine’s logsource extractor L, which defaults to LogSourceExtractor (see Engine).

Implementations§

Source§

impl<L> CorrelationEngine<L>

Source

pub fn introspect(&self) -> CorrelationStateSnapshot

Snapshot every compiled correlation and its live per-group window state.

Source

pub fn introspect_filtered( &self, id_filter: Option<&str>, group_filter: Option<&str>, ) -> CorrelationStateSnapshot

Like introspect but keeps only the correlations whose id, name, or title equals id_filter and the groups whose rendered key contains group_filter.

Source

pub fn introspect_for_tenant( &self, id_filter: Option<&str>, group_filter: Option<&str>, tenant_filter: Option<&TenantId>, ) -> CorrelationStateSnapshot

Like introspect_filtered but, when tenant_filter is set, keeps only groups owned by that tenant and counts only its groups as active.

Source§

impl CorrelationEngine

Source

pub fn new(config: CorrelationConfig) -> Self

Create a new correlation engine with the given configuration.

Source§

impl<L> CorrelationEngine<L>

Source

pub fn with_logsource_extractor(config: CorrelationConfig, extractor: L) -> Self

Create a new correlation engine whose inner detection engine prunes with extractor, a custom ExtractLogSource implementation.

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_match_detail(&mut self, level: MatchDetailLevel)

Forward to crate::Engine::set_match_detail on the inner detection engine. Correlation detections inherit the level set here.

Source

pub fn set_bloom_prefilter(&mut self, enabled: bool)

Forward to crate::Engine::set_bloom_prefilter on the inner detection engine. Off by default; the optimization helps only on substring-heavy rule sets paired with mostly-non-matching events.

Source

pub fn set_logsource_extractor(&mut self, extractor: Option<L>)

Forward to crate::Engine::set_logsource_extractor on the inner detection engine. Correlation inherits logsource pruning, since process_event evaluates through this engine.

Source

pub fn logsource_pruned_total(&self) -> u64

Total rule candidates pruned by logsource on the inner engine.

Source

pub fn logsource_absent_total(&self) -> u64

Total evaluate calls with no extractable event logsource (fail-open).

Source

pub fn set_bloom_max_bytes(&mut self, max_bytes: usize)

Forward to crate::Engine::set_bloom_max_bytes 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. Detection rules are compiled sequentially and then pushed to the inner engine in a single batch, so the inverted index and bloom filter are rebuilt exactly once for the whole collection. Without this batching, large rule sets (multi-thousand rules) hit an O(N²) rebuild cost on load.

Source

pub fn process_event<E: Event>(&mut self, event: &E) -> ProcessResult
where L: ExtractLogSource<E>,

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_for_tenant<E: Event>( &mut self, event: &E, tenant: Option<&TenantId>, ) -> ProcessResult
where L: ExtractLogSource<E>,

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

The tenant keys every window this event touches; correlation results carry it. None is the untenanted bucket used when tenancy is off.

Source

pub fn correlate_detections( &mut self, event: &impl Event, all_detections: Vec<EvaluationResult>, ) -> ProcessResult

Run the correlation layer over externally-produced detections.

Like process_event but the detections are supplied by the caller instead of computed by this engine’s inner detection engine. This lets a multi-engine router run detection in a per-schema engine and still feed every detection into one shared correlation store. Timestamp extraction and the timestamp_fallback policy match process_event. Rule identity is recovered as in process_with_detections.

Source

pub fn correlate_detections_for_tenant( &mut self, event: &impl Event, all_detections: Vec<EvaluationResult>, tenant: Option<&TenantId>, ) -> ProcessResult

Like correlate_detections but as tenant.

Source

pub fn process_event_at<E: Event>( &mut self, event: &E, timestamp_secs: i64, ) -> ProcessResult
where L: ExtractLogSource<E>,

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 process_event_at_for_tenant<E: Event>( &mut self, event: &E, timestamp_secs: i64, tenant: Option<&TenantId>, ) -> ProcessResult
where L: ExtractLogSource<E>,

Like process_event_at but as tenant.

Source

pub fn process_with_detections( &mut self, event: &impl Event, all_detections: Vec<EvaluationResult>, timestamp_secs: i64, ) -> ProcessResult

Process an event with pre-computed detection results.

Enables external parallelism: callers can run detection (via evaluate) in parallel, then feed results here sequentially for stateful correlation.

A result carries its rule’s id but not its name, so a detection from a rule without an id is matched to its rule by title and feeds no correlation when several such rules share that title. process_event_at and process_batch keep the compiled identity.

Source

pub fn process_with_detections_for_tenant( &mut self, event: &impl Event, all_detections: Vec<EvaluationResult>, timestamp_secs: i64, tenant: Option<&TenantId>, ) -> ProcessResult

Like process_with_detections but as tenant.

Source

pub fn untenanted_skipped(&self) -> u64

Number of events skipped by require_tenant because they carried no tenant.

Source

pub fn take_untenanted_skipped(&mut self) -> u64

Events skipped by require_tenant since the previous call, draining the counter.

Source

pub fn set_max_state_entries_per_tenant(&mut self, max: Option<usize>)

Set the per-tenant state cap. None leaves only the global cap.

Source

pub fn take_tenant_quota_evictions(&mut self) -> u64

Entries evicted because a tenant hit its quota since the previous call, draining the counter.

Source

pub fn evaluate<E: Event>(&self, event: &E) -> Vec<EvaluationResult>
where L: ExtractLogSource<E>,

Run stateless detection only (no correlation), delegating to the inner engine.

Returns one EvaluationResult per matched detection. Takes &self so it can be called concurrently from multiple threads (e.g. via rayon::par_iter) while the mutable correlation phase runs sequentially afterwards.

Source

pub fn process_batch<E: Event + Sync>( &mut self, events: &[&E], ) -> Vec<ProcessResult>
where L: ExtractLogSource<E> + Sync,

Process a batch of events: parallel detection, then sequential correlation.

When the parallel feature is enabled, the stateless detection phase runs concurrently via rayon. Timestamp extraction also runs in the parallel phase (it borrows &self.config immutably). After collect() releases the immutable borrows, each event’s pre-computed detections are fed into the stateful correlation engine sequentially.

Source

pub fn process_batch_for_tenants<E: Event + Sync>( &mut self, events: &[&E], tenants: &[Option<TenantId>], ) -> Vec<ProcessResult>
where L: ExtractLogSource<E> + Sync,

Process a batch of events, each as the tenant at its position in tenants.

tenants is either empty (every event is untenanted) or exactly as long as events. Any other length is a caller bug: in debug builds it trips a debug_assert!, and in release builds it logs and returns one empty result per event.

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<L>

Access the inner stateless engine.

Source

pub fn rule_metadata(&self, key: &str) -> RuleMetadataLookup

Resolve a rule key (an id, or a title for a rule without one) to the documentation of every loaded rule that carries it, across both the detection rules and the correlations.

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. State is nested per tenant; with tenancy off it is one tenant: None entry.

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.

A snapshot exported by a fan-out over exactly one ruleset imports that ruleset’s state.

Returns false (and imports nothing) if the snapshot version is incompatible with the current schema, or if the snapshot holds state for several rulesets.

Source

pub fn import_state_detailed( &mut self, snapshot: CorrelationSnapshot, ) -> Option<ImportStats>

Like import_state, returning the counts of restored and discarded entries.

Accepts versions 1 and 2. Attribution follows CorrelationConfig::require_tenant: with it set, untenanted entries are discarded; without it, tenanted entries are discarded. Returns None for an unknown version or a multi-ruleset snapshot that does not fit this engine.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.