CI / Lint (flake8, house style) (pull_request) Successful in 54s
CI / Test (pytest) (pull_request) Successful in 55s
CI / Security (bandit, pip-audit) (pull_request) Successful in 56s
CI / Integration (MariaDB) (pull_request) Successful in 2m2s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m30s
CI / Deploy (pull_request) Skipped
- checks/reboots.py (thor#4): boot-time changes classified as planned (logind line), unexpected, or unknown (journal went quiet first); several together are one event. - checks/cluster.py: HA fence lines, watchdog self-fences, corosync quorum loss: one host is 'lost its cluster link and was fenced' (P2), two or more a cluster partition (P1). - checks/maintenance.py: Gandalf suppressions (with ended ones) as a cause that never opens a ticket; everything under it goes on the timeline. - Engine: higher causes first, lower causes they explain become symptoms; a higher cause found later absorbs pending ones and comments 'Root cause' on opened ones; host-scoped causes never explain another host's cause; incidents stay active while an attached host is still down; silent state changes are saved; notes join timeline-only incidents. - Known conditions (migration 3, seeded): compute-storage-02 reboots and Ceph noout -> 693930698, the old UPS battery. A match sends a note to that ticket instead of a new one. - Replays: T2 0 tickets; T3 one P2 (fenced, cleared when the host is back); T4 one P1 partition (storage-01's later fence and all reboots fold in); DIMM one note on 693930698. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
3.3 KiB
Python
102 lines
3.3 KiB
Python
"""Findings, incidents and ticket actions.
|
|
|
|
A check turns source data into **findings**. A finding is either a **cause** (something that
|
|
can own a ticket: a host out of memory) or a **symptom** (something that is usually the
|
|
result of a cause: scrapes timing out, a new Ceph alert). The engine groups findings into
|
|
**incidents**, one per root cause, keyed by the incident key that becomes the Tinker
|
|
``dedup_key`` (``scope:subject:kind``, thor#1 contract).
|
|
"""
|
|
from dataclasses import dataclass, field
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
# Cause precedence (thor#1, Area 4): when several causes are active, symptoms attach to the
|
|
# highest. Maintenance, power, network and partitions arrive with later checks.
|
|
LAYER_MAINTENANCE = 90
|
|
LAYER_POWER = 80
|
|
LAYER_NETWORK = 70
|
|
LAYER_PARTITION = 60
|
|
LAYER_HOST_DOWN = 50
|
|
LAYER_RESOURCE = 40
|
|
LAYER_CEPH = 30
|
|
LAYER_SCRAPE = 20
|
|
|
|
CAUSE = 'cause'
|
|
SYMPTOM = 'symptom'
|
|
NOTE = 'note' # shown in Thor, never a ticket; only joins timeline-only incidents (maintenance)
|
|
|
|
# Incident states
|
|
PENDING = 'pending' # seen, held one cycle so same-moment symptoms land in the first text
|
|
OPEN = 'open'
|
|
CLEARED = 'cleared'
|
|
|
|
|
|
@dataclass
|
|
class Finding:
|
|
kind: str
|
|
subject: str # canonical host name, or 'cluster'
|
|
role: str # CAUSE, SYMPTOM or NOTE
|
|
layer: int
|
|
start: float
|
|
end: float
|
|
key: str # incident key for a cause; a stable symptom key otherwise
|
|
summary: str
|
|
priority: int = 3
|
|
check: str = ''
|
|
facts: Dict[str, Any] = field(default_factory=dict)
|
|
events: List[Dict[str, Any]] = field(default_factory=list) # dated items, deduplicated by 'id'
|
|
cluster_effect: bool = False # can be the result of trouble on another host
|
|
# False for causes that explain things but never become tickets (planned maintenance).
|
|
ticket: bool = True
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return dict(self.__dict__)
|
|
|
|
|
|
@dataclass
|
|
class Incident:
|
|
key: str
|
|
kind: str
|
|
subject: str
|
|
layer: int
|
|
check: str
|
|
state: str = PENDING
|
|
priority: int = 3
|
|
first_seen: float = 0.0
|
|
last_seen: float = 0.0
|
|
pending_since: float = 0.0
|
|
opened_at: Optional[float] = None
|
|
cleared_at: Optional[float] = None
|
|
summary: str = ''
|
|
facts: Dict[str, Any] = field(default_factory=dict)
|
|
events: List[Dict[str, Any]] = field(default_factory=list)
|
|
symptoms: Dict[str, Dict[str, Any]] = field(default_factory=dict)
|
|
ticket_id: Optional[str] = None
|
|
mode: str = 'shadow'
|
|
seen_after_the_fact: bool = False
|
|
ticket: bool = True
|
|
# A known condition covers this incident: notes go to that ticket instead of a new one.
|
|
known_ticket: Optional[str] = None
|
|
known_reason: str = ''
|
|
|
|
@property
|
|
def active(self) -> bool:
|
|
return self.state in (PENDING, OPEN)
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return dict(self.__dict__)
|
|
|
|
@classmethod
|
|
def from_dict(cls, d: Dict[str, Any]) -> 'Incident':
|
|
known = {k: v for k, v in d.items() if k in cls.__dataclass_fields__}
|
|
return cls(**known)
|
|
|
|
|
|
@dataclass
|
|
class Action:
|
|
"""Something to tell Tinker. In shadow mode it is recorded and never sent."""
|
|
incident_key: str
|
|
kind: str # 'open', 'escalate', 'refresh', 'also_seen', 'cleared'
|
|
created: float
|
|
mode: str # 'shadow' or 'live'
|
|
payload: Dict[str, Any] = field(default_factory=dict)
|