Hotovo. Přidal jsem správu Alertingu do appfactory-portal bez ORM:

Nové SQL migrace pro alert_rules a alert_events v migrations.py (line 165).
Nová ruční DB vrstva v alerting.py (line 7).
Nové stránky a akce v routes/alerting.py (line 288):Alert pravidla, detail, vytvoření, úprava, smazání
povolit/zakázat pravidlo
Alert eventy a detail eventu s payload_json
odkazy z job_id na detail úlohy
detail pravidla s posledními eventy
admin-only editor .sh alert skriptů v /opt/appfactory/workspace/appfactory-tools/alerts
audit eventy podle zadání

Menu Provoz → Alerting v layout.py (line 23).
Router je zaregistrovaný v main.py (line 8).
This commit is contained in:
JiriUhlir
2026-06-08 06:57:12 +02:00
parent 64f8fe806d
commit 382825085f
5 changed files with 941 additions and 1 deletions
+37
View File
@@ -160,6 +160,43 @@ def run_migrations():
con.execute("CREATE INDEX IF NOT EXISTS idx_app_variables_app_id ON app_variables(app_id)")
con.execute("CREATE INDEX IF NOT EXISTS idx_service_incidents_status_started ON service_incidents(status, started_at)")
con.execute("CREATE INDEX IF NOT EXISTS idx_service_incidents_service_started ON service_incidents(service_id, started_at)")
con.execute(
"""
CREATE TABLE IF NOT EXISTS alert_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
event_type TEXT NOT NULL,
service_id TEXT,
script_name TEXT NOT NULL,
is_enabled INTEGER NOT NULL DEFAULT 1,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
)
"""
)
con.execute(
"""
CREATE TABLE IF NOT EXISTS alert_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
rule_id INTEGER,
event_type TEXT NOT NULL,
service_id TEXT,
incident_id INTEGER,
status TEXT,
job_id INTEGER,
error_text TEXT,
payload_json TEXT,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
processed_at TEXT
)
"""
)
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_rules_event_enabled ON alert_rules(event_type, is_enabled)")
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_rules_service ON alert_rules(service_id)")
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_events_rule_created ON alert_events(rule_id, created_at)")
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_events_created ON alert_events(created_at)")
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_events_job_id ON alert_events(job_id)")
con.commit()
con.close()