Add stable v1 schema IDs and docs

This commit is contained in:
Luna 2026-06-16 04:05:12 -07:00
parent bfef23fc4a
commit 7a176ea238
13 changed files with 409 additions and 8 deletions

View file

@ -28,6 +28,7 @@ import time
from collections.abc import Callable, Iterable
from datetime import datetime
from . import schemas
from .alert import Alert, Severity
from .config import Config
@ -112,7 +113,12 @@ def index_path(cfg: Config):
def load_index(cfg: Config) -> dict:
try:
data = json.loads(index_path(cfg).read_text())
return data if isinstance(data, dict) else {}
if not isinstance(data, dict):
return {}
for inc in data.values():
if isinstance(inc, dict):
inc.setdefault("schema", schemas.INCIDENT_V1)
return data
except (OSError, ValueError):
return {}
@ -161,6 +167,7 @@ def record(cfg: Config, snapshot_name: str, alerts: list[Alert],
if iid is None:
iid = _new_id(when)
index[iid] = {
"schema": schemas.INCIDENT_V1,
"id": iid, "host": host,
"first_ts": when, "last_ts": when,
"first_seen": iso, "last_seen": iso,
@ -169,6 +176,7 @@ def record(cfg: Config, snapshot_name: str, alerts: list[Alert],
"lineage": [], "snapshots": [], "alert_count": 0,
}
inc = index[iid]
inc.setdefault("schema", schemas.INCIDENT_V1)
inc["last_ts"] = when
inc["last_seen"] = iso
inc["severity"] = max_severity(inc.get("severity", severity), severity)