Skip to content

About

A vendor-log normaliser to OCSF classes that accounts for every source field as mapped, dropped by rule or kept unmapped, and flags drift when a firmware update renames one.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

fieldledger

CI

fieldledger

fieldledger normalises vendor logs (key=value syslog, JSON, CEF, RFC 5424) into a hand-written subset of four OCSF classes. Every normalised event ships with a ledger that puts each source field into exactly one of four buckets: mapped, dropped by a rule with a reason, kept unmapped with its raw value, or failed (the transform rejected the value, the raw value is kept). A drift command compares two samples of a source and proposes renames from value overlap, so a firmware update that renames a field is caught instead of silently emptying a column. All sample data is synthetic and produced by a seeded generator in this repository.

The problem

SIEM content engineers write parsers that turn vendor logs into a common schema. Two failures are silent. A field nobody mapped is dropped on the floor, so nobody can tell whether the parser covers the feed. And when a firmware update renames srcip to src_ip, every event still parses, the normalised source address is empty, and every detection that reads it goes blind without raising an error. fieldledger makes both visible: the ledger shows where each field went, and drift detection shows which fields appeared, vanished or changed shape between two samples.

How it works

flowchart LR
    raw["Raw vendor lines<br/>kv syslog, JSON, CEF, RFC 5424"] --> dec["Decode by format<br/>flat source paths"]
    dec --> map["YAML mapping rules<br/>map, coalesce, const, drop"]
    map --> ev["OCSF class event"]
    map --> bag["unmapped bag<br/>raw leftovers verbatim"]
    map --> led["Per-field ledger<br/>mapped, dropped, unmapped, failed"]
    ev --> val["Validate against<br/>bundled schema"]
    dec --> drift["Drift profile<br/>key sets, types, value sets"]
    drift --> rep["Drift report<br/>renames, new keys, type changes"]
Loading
  1. fieldledger.decode turns a line into a flat dictionary of source paths. JSON leaves become dotted paths with array indexes (user.groups[1]), CEF becomes cef.* header fields and ext.* extension keys, syslog envelopes become syslog.* and sd.<id>.<param>.
  2. fieldledger.mapping loads a YAML mapping. Rules are map (source path to target path with transforms), coalesce (first present source wins), const and drop (a reason is required).
  3. fieldledger.normalize applies the rules and builds the ledger. After every event it checks that the ledger paths equal the source leaf paths, that the unmapped bag holds exactly the unmapped and failed paths with unchanged values, and that every target a mapped entry names is present in the event.
  4. fieldledger.validate checks type, required and enum constraints against the bundled schema and returns a list of issues with paths instead of raising.
  5. fieldledger.drift profiles two samples (key counts, dominant type, value sets) and compares them.

Quick start

Python 3.12 or newer (CI runs 3.12, 3.13 and 3.14).

python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"

# synthetic samples: seed 13, 2000 lines each; v2 is the planted firmware update
fieldledger generate acme-fw -o acme-v1.log
fieldledger generate acme-fw --variant v2 -o acme-v2.log

fieldledger drift acme-fw acme-v1.log acme-v2.log
fieldledger lint acme-fw nimbus-vpn ward-edr corp-dns
fieldledger normalize ward-edr some-edr.log --ledger --validate --pretty
fieldledger coverage acme-fw=acme-v1.log --path src_endpoint.ip
pytest -q

Commands:

Command What it does Exit code
normalize VENDOR FILE one JSON object per event; --ledger, --validate, --mapping FILE, --limit N 0
lint TARGET... check bundled vendor mappings or mapping YAML files against the schema 1 on any finding
drift VENDOR BASELINE NEW compare two samples; --json for machine output 1 if drift is found
coverage VENDOR=FILE... fill rate per normalised attribute, plus unmapped and failed counts 0
generate VENDOR write seeded synthetic lines; --seed, --count, --variant v2 (acme-fw only) 0

Bundled vendors, all synthetic: acme-fw (RFC 3164 syslog with a key=value body, to Network Activity 4001), nimbus-vpn (JSON, to Authentication 3002), ward-edr (CEF, to Process Activity 1007) and corp-dns (RFC 5424 with structured data, to DNS Activity 4003). RFC 3164 lines carry no year, so --reference (an RFC 3339 receive time, default: now) decides it.

Example output

Drift between the two acme-fw samples generated above (seed 13, firmware v1 against v2):

$ fieldledger drift acme-fw acme-v1.log acme-v2.log
baseline: 2000 records, new: 2000 records
rename suspected: srcip -> src_ip (value similarity 1.00, 40 vs 40 distinct values)
new key: rule_uuid (in 2000/2000 new records)
type change: bytes integer -> string
new enum value: action = reset-both (67x); baseline values: allow, deny, drop, reset
transform failures: action 0.0% -> 3.4%
transform failures: bytes 0.0% -> 100.0%

The last two lines come from running the old mapping over the new sample: bytes is now 1.2KB-style text that the int transform rejects, and reset-both is not in the action enum map. Two clean samples from different seeds print no drift and exit 0. The 1.00 and 40 vs 40 are optimistic compared with real traffic: every generator seed draws from one fixed pool of 40 addresses, so both samples see the same values.

One CEF event with its ledger (fieldledger normalize ward-edr one.log --ledger --validate --pretty, trimmed with ...):

