max / makenotwork
| 1 | -- Inbound infra-alert ingestion (pom / MT / other monitoring agents -> MNW). |
| 2 | -- |
| 3 | -- External monitoring agents (PoM health/TLS/DNS watchers, the Multithreaded |
| 4 | -- forum's own probes) had no way to reach an operator: the health monitor in |
| 5 | -- `monitor.rs` only emails on *this server's* status transitions, and there is |
| 6 | -- no admin notification center. This table is the durable log behind the |
| 7 | -- `POST /api/internal/alerts` ingestion endpoint: each accepted alert is |
| 8 | -- persisted here and also emailed to ALERT_EMAIL. Admin-routed only -- these are |
| 9 | -- ops signals for the operator, never creator-facing. |
| 10 | -- |
| 11 | -- `source` names the reporting agent ("pom", "mt", ...). `kind` is the alert |
| 12 | -- domain the agent assigns ("health"/"tls"/"dns"/"whois"/"backup"/... — see the |
| 13 | -- AlertKind enum) and `severity` the urgency ("critical"/"warning"/"info"); |
| 14 | -- both are closed sets enforced at the application layer. Stored as TEXT (not an |
| 15 | -- enum type) so extending either set is a code change, not a migration. |
| 16 | -- `dedup_key` lets an agent collapse repeated firings of the same condition |
| 17 | -- (e.g. one row per (source, dedup_key) flap) without the server modeling agent |
| 18 | -- state; it is nullable for one-shot alerts. |
| 19 | NOT EXISTS admin_alerts ( |
| 20 | id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 21 | source TEXT NOT NULL, |
| 22 | kind TEXT NOT NULL, |
| 23 | severity TEXT NOT NULL, |
| 24 | title TEXT NOT NULL, |
| 25 | body TEXT NOT NULL, |
| 26 | dedup_key TEXT, |
| 27 | details JSONB, |
| 28 | received_at TIMESTAMPTZ NOT NULL DEFAULT now, |
| 29 | emailed BOOLEAN NOT NULL DEFAULT false |
| 30 | ); |
| 31 | |
| 32 | -- The admin log view is "newest first", so index the sort key. |
| 33 | NOT EXISTS idx_admin_alerts_received ON admin_alerts (received_at DESC); |
| 34 |