Alerts
The alerting system delivers Prometheus alerts to Matrix rooms (and via email for incidents). A one-time provisioning of the bot is enough: everything is declarative afterwards. The overall architecture is described in Monitoring & Alerting.
Prerequisites
Section titled “Prerequisites”| Prerequisite | Why |
|---|---|
prometheus + monitoring on the collector | carries Alertmanager and the rules |
matrix service reachable | hosts the bot and channels |
SSH access to the Matrix host (nix) | creates the bot account with dnf-mas |
| Admin sops key present | writes the bot secrets |
Install the bot
Section titled “Install the bot”A single command, idempotent (safe to run repeatedly): it creates the bot account, channels, and writes the identity to var/generated/matrix.nix.
-
Declare the administrators (local parties) in the configuration:
etc/config.yaml network:matrix:admins: ["alice", "bob"] -
Run the provisioning:
Fenêtre de terminal just configure-alert-botThe command, leveraging the admin sops key:
- creates the
@alertbot:domain.tldaccount (dnf-mas manage register-useron the Matrix host); - creates or resolves the
#alert-warningsand#alert-incidentschannels, adds the bot to them and invites the admins; - writes
botand channel IDs tovar/generated/matrix.nix; - stores the password, access token and webhook secret in sops.
- creates the
-
Deploy the collector:
Fenêtre de terminal just generatejust apply <collector>Alerting activates automatically as soon as the channels exist (
var/generated/matrix.nixis populated). To disable it anyway:darkone.service.prometheus.alerting.enable = false;.
Created secrets
Section titled “Created secrets”Provisioning stores three secrets in usr/secrets/secrets.yaml:
| Sops key | Role |
|---|---|
alertmanager-matrix-password | bot account password (reconnection) |
alertmanager-matrix-token | bot access token (message sending) |
alertmanager-webhook-secret | authenticates Alertmanager to the Matrix bridge |
Sending a message to a room
Section titled “Sending a message to a room”Once the bot is in place, any tool in the project can write to the alert rooms. The message body, in markdown, arrives on standard input:
just send-msg warnings < rapport.mdecho "**Sauvegarde nocturne** : 2 dépôts en retard" | just send-msg incidentsThe recipe reads the rooms from var/generated/matrix.nix and the token from sops, under the deployment identity nix. The caller therefore does not need to know either of them.
Markdown is converted to HTML before sending; otherwise Matrix clients would display it as-is: headings, lists, bold, code and links. No italics: a lone * is a host pattern (gw-*).
| Exit code | Meaning |
|---|---|
0 | Message sent |
10 | Nothing configured here: missing room, token or program |
11 | The Matrix server refused the message |
Testing an alert
Section titled “Testing an alert”-
On a supervised node, stop a monitored service:
Fenêtre de terminal sudo systemctl stop <unit> -
Within a minute, a
ServiceDown(orSystemdUnitFailed) message appears in#alert-warnings,#alert-incidentsand an email if the node is critical. The alert link points tohttps://prometheus.<zone>.domain.tld. -
Restart the service: the alert resolves (resolution notification). For
SystemdUnitFailed, resolution only comes after 30 minutes without failure (why).Fenêtre de terminal sudo systemctl start <unit>
Silencing during a rebuild
Section titled “Silencing during a rebuild”The deployment flow sets a maintenance flag to avoid triggering false alerts
during a nixos-rebuild. Manually:
dnf-maintenance on # inhibits node alertsdnf-maintenance off # re-enables themSilencing a known alert
Section titled “Silencing a known alert”Some alerts are accurate but not actionable: a backup drive intentionally filled
permanently triggers DiskSpaceLow. silences prevents them from notifying.
{ darkone.service.prometheus.alerting.silences = [ { alert = "DiskSpaceLow"; host = "srv-backup"; matchers.device = "/dev/sdb"; reason = '' Disque de sauvegarde volontairement rempli, seuil structurellement franchi. Retirer si la rétention est réduite. ''; } ];}| Field | Role |
|---|---|
alert | Name of the alert to silence (alertname) |
host | Target host name (host label), null for the entire fleet |
matchers | Additional labels in strict equality, combined with AND |
reason | Required: why the alert is accepted |
Each entry becomes an Alertmanager route to the null receiver. The alert
continues to fire and remains visible in Prometheus, Alertmanager, and Grafana;
it simply stops notifying.
Verify routing on the Prometheus host:
amtool config routes test --config.file=/etc/alertmanager.yml \ alertname=DiskSpaceLow host=srv-backup device=/dev/sdbTo silence a systemic failure mode rather than an isolated case, see
ignoredUnits (dnf/config/alerts.nix), which excludes a systemd unit from
SystemdUnitFailed across the entire fleet.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause | Fix |
|---|---|---|
| No messages in a room | bot not in the room or expired token | re-run just configure-alert-bot |
| Room creation 403 | Caddy anti-bot filter | already handled (neutral agent) ; do not use raw curl |
admin API not public | /_synapse/admin closed | let the automatic SSH tunnel work (Matrix host must be reachable) |
| Unresolved alert link | missing DNS or certificate for the prometheus vhost | deploy the gateway / HCS for the new subdomain |
matrix.nix ignored at deploy | file not readable by nix | the script does a chmod 644 ; check var/generated/ permissions |
| No incident email | local Postfix relay inactive | alerting enables it by default ; check darkone.service.prometheus.alerting.email |