goliath_normalize/lib.rs
1//! Declarative source definitions that turn raw log records into OCSF events.
2//!
3//! A source definition says, in YAML, how a log source's bytes split into
4//! records, how a record decodes, which kind of record it is, and where each
5//! of its fields goes in OCSF. People who know a log source can write one
6//! without writing Rust. The model is `docs/adr/0007-source-and-parser-model.md`.
7//!
8//! Nothing a source sends is dropped. A record that cannot become an event is
9//! a [`DeadLetter`] with its raw bytes intact. A field whose value does not
10//! convert is kept as written under `unmapped` and reported as an [`Issue`],
11//! and the event still goes on to detection.
12//!
13//! Definitions shipped with this crate live in `sources/`, each with fixtures
14//! of raw records and the events they must produce.
15//!
16//! # Example
17//!
18//! ```
19//! use goliath_normalize::{Normalizer, Outcome, SYSMON};
20//!
21//! let sysmon = Normalizer::from_yaml(SYSMON)?;
22//! let raw = br##"{"Event": {
23//! "System": {
24//! "Provider": { "#attributes": { "Name": "Microsoft-Windows-Sysmon" } },
25//! "EventID": 1,
26//! "TimeCreated": { "#attributes": { "SystemTime": "2026-09-24T10:15:30.1234567Z" } },
27//! "Computer": "WS-07"
28//! },
29//! "EventData": { "Image": "C:\\Windows\\notepad.exe", "ProcessId": "42", "RuleName": "-" }
30//! }}"##;
31//!
32//! sysmon.normalize(raw, |outcome| match outcome {
33//! Outcome::Event(normalized) => {
34//! assert_eq!(normalized.event["class_uid"], 1007);
35//! assert_eq!(normalized.event["process"]["pid"], 42);
36//! assert_eq!(normalized.event["time"], 1_790_244_930_123_i64);
37//! // Nothing is dropped: fields the definition does not map are kept.
38//! assert_eq!(normalized.event["unmapped"]["RuleName"], "-");
39//! }
40//! other => panic!("{other:?}"),
41//! });
42//! # Ok::<(), goliath_normalize::DefinitionError>(())
43//! ```
44
45// Tests assert on outcomes; a failed assertion should abort the test.
46#![cfg_attr(test, allow(clippy::expect_used, clippy::panic, clippy::unwrap_used))]
47
48mod auditd;
49pub mod definition;
50pub mod error;
51pub mod normalizer;
52pub mod wire;
53
54pub use definition::SourceDefinition;
55pub use error::DefinitionError;
56pub use normalizer::{DeadLetter, EventId, Issue, Normalized, Normalizer, Outcome, Stage};
57pub use wire::{Envelope, WireError};
58
59/// The Sysmon source definition shipped with this crate.
60pub const SYSMON: &str = include_str!("../sources/sysmon.yaml");
61
62/// The Falco source definition shipped with this crate.
63pub const FALCO: &str = include_str!("../sources/falco.yaml");
64
65/// The Microsoft Entra ID sign-in log definition shipped with this crate.
66pub const ENTRA: &str = include_str!("../sources/entra.yaml");
67
68/// The Linux audit log definition shipped with this crate.
69pub const AUDITD: &str = include_str!("../sources/auditd.yaml");
70
71/// Every definition shipped with this crate, by name.
72pub const BUILTIN: &[(&str, &str)] = &[
73 ("auditd", AUDITD),
74 ("entra", ENTRA),
75 ("falco", FALCO),
76 ("sysmon", SYSMON),
77];
78
79/// The shipped definition named `name`, if there is one.
80pub fn builtin(name: &str) -> Option<&'static str> {
81 BUILTIN
82 .iter()
83 .find(|(builtin, _)| *builtin == name)
84 .map(|(_, text)| *text)
85}