From 071d8afb9f0399b9b01a4a2d0d4d9f792924d3db Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 9 Nov 2024 12:48:53 +0300 Subject: [PATCH] move upsstatus enum to sensors --- misc/checks.py | 9 ++++----- misc/enums.py | 21 --------------------- misc/sensors.py | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 misc/enums.py diff --git a/misc/checks.py b/misc/checks.py index 64fe817..c4ccb0d 100644 --- a/misc/checks.py +++ b/misc/checks.py @@ -5,7 +5,6 @@ from datetime import timedelta from alerting import alerts from misc import cvars, docker_registry, sensors, vuln from misc.disks import LVAttr -from misc.enums import UPSStatus IS_TESTING = False @@ -126,13 +125,13 @@ async def ups_check() -> list[alerts.Alert]: ) for status in sensor.ups_status: - if IS_TESTING or status == UPSStatus.UPS_OVERLOAD: + if IS_TESTING or status == sensors.UPSStatus.UPS_OVERLOAD: alert_list.append( alerts.Alert( alert_type=alerts.AlertType.UPS, message=f"UPS is overloaded!", severity=alerts.Severity.CRITICAL ) ) - elif IS_TESTING or status == UPSStatus.ON_BATTERY: + elif IS_TESTING or status == sensors.UPSStatus.ON_BATTERY: alert_list.append( alerts.Alert( alert_type=alerts.AlertType.UPS, @@ -140,7 +139,7 @@ async def ups_check() -> list[alerts.Alert]: severity=alerts.Severity.INFO, ) ) - elif IS_TESTING or status == UPSStatus.UPS_TRIM: + elif IS_TESTING or status == sensors.UPSStatus.UPS_TRIM: alert_list.append( alerts.Alert( alert_type=alerts.AlertType.UPS, @@ -148,7 +147,7 @@ async def ups_check() -> list[alerts.Alert]: severity=alerts.Severity.INFO, ) ) - elif IS_TESTING or status == UPSStatus.UPS_BOOST: + elif IS_TESTING or status == sensors.UPSStatus.UPS_BOOST: alert_list.append( alerts.Alert( alert_type=alerts.AlertType.UPS, diff --git a/misc/enums.py b/misc/enums.py deleted file mode 100644 index 2ea1fc1..0000000 --- a/misc/enums.py +++ /dev/null @@ -1,21 +0,0 @@ -from enum import StrEnum - - -class UPSStatus(StrEnum): - """https://networkupstools.org/docs/developer-guide.chunked/new-drivers.html#_status_data""" - - ON_LINE = "OL" - ON_BATTERY = "OB" - BATTERY_LOW = "LB" - BATTERY_HIGH = "HB" - BATTERY_REPLACE = "RB" - BATTERY_CHARGING = "CHRG" - BATTERY_DISCHARGING = "DISCHRG" - UPS_BYPASS = "BYPASS" - """Battery and connected devices are not protected from power outage!""" - UPS_OFFLINE = "OFF" - UPS_OVERLOAD = "OVER" - UPS_CALIBRATION = "CAL" - UPS_TRIM = "TRIM" - UPS_BOOST = "BOOST" - UPS_FSD = "FSD" diff --git a/misc/sensors.py b/misc/sensors.py index f5082cc..6a05a54 100644 --- a/misc/sensors.py +++ b/misc/sensors.py @@ -1,12 +1,11 @@ import subprocess from dataclasses import dataclass +from enum import StrEnum from psutil import cpu_percent, sensors_temperatures, virtual_memory from alerting import alerts -from .enums import UPSStatus - @dataclass class TemperatureSensor: @@ -32,6 +31,26 @@ class RamSensor: critical_avail: int = 2 * 1024**3 +class UPSStatus(StrEnum): + """https://networkupstools.org/docs/developer-guide.chunked/new-drivers.html#_status_data""" + + ON_LINE = "OL" + ON_BATTERY = "OB" + BATTERY_LOW = "LB" + BATTERY_HIGH = "HB" + BATTERY_REPLACE = "RB" + BATTERY_CHARGING = "CHRG" + BATTERY_DISCHARGING = "DISCHRG" + UPS_BYPASS = "BYPASS" + """Battery and connected devices are not protected from power outage!""" + UPS_OFFLINE = "OFF" + UPS_OVERLOAD = "OVER" + UPS_CALIBRATION = "CAL" + UPS_TRIM = "TRIM" + UPS_BOOST = "BOOST" + UPS_FSD = "FSD" + + @dataclass class UPSSensor: ups_status: list[UPSStatus] = None