Add asset context to events
Join observations with an asset export while preserving unknowns and source records.
Context makes a finding useful
A failed logon on a disposable training device and one on a critical payroll server may need different attention. An asset export can supply an owner and criticality label, but it cannot change what the original event says happened.
Normalize host keys with strip().casefold() for this fictional inventory. Build an index once and use exact lookup. Substring matching can attach the wrong owner when hostnames share a prefix. Reject duplicate normalized keys because an ambiguous inventory should be corrected rather than guessed through.
Unknown is a useful result
If the event host is absent from the inventory, keep the event and use None for the added context. Treating an unknown host as noncritical would hide missing evidence inside a reassuring boolean. A later report can count unknowns and explain the limitation.
Create new dictionaries using {**event, ...} instead of mutating the source list. Preserve event IDs and other supplied fields. That allows another rule to reuse the same input without inheriting your analysis changes.
This is an exact join between two supplied exports, not an endpoint query. It sends no commands to a machine. The checks include mixed-case keys, unknown hosts, duplicate assets, and unchanged inputs so the join remains dependable when reused in the capstone.
assets = {"srv-01": {"owner": "IT", "critical": True}}
key = " SRV-01 ".strip().casefold()
print(assets.get(key))
Put it into practice.
Define enrich_events(events, assets). Index asset rows by host.strip().casefold(); reject duplicate normalized hosts with ValueError. Return new event dictionaries in input order, preserving all original fields except normalized host, and adding asset_owner and asset_critical from the matching asset. Both added fields must be None for unknown hosts. Do not mutate either input.
See an explained solution
def enrich_events(events, assets):
index = {}
for asset in assets:
key = asset["host"].strip().casefold()
if key in index:
raise ValueError("Duplicate asset host")
index[key] = asset
result = []
for event in events:
key = event["host"].strip().casefold()
asset = index.get(key)
result.append({**event, "host": key, "asset_owner": asset["owner"] if asset else None, "asset_critical": asset["critical"] if asset else None})
return result
An indexed exact join adds useful context without dropping unknown events. New dictionaries preserve the original evidence for other analysis steps.