{
  "event": {
    "class_uid": 1007,
    "category_uid": 1,
    "metadata": { "product": { "vendor_name": "WardSec", "name": "WardEDR" } },
    "time": 1773100802738,
    "activity_id": 2,
    "severity_id": 3,
    "message": "Process Terminated",
    "device": { "hostname": "wks-022", "ip": "192.168.17.75" },
    "actor": { "user": { "name": "ajones" }, "process": { "name": "cmd.exe", "pid": 2803 } },
    "process": {
      "name": "python.exe",
      "pid": 1791,
      "file": { "path": "C:\\Python312\\python.exe", "name": "python.exe", ... },
      "cmd_line": "python.exe C:\\jobs\\etl.py --date=2026-03-10 --mode=full"
    },
    "unmapped": { "cef.device_version": "4.2.1" }
  },
  "ledger": {
    "cef.version":        { "status": "dropped", "reason": "CEF format version, constant 0" },
    "cef.device_version": { "status": "unmapped" },
    "cef.signature_id":   { "status": "mapped", "to": ["activity_id"] },
    "ext.rt":             { "status": "mapped", "to": ["time"] },
    "ext.cs1Label":       { "status": "dropped", "reason": "label of cs1, always commandLine" },
    "ext.cs1":            { "status": "mapped", "to": ["process.cmd_line"] },
    ...
  },
  "validation": []
}

This excerpt is condensed by hand, not pasted: the real output is indented one key per line, the ... lines stand for omitted fields, and the ledger lists every source path. A value a transform rejects is kept in the bag, for example an acme-fw line with srcip=not-an-ip:

"srcip": {"status": "failed", "to": ["src_endpoint.ip"], "error": "srcip: not an IP address: 'not-an-ip'"}
"unmapped": {"srcip": "not-an-ip"}

Design decisions

  • A ledger, enforced as an invariant, instead of a coverage report. Accounting is checked on every event inside normalize, so a mapping bug raises LedgerError rather than producing quietly incomplete output. The cost is a small per-event check; the benefit is that "nothing vanished between the line and the record" holds for any input, which the property tests exercise with 500 generated events per vendor.
  • Repeated source keys are kept, not overwritten. a=1 a=2 decodes to a and a[1] (the same for CEF extensions and RFC 5424 SD params and ids), so every occurrence is its own leaf path in the ledger and lands in unmapped unless mapped. The mapping sees the first occurrence under the plain key; the cost is that a mapping for a never reads the later ones.
  • Failed values stay in the unmapped bag. A value that a transform rejects (not-an-ip, an unparseable size) is neither dropped nor half-converted. The bag then answers "what did the parser not understand" in one place, at the price of the bag being noisier during an incident with a malformed feed.
  • Drift compares value sets, not key names. A vanished key plus a new key is only called a rename when their sampled values have Jaccard similarity of at least 0.8 (RENAME_THRESHOLD). This avoids pairing unrelated fields, but it needs samples that cover the same entities: two samples of different hosts may not overlap enough to be matched, and the report then lists a vanished and a new key instead.
  • Hand-written OCSF subset. Four classes with 19 to 24 attributes each, kept as JSON in the package. Nothing is downloaded and validation is fast, but it covers only what the bundled mappings need; it is not the OCSF schema.
  • Transform errors are data errors. Every transform failure, including out-of-range dates and absurdly long digit strings, becomes a TransformError and a failed ledger entry, never an exception that stops a batch.
  • A dropped path hides a failed transform. A source path named by a drop rule is reported dropped even when a map rule for it failed, so its raw value is not kept in the bag. The precedence is mapped, dropped, failed, unmapped.
  • A map onto a const target wins silently. The constant is overridden and neither normalize nor lint reports it.
  • Quote yes, no, on and off enum keys. Unquoted, YAML reads them as booleans, they become the keys True and False, and they never match a source value.
  • Pure-Python decoders. The CEF extension decoder splits on the next unescaped key= so values may contain spaces; a value that itself contains word= is ambiguous under the CEF specification unless the = is escaped, and is split there.

Testing

GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest -q

135 tests, including 12 hand-written CEF fixtures, the RFC 3164 year rollover, golden normalised output for 5 lines per vendor, seven Hypothesis properties (500 examples each, derandomised) that build adversarial CEF escapes, nested JSON, quoted key=value text, structured data and repeated source keys, lint against a deliberately broken mapping, and drift on the planted firmware update. Tests need no network.

Project layout

src/fieldledger/
  decode.py        RFC 3164, RFC 5424, key=value, CEF and JSON decoders
  mapping.py       YAML mapping model and transforms
  normalize.py     apply a mapping, build the ledger, check the invariant
  schema.py        loader for the bundled OCSF subset
  schemas/         authentication, network_activity, process_activity, dns_activity (JSON)
  validate.py      type, required and enum validation that collects issues
  lint.py          static checks on a mapping
  drift.py         sample profiles and drift report
  coverage.py      attribute fill rates
  vendors.py       decoder and mapping per bundled vendor
  mappings/        acme-fw, nimbus-vpn, ward-edr, corp-dns (YAML)
  generators.py    seeded synthetic log generators and wire-format writers
  cli.py           typer command line
tests/             pytest and Hypothesis tests, golden and lint fixtures

License

MIT. See LICENSE.

About

A vendor-log normaliser to OCSF classes that accounts for every source field as mapped, dropped by rule or kept unmapped, and flags drift when a firmware update renames one.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages