1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Event correlation helpers for linking related security events.
use crateSecurityEvent;
use Uuid;
/// Returns `event` linked to `parent_event_id`.
///
/// # Examples
///
/// ```rust
/// use security_core::severity::SecuritySeverity;
/// use security_events::correlation::with_parent;
/// use security_events::event::{EventOutcome, SecurityEvent};
/// use security_events::kind::EventKind;
/// use uuid::Uuid;
///
/// let parent_id = Uuid::new_v4();
/// let child = with_parent(
/// SecurityEvent::new(
/// EventKind::AuthzDeny,
/// SecuritySeverity::Medium,
/// EventOutcome::Blocked,
/// ),
/// parent_id,
/// );
///
/// assert_eq!(child.parent_event_id, Some(parent_id));
/// ```
/// Attaches a `parent_event_id` to an existing event in place.
///
/// # Examples
///
/// ```rust
/// use security_core::severity::SecuritySeverity;
/// use security_events::correlation::attach_parent;
/// use security_events::event::{EventOutcome, SecurityEvent};
/// use security_events::kind::EventKind;
/// use uuid::Uuid;
///
/// let parent_id = Uuid::new_v4();
/// let mut child = SecurityEvent::new(
/// EventKind::AuthzDeny,
/// SecuritySeverity::Medium,
/// EventOutcome::Blocked,
/// );
/// attach_parent(&mut child, parent_id);
/// assert_eq!(child.parent_event_id, Some(parent_id));
/// ```
/// Returns the subset of `events` that reference `parent_event_id`.
///
/// # Examples
///
/// ```rust
/// use security_core::severity::SecuritySeverity;
/// use security_events::correlation::{filter_by_parent, with_parent};
/// use security_events::event::{EventOutcome, SecurityEvent};
/// use security_events::kind::EventKind;
/// use uuid::Uuid;
///
/// let parent_id = Uuid::new_v4();
/// let child = with_parent(
/// SecurityEvent::new(
/// EventKind::AuthzDeny,
/// SecuritySeverity::Medium,
/// EventOutcome::Blocked,
/// ),
/// parent_id,
/// );
/// let events = vec![child];
/// assert_eq!(filter_by_parent(&events, parent_id).len(), 1);
/// ```