feat: webhook notification channel with UI and ingest dispatch

Add webhook config (DB/env), JSON POST on events/problems, settings API,
Settings UI section, and notify_dispatch for multi-channel ingest.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 16:09:40 +10:00
parent f7b5fff04e
commit 20fa7e2c27
13 changed files with 826 additions and 189 deletions
+50
View File
@@ -22,6 +22,56 @@ def test_get_notification_settings_masks_secrets(jwt_headers, client, monkeypatc
assert body["telegram"]["min_severity"] == "warning"
assert body["telegram"]["source"] == "env"
assert body["telegram"]["bot_token_hint"].endswith("ghij")
assert "webhook" in body
assert body["webhook"]["enabled"] is False
def test_put_webhook_settings_persists_db(jwt_headers, client, db_session, monkeypatch):
monkeypatch.setenv("WEBHOOK_ENABLED", "false")
monkeypatch.setenv("WEBHOOK_URL", "")
get_settings.cache_clear()
response = client.put(
"/api/v1/settings/notifications/webhook",
headers=jwt_headers,
json={
"enabled": True,
"min_severity": "warning",
"url": "https://example.com/hooks/sac",
"secret_header": "X-SAC-Token",
"secret": "supersecret",
},
)
assert response.status_code == 200
body = response.json()
assert body["source"] == "db"
assert body["configured"] is True
row = db_session.get(NotificationChannel, "webhook")
assert row is not None
assert row.webhook_url == "https://example.com/hooks/sac"
assert row.webhook_secret_header == "X-SAC-Token"
def test_post_webhook_test_success(jwt_headers, client, db_session, monkeypatch):
monkeypatch.setenv("WEBHOOK_ENABLED", "false")
get_settings.cache_clear()
db_session.add(
NotificationChannel(
channel="webhook",
enabled=True,
min_severity="warning",
webhook_url="https://example.com/hook",
)
)
db_session.commit()
with patch("app.api.v1.settings.send_webhook_test_message") as mock_test:
response = client.post("/api/v1/settings/notifications/webhook/test", headers=jwt_headers)
assert response.status_code == 200
assert response.json()["ok"] is True
mock_test.assert_called_once()
def test_put_telegram_settings_persists_db(jwt_headers, client, db_session, monkeypatch):