Add alerting database and default alert script
This commit is contained in:
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DB_FILE="/opt/appfactory/data/appfactory/appfactory.db"
|
||||
|
||||
python3 - "$DB_FILE" <<'PY'
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
con = sqlite3.connect(sys.argv[1])
|
||||
|
||||
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 NOT NULL DEFAULT 'queued',
|
||||
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
|
||||
ON alert_rules(event_type, is_enabled)
|
||||
""")
|
||||
|
||||
con.execute("""
|
||||
CREATE INDEX IF NOT EXISTS idx_alert_events_status
|
||||
ON alert_events(status, created_at)
|
||||
""")
|
||||
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
print("Alerting migration completed.")
|
||||
PY
|
||||
Reference in New Issue
Block a user