Files
checkbot/app/alerts/report_status.py
T
patrickandClaude Sonnet 5.5 5278530467
test / pytest (3.11) (push) Waiting to run
test / pytest (3.13) (push) Waiting to run
feat: Phase 6b rules with delay, delta format, reminders, zpool default rule
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 02:38:10 +01:00

36 lines
1.3 KiB
Python

import math
from dataclasses import dataclass
from typing import Mapping, Sequence
from ..models import STATE_OK
from ..mutes import Mute, find_active_mute
from ..routing import Route, resolve_delay
SECONDS_PER_MINUTE = 60
STATUS_REPORTED = "reported"
STATUS_WAITING = "waiting"
STATUS_SUPPRESSED = "suppressed"
STATUS_DUE = "due"
@dataclass(frozen=True)
class ReportStatus:
kind: str
label: str
def report_status(row: Mapping, rules: Sequence[Route], mutes: Sequence[Mute], default_minutes: int,
now: float) -> ReportStatus:
if row["in_downtime"]:
return ReportStatus(STATUS_SUPPRESSED, "unterdrückt (Downtime)")
if find_active_mute(mutes, row["host"], row["service"], now):
return ReportStatus(STATUS_SUPPRESSED, "unterdrückt (Stummschaltung)")
if row["flap_reported"] or (row["reported_state"] != STATE_OK and row["reported_state"] == row["state"]):
return ReportStatus(STATUS_REPORTED, "gemeldet")
delay = resolve_delay(rules, row["host"], row["service"], row["state"], row["output"], default_minutes)
remaining = delay * SECONDS_PER_MINUTE - (now - row["last_state_change"])
if remaining <= 0:
return ReportStatus(STATUS_DUE, "wird beim nächsten Abruf gemeldet")
return ReportStatus(STATUS_WAITING, f"wartet noch {math.ceil(remaining / SECONDS_PER_MINUTE)} min")