mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
move checks to upsmon, where possible
This commit is contained in:
parent
9518527beb
commit
09a9cfe310
3 changed files with 53 additions and 51 deletions
41
send_ups_alert.py
Normal file
41
send_ups_alert.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
from os import environ
|
||||
from sys import argv
|
||||
|
||||
from alerting import alerts
|
||||
|
||||
type_priority_map = {
|
||||
"ONLINE": alerts.Severity.INFO,
|
||||
"ONBATT": alerts.Severity.WARNING,
|
||||
"LOWBATT": alerts.Severity.CRITICAL,
|
||||
"FSD": alerts.Severity.CRITICAL,
|
||||
"COMMOK": alerts.Severity.INFO,
|
||||
"COMMBAD": alerts.Severity.WARNING,
|
||||
"SHUTDOWN": alerts.Severity.CRITICAL,
|
||||
"REPLBATT": alerts.Severity.WARNING,
|
||||
"NOCOMM": alerts.Severity.WARNING,
|
||||
"NOPARENT": alerts.Severity.CRITICAL,
|
||||
"CAL": alerts.Severity.INFO,
|
||||
"NOTCAL": alerts.Severity.INFO,
|
||||
"OFF": alerts.Severity.CRITICAL,
|
||||
"NOTOFF": alerts.Severity.INFO,
|
||||
"BYPASS": alerts.Severity.WARNING,
|
||||
"NOTBYPASS": alerts.Severity.INFO,
|
||||
None: alerts.Severity.CRITICAL,
|
||||
}
|
||||
|
||||
|
||||
async def main():
|
||||
"""Sends an alert about a UPS event. Meant to be used from upsmon with NOTIFYCMD"""
|
||||
if len(argv) != 2:
|
||||
raise Exception("provide exactly one argument: alert message")
|
||||
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)
|
||||
await alerts.send_alert(alert)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue