Files
checkbot/app/models.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

70 lines
1.5 KiB
Python

from dataclasses import dataclass
KIND_PROBLEM = "problem"
KIND_RECOVERY = "recovery"
KIND_FLAPPING = "flapping"
KIND_REMINDER = "reminder"
STATE_OK = 0
STATE_CRIT = 2
STATE_NAMES = {0: "OK", 1: "WARN", 2: "CRIT", 3: "UNKNOWN"}
SUPPRESS_DOWNTIME = "downtime"
SUPPRESS_MUTE = "mute"
SUPPRESS_RECOVERY_OFF = "recovery_aus"
SUPPRESS_NOT_REPORTED = "nicht_gemeldet"
AI_PENDING = "pending"
AI_DONE = "done"
AI_FAILED = "failed"
AI_SKIPPED = "skipped"
Key = tuple[str, str]
def state_name(state: int) -> str:
return STATE_NAMES.get(state, "UNKNOWN")
@dataclass(frozen=True)
class Event:
ts: int
host: str
service: str
kind: str
state: int
output: str = ""
suppressed: bool = False
suppress_reason: str | None = None
previous_state: int | None = None
previous_duration: int | None = None
since_ts: int | None = None
problem_since_ts: int | None = None
ai_enabled: bool = True
ai_hint: str = ""
@property
def wants_ai(self) -> bool:
return self.kind == KIND_PROBLEM and not self.suppressed and self.ai_enabled
@dataclass(frozen=True)
class StateRow:
host: str
service: str
state: int
output: str
last_state_change: int
in_downtime: bool
flapping: bool
reported_state: int
flap_reported: bool
problem_since: int | None = None
reported_at: int = 0
reported_since: int = 0
last_reminder_ts: int = 0
@property
def key(self) -> Key:
return (self.host, self.service)