2.0 KiB
2.0 KiB
ups
Purpose
Polls a local NUT (Network UPS Tools) daemon for battery status and publishes power state transitions onto the MQTT bus. When the UPS runs below a configured critical-runtime threshold, triggers a graceful shutdown of the host.
Key files
vigilar/ups/monitor.py—UPSMonitor: NUT client, status parser, transition detection, MQTT publishervigilar/ups/shutdown.py—ShutdownSequence: publishesSYSTEM_SHUTDOWNand executes the OS shutdownvigilar/ups/__init__.py
MQTT topics
Subscribes: none Publishes:
vigilar/ups/status(every poll; status, battery charge %, runtime seconds, input voltage, load %)vigilar/ups/power_loss(transitionOL -> OB/LB)vigilar/ups/restored(transition back toOL)vigilar/ups/low_battery(charge belowlow_battery_threshold_pct)vigilar/ups/critical(runtime belowcritical_runtime_threshold_s, triggers shutdown)vigilar/system/shutdown(published byShutdownSequence)
Database tables
events— writesPOWER_LOSS,POWER_RESTORED,LOW_BATTERYrows viainsert_eventsystem_events— writes operator-facing notices ("Power loss detected — running on battery", critical shutdown messages)
Depends on
- External NUT daemon reachable at
[ups] nut_host:nut_portvia thepynut2client storage—insert_event,insert_system_event
Consumed by
events— classifiesvigilar/ups/*intoPOWER_LOSS/LOW_BATTERY/POWER_RESTOREDalerts— receives those classified events through rule actionsmainsupervisor — reacts toSYSTEM_SHUTDOWNso all subsystems can drain cleanly
Notes
The critical shutdown trigger fires when the UPS is not online AND battery.runtime < ups.critical_runtime_threshold_s AND no shutdown has already been triggered. The low-battery alert fires when battery.charge < ups.low_battery_threshold_pct while off mains. NUT reconnection uses exponential backoff capped at 120 seconds, so the monitor survives a temporary NUT restart without the supervisor having to restart it.