feat: global notification policy severity to channels (notif-22)

Singleton notification_policy table, NOTIFY_MIN_SEVERITY/CHANNELS env,
central dispatch gate, Settings policy UI, migration 007.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-05-29 16:19:26 +10:00
parent 9b177c145b
commit ebb450be92
19 changed files with 577 additions and 126 deletions
+22 -7
View File
@@ -1,18 +1,33 @@
"""Dispatch ingest notifications to all configured channels."""
"""Dispatch ingest notifications per global policy (severity → channels)."""
from sqlalchemy.orm import Session
from app.models import Event, Problem
from app.services import email_notify, telegram_notify, webhook_notify
from app.services.notification_policy import get_effective_notification_policy
from app.services.notification_severity import severity_meets_minimum
from app.services.notification_settings import CHANNEL_EMAIL, CHANNEL_TELEGRAM, CHANNEL_WEBHOOK
def notify_event(event: Event, *, db: Session | None = None) -> None:
telegram_notify.notify_event(event, db=db)
webhook_notify.notify_event(event, db=db)
email_notify.notify_event(event, db=db)
policy = get_effective_notification_policy(db)
if not severity_meets_minimum(event.severity, policy.min_severity):
return
if policy.use_telegram:
telegram_notify.notify_event(event, db=db, apply_policy_gate=False)
if policy.use_webhook:
webhook_notify.notify_event(event, db=db, apply_policy_gate=False)
if policy.use_email:
email_notify.notify_event(event, db=db, apply_policy_gate=False)
def notify_problem(problem: Problem, event: Event | None = None, *, db: Session | None = None) -> None:
telegram_notify.notify_problem(problem, event, db=db)
webhook_notify.notify_problem(problem, event, db=db)
email_notify.notify_problem(problem, event, db=db)
policy = get_effective_notification_policy(db)
if not severity_meets_minimum(problem.severity, policy.min_severity):
return
if policy.use_telegram:
telegram_notify.notify_problem(problem, event, db=db, apply_policy_gate=False)
if policy.use_webhook:
webhook_notify.notify_problem(problem, event, db=db, apply_policy_gate=False)
if policy.use_email:
email_notify.notify_problem(problem, event, db=db, apply_policy_gate=False)