try to use OK alerts to reflect successful checks

This commit is contained in:
Alex Tau 2025-08-15 18:02:43 +03:00
parent d59d5ac4e2
commit 5f9952314d
8 changed files with 22 additions and 17 deletions

View file

@ -56,7 +56,7 @@ class CommandHandlerManager:
if not isinstance(c, BaseChecker) or not c.persistent:
continue
for a in c.current_alerts:
if a.alert_type not in alert_num_by_state_with_max_type:
if a.alert_type not in alert_num_by_state_with_max_type and a.severity != Severity.OK:
alert_num_by_state_with_max_type[a.alert_type] = [a.severity, 1]
else:
existing_list = alert_num_by_state_with_max_type[a.alert_type]
@ -80,6 +80,8 @@ class CommandHandlerManager:
if not isinstance(c, BaseChecker) or not c.persistent:
continue
for a in c.current_alerts:
if a.severity == Severity.OK:
continue
message = format_message(a, note="ongoing")
messages.add(message)
if len(messages) == 0:

View file

@ -22,7 +22,7 @@ class AlertType(StrEnum):
class Severity(IntEnum):
OK = 0 # should only be used when persistent alerts resolve
OK = 0
INFO = 1
WARNING = 2
CRITICAL = 3

View file

@ -38,7 +38,7 @@ def format_message(alert: Alert, note: str) -> str:
async def send_alert(alert: Alert, note: str = "") -> None:
try:
client = cvars.tg_client.get()
tg_client = cvars.tg_client.get()
except LookupError: # being called standalone
# cvars.config.set(get_config())
# temp_client = True
@ -47,10 +47,10 @@ async def send_alert(alert: Alert, note: str = "") -> None:
raise NotImplementedError # TODO
else:
... # temp_client = False
if client is not None:
if tg_client is not None:
room_id = cvars.config.get().alert_channels.telegram.room_id
message = format_message(alert, note)
await client.send_message(entity=room_id, message=message)
await tg_client.send_message(entity=room_id, message=message)
# if temp_client:
# await client.close()