2.5 KiB
events
Purpose
Central classifier and persistence layer for everything that happens on the MQTT bus. Subscribes to the whole bus, parses topic paths into EventType/Severity/source_id, writes rows into events, evaluates the rule engine against the arm-state FSM, and executes resulting actions (send alert, broadcast system-alert, command all cameras to record).
Key files
vigilar/events/processor.py—EventProcessor: subscribes viabus.subscribe_all, classifies topics in_classify_event(a big if-chain, no routing table), writes viainsert_event, executes rule actionsvigilar/events/state.py—ArmStateFSM(HOME/AWAY/NIGHT/DISARMED), publishesTopics.SYSTEM_ARM_STATE, persists toarm_state_logvigilar/events/rules.py—RuleEngineevaluating TOML-configured rules against topic/payload/arm-statevigilar/events/history.py— thin wrapper aroundget_events/acknowledge_event
MQTT topics
Subscribes: vigilar/# (wildcard via bus.subscribe_all)
Publishes:
vigilar/system/arm_state(fromArmStateFSM)vigilar/system/alert(when a rule firesalert_all/push_and_record)vigilar/camera/{id}/command/record(per-camera record command forpush_and_record/record_all_cameras)
Database tables
events— canonical event log; every classified message becomes a rowarm_state_log— arm-state transitions written by the FSMpet_sightings— inserted when classification producesPET_DETECTED,PET_ESCAPE, orUNKNOWN_ANIMALwildlife_sightings— inserted forWILDLIFE_PREDATOR/NUISANCE/PASSIVE
Depends on
- Every publisher on the bus (camera, sensors, ups, presence, detection, health, highlights, etc.)
storage— usesvigilar.storage.queriesfor all insertsalerts— callssend_alertfromvigilar.alerts.senderwhen a rule requests it
Consumed by
alerts— triggered indirectly via rule actionsweb— readseventstable throughvigilar.storage.queriesfor the timeline and SSE streamhighlights— consumes theeventstable for reel scoring
Notes
Classification is a hand-written if-chain keyed on the topic path. Camera heartbeat and error topics are intentionally ignored (return None). Person and vehicle YOLO detections ride on camera/{id}/motion/start and currently collapse back to a plain MOTION_START event — a known artefact of the publishing quirk in the camera worker. Arm-state change messages on vigilar/system/* are also deliberately ignored by the classifier to avoid feedback loops.