diff --git a/misc/checks.py b/misc/checks.py index d4bad14..70a9d37 100644 --- a/misc/checks.py +++ b/misc/checks.py @@ -98,7 +98,10 @@ async def vuln_check() -> list[alerts.Alert]: async def ups_check() -> list[alerts.Alert]: - sensor = sensors.Sensors.get_ups() + sensor = await sensors.Sensors.get_ups() + + if not sensor: return + alert_list = [] if IS_TESTING or sensor.battery_charge_percentage < sensor.battery_critical_percentage: diff --git a/misc/sensors.py b/misc/sensors.py index 16e25e4..ed554cb 100644 --- a/misc/sensors.py +++ b/misc/sensors.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from psutil import cpu_percent, sensors_temperatures, virtual_memory from .enums import UPSStatus +from alerting import alerts @dataclass @@ -111,8 +112,16 @@ class Sensors: return RamSensor(current_avail=ram.available, current_avail_percentage=ram.percent) @staticmethod - def get_ups() -> UPSSensor: - raw_data = subprocess.run(["upsc", "cp1300"], stdout=subprocess.PIPE, encoding="utf-8") + async def get_ups() -> None | UPSSensor: + try: + raw_data = subprocess.run(["upsc", "cp1300"], stdout=subprocess.PIPE, encoding="utf-8") + except FileNotFoundError: + await alerts.send_alert(alerts.Alert( + alert_type=alerts.AlertType.ERROR, + message="upsc is not installed!", + severity=alerts.Severity.CRITICAL + )) + return None sensor_data = UPSSensor()