mirror of
https://forgejo.altau.su/lego/lego-monitoring.git
synced 2026-03-10 04:41:10 +00:00
move upsstatus enum to sensors
This commit is contained in:
parent
47c110f83e
commit
071d8afb9f
3 changed files with 25 additions and 28 deletions
|
|
@ -5,7 +5,6 @@ from datetime import timedelta
|
||||||
from alerting import alerts
|
from alerting import alerts
|
||||||
from misc import cvars, docker_registry, sensors, vuln
|
from misc import cvars, docker_registry, sensors, vuln
|
||||||
from misc.disks import LVAttr
|
from misc.disks import LVAttr
|
||||||
from misc.enums import UPSStatus
|
|
||||||
|
|
||||||
IS_TESTING = False
|
IS_TESTING = False
|
||||||
|
|
||||||
|
|
@ -126,13 +125,13 @@ async def ups_check() -> list[alerts.Alert]:
|
||||||
)
|
)
|
||||||
|
|
||||||
for status in sensor.ups_status:
|
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(
|
alert_list.append(
|
||||||
alerts.Alert(
|
alerts.Alert(
|
||||||
alert_type=alerts.AlertType.UPS, message=f"UPS is overloaded!", severity=alerts.Severity.CRITICAL
|
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(
|
alert_list.append(
|
||||||
alerts.Alert(
|
alerts.Alert(
|
||||||
alert_type=alerts.AlertType.UPS,
|
alert_type=alerts.AlertType.UPS,
|
||||||
|
|
@ -140,7 +139,7 @@ async def ups_check() -> list[alerts.Alert]:
|
||||||
severity=alerts.Severity.INFO,
|
severity=alerts.Severity.INFO,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif IS_TESTING or status == UPSStatus.UPS_TRIM:
|
elif IS_TESTING or status == sensors.UPSStatus.UPS_TRIM:
|
||||||
alert_list.append(
|
alert_list.append(
|
||||||
alerts.Alert(
|
alerts.Alert(
|
||||||
alert_type=alerts.AlertType.UPS,
|
alert_type=alerts.AlertType.UPS,
|
||||||
|
|
@ -148,7 +147,7 @@ async def ups_check() -> list[alerts.Alert]:
|
||||||
severity=alerts.Severity.INFO,
|
severity=alerts.Severity.INFO,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif IS_TESTING or status == UPSStatus.UPS_BOOST:
|
elif IS_TESTING or status == sensors.UPSStatus.UPS_BOOST:
|
||||||
alert_list.append(
|
alert_list.append(
|
||||||
alerts.Alert(
|
alerts.Alert(
|
||||||
alert_type=alerts.AlertType.UPS,
|
alert_type=alerts.AlertType.UPS,
|
||||||
|
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import StrEnum
|
||||||
|
|
||||||
from psutil import cpu_percent, sensors_temperatures, virtual_memory
|
from psutil import cpu_percent, sensors_temperatures, virtual_memory
|
||||||
|
|
||||||
from alerting import alerts
|
from alerting import alerts
|
||||||
|
|
||||||
from .enums import UPSStatus
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TemperatureSensor:
|
class TemperatureSensor:
|
||||||
|
|
@ -32,6 +31,26 @@ class RamSensor:
|
||||||
critical_avail: int = 2 * 1024**3
|
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
|
@dataclass
|
||||||
class UPSSensor:
|
class UPSSensor:
|
||||||
ups_status: list[UPSStatus] = None
|
ups_status: list[UPSStatus] = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue