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
48pub mod definition;
49pub mod error;
50pub mod normalizer;
51pub mod wire;
52
53pub use definition::SourceDefinition;
54pub use error::DefinitionError;
55pub use normalizer::{DeadLetter, EventId, Issue, Normalized, Normalizer, Outcome, Stage};
56pub use wire::{Envelope, WireError};
57
58/// The Sysmon source definition shipped with this crate.
59pub const SYSMON: &str = include_str!("../sources/sysmon.yaml");