alerting if upsc is not installed

This commit is contained in:
saqriphnix 2024-08-17 12:32:25 +03:00
parent 66bc90da5c
commit 17e5d1be0c
2 changed files with 15 additions and 3 deletions

View file

@ -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:

View file

@ -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()