checkers are now objects, lay foundation for persistent alerts

This commit is contained in:
Alex Tau 2025-06-05 21:45:01 +03:00
parent 5d2759c63c
commit eef6ec59b0
12 changed files with 162 additions and 81 deletions

View file

@ -1,18 +1,18 @@
from psutil import cpu_percent
from lego_monitoring.alerting import alerts
from lego_monitoring.alerting.alert import Alert
from lego_monitoring.alerting.enum import AlertType, Severity
from lego_monitoring.core import cvars
IS_TESTING = False
def cpu_check() -> list[alerts.Alert]:
def cpu_check() -> list[Alert]:
percentage = cpu_percent()
config = cvars.config.get().checks.cpu
if config.critical_percentage and (IS_TESTING or percentage > config.critical_percentage):
return [
alerts.Alert(
Alert(
alert_type=AlertType.CPU,
message=f"CPU load: {percentage:.2f}% > {config.critical_percentage:.2f}%",
severity=Severity.CRITICAL,
@ -20,7 +20,7 @@ def cpu_check() -> list[alerts.Alert]:
]
elif config.warning_percentage and (IS_TESTING or percentage > config.warning_percentage):
return [
alerts.Alert(
Alert(
alert_type=AlertType.CPU,
message=f"CPU load: {percentage:.2f}% > {config.warning_percentage:.2f}%",
severity=Severity.WARNING,