use NestedDeserializableDataclass for config

This commit is contained in:
Alex 2025-01-07 01:43:39 +03:00
parent 96664684f8
commit 3eb358d618
13 changed files with 188 additions and 130 deletions

View file

@ -4,25 +4,26 @@ from os import environ
from sys import argv
from alerting import alerts
from alerting.enum import AlertType, Severity
type_priority_map = {
"ONLINE": alerts.Severity.INFO, # UPS is back online
"ONBATT": alerts.Severity.WARNING, # UPS is on battery
"LOWBATT": alerts.Severity.CRITICAL, # UPS is on battery and has a low battery (is critical)
"FSD": alerts.Severity.CRITICAL, # UPS is being shutdown by the primary (FSD = "Forced Shutdown")
"COMMOK": alerts.Severity.INFO, # Communications established with the UPS
"COMMBAD": alerts.Severity.WARNING, # Communications lost to the UPS
"SHUTDOWN": alerts.Severity.CRITICAL, # The system is being shutdown
"REPLBATT": alerts.Severity.WARNING, # The UPS battery is bad and needs to be replaced
"NOCOMM": alerts.Severity.WARNING, # A UPS is unavailable (cant be contacted for monitoring)
"NOPARENT": alerts.Severity.CRITICAL, # upsmon parent process died - shutdown impossible
"CAL": alerts.Severity.INFO, # UPS calibration in progress
"NOTCAL": alerts.Severity.INFO, # UPS calibration finished
"OFF": alerts.Severity.CRITICAL, # UPS administratively OFF or asleep
"NOTOFF": alerts.Severity.INFO, # UPS no longer administratively OFF or asleep
"BYPASS": alerts.Severity.WARNING, # UPS on bypass (powered, not protecting)
"NOTBYPASS": alerts.Severity.INFO, # UPS no longer on bypass
None: alerts.Severity.CRITICAL, # unknown alert type
"ONLINE": Severity.INFO, # UPS is back online
"ONBATT": Severity.WARNING, # UPS is on battery
"LOWBATT": Severity.CRITICAL, # UPS is on battery and has a low battery (is critical)
"FSD": Severity.CRITICAL, # UPS is being shutdown by the primary (FSD = "Forced Shutdown")
"COMMOK": Severity.INFO, # Communications established with the UPS
"COMMBAD": Severity.WARNING, # Communications lost to the UPS
"SHUTDOWN": Severity.CRITICAL, # The system is being shutdown
"REPLBATT": Severity.WARNING, # The UPS battery is bad and needs to be replaced
"NOCOMM": Severity.WARNING, # A UPS is unavailable (cant be contacted for monitoring)
"NOPARENT": Severity.CRITICAL, # upsmon parent process died - shutdown impossible
"CAL": Severity.INFO, # UPS calibration in progress
"NOTCAL": Severity.INFO, # UPS calibration finished
"OFF": Severity.CRITICAL, # UPS administratively OFF or asleep
"NOTOFF": Severity.INFO, # UPS no longer administratively OFF or asleep
"BYPASS": Severity.WARNING, # UPS on bypass (powered, not protecting)
"NOTBYPASS": Severity.INFO, # UPS no longer on bypass
None: Severity.CRITICAL, # unknown alert type
}
@ -33,7 +34,7 @@ async def main():
message = argv[1]
typestr = environ.get("NOTIFYTYPE", None)
severity = type_priority_map[typestr]
alert = alerts.Alert(alert_type=alerts.AlertType.UPS, message=message, severity=severity)
alert = alerts.Alert(alert_type=AlertType.UPS, message=message, severity=severity)
await alerts.send_alert(alert)