Files
checkbot/app/models.py
T

56 lines
1.0 KiB
Python

from dataclasses import dataclass
KIND_PROBLEM = "problem"
KIND_RECOVERY = "recovery"
KIND_FLAPPING = "flapping"
STATE_OK = 0
STATE_NAMES = {0: "OK", 1: "WARN", 2: "CRIT", 3: "UNKNOWN"}
SUPPRESS_DOWNTIME = "downtime"
SUPPRESS_MUTE = "mute"
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
@property
def wants_ai(self) -> bool:
return self.kind == KIND_PROBLEM and not self.suppressed
@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
@property
def key(self) -> Key:
return (self.host, self.service)