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

44 lines
1.7 KiB
Python

from typing import Callable, Sequence
from ..models import KIND_PROBLEM, Event
from .limits import AI_HINTS_TOTAL_MAX
from .rules import Route, matching_rules
SECONDS_PER_MINUTE = 60
def _problem_probe(host: str, service: str, state: int, output: str) -> Event:
return Event(0, host, service, KIND_PROBLEM, state, output)
def resolve_delay(rules: Sequence[Route], host: str, service: str, state: int, output: str,
default_minutes: int) -> int:
found = matching_rules(rules, _problem_probe(host, service, state, output))
delays = [r.delay_minutes for r in found if r.delay_minutes is not None]
return min(delays) if delays else default_minutes
def delay_provider(rules: Sequence[Route], default_minutes: int) -> Callable[[str, str, int, str], int]:
def seconds(host: str, service: str, state: int, output: str) -> int:
return resolve_delay(rules, host, service, state, output, default_minutes) * SECONDS_PER_MINUTE
return seconds
def ai_allowed(rules: Sequence[Route], event: Event) -> bool:
return all(rule.ai_enabled for rule in matching_rules(rules, event))
def resolve_loud(rules: Sequence[Route], event: Event) -> bool:
found = matching_rules(rules, event)
return not found or any(rule.loud for rule in found)
def ai_hints(rules: Sequence[Route], event: Event) -> str:
hints = [rule.ai_hint.strip() for rule in matching_rules(rules, event) if rule.ai_hint.strip()]
return "\n".join(hints)[:AI_HINTS_TOTAL_MAX]
def reminder_interval(rules: Sequence[Route], event: Event) -> int:
hours = [r.reminder_hours for r in matching_rules(rules, event) if r.reminder_hours and r.reminder_hours > 0]
return min(hours) if hours else 0