Skip to content

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.

PrerequisiteWhy
prometheus + monitoring on the collectorcarries Alertmanager and the rules
matrix service reachablehosts the bot and channels
SSH access to the Matrix host (nix)creates the bot account with dnf-mas
Admin sops key presentwrites the bot secrets

A single command, idempotent (safe to run repeatedly): it creates the bot account, channels, and writes the identity to var/generated/matrix.nix.

  1. Declare the administrators (local parties) in the configuration:

    etc/config.yaml
    network:
    matrix:
    admins: ["alice", "bob"]
  2. Run the provisioning:

    Fenêtre de terminal
    just configure-alert-bot

    The command, leveraging the admin sops key:

    • creates the @alertbot:domain.tld account (dnf-mas manage register-user on the Matrix host);
    • creates or resolves the #alert-warnings and #alert-incidents channels, adds the bot to them and invites the admins;
    • writes bot and channel IDs to var/generated/matrix.nix;
    • stores the password, access token and webhook secret in sops.
  3. Deploy the collector:

    Fenêtre de terminal
    just generate
    just apply <collector>

    Alerting activates automatically as soon as the channels exist (var/generated/matrix.nix is populated). To disable it anyway: darkone.service.prometheus.alerting.enable = false;.

Provisioning stores three secrets in usr/secrets/secrets.yaml:

Sops keyRole
alertmanager-matrix-passwordbot account password (reconnection)
alertmanager-matrix-tokenbot access token (message sending)
alertmanager-webhook-secretauthenticates Alertmanager to the Matrix bridge

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:

Fenêtre de terminal
just send-msg warnings < rapport.md
echo "**Sauvegarde nocturne** : 2 dépôts en retard" | just send-msg incidents

The 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 codeMeaning
0Message sent
10Nothing configured here: missing room, token or program
11The Matrix server refused the message
  1. On a supervised node, stop a monitored service:

    Fenêtre de terminal
    sudo systemctl stop <unit>
  2. Within a minute, a ServiceDown (or SystemdUnitFailed) message appears in #alert-warnings, #alert-incidents and an email if the node is critical. The alert link points to https://prometheus.<zone>.domain.tld.

  3. 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>

The deployment flow sets a maintenance flag to avoid triggering false alerts during a nixos-rebuild. Manually:

Fenêtre de terminal
dnf-maintenance on # inhibits node alerts
dnf-maintenance off # re-enables them

Some alerts are accurate but not actionable: a backup drive intentionally filled permanently triggers DiskSpaceLow. silences prevents them from notifying.

usr/modules/alerts.nix
{
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.
'';
}
];
}
FieldRole
alertName of the alert to silence (alertname)
hostTarget host name (host label), null for the entire fleet
matchersAdditional labels in strict equality, combined with AND
reasonRequired: 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:

Fenêtre de terminal
amtool config routes test --config.file=/etc/alertmanager.yml \
alertname=DiskSpaceLow host=srv-backup device=/dev/sdb

To 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.

SymptomLikely causeFix
No messages in a roombot not in the room or expired tokenre-run just configure-alert-bot
Room creation 403Caddy anti-bot filteralready handled (neutral agent) ; do not use raw curl
admin API not public/_synapse/admin closedlet the automatic SSH tunnel work (Matrix host must be reachable)
Unresolved alert linkmissing DNS or certificate for the prometheus vhostdeploy the gateway / HCS for the new subdomain
matrix.nix ignored at deployfile not readable by nixthe script does a chmod 644 ; check var/generated/ permissions
No incident emaillocal Postfix relay inactivealerting enables it by default ; check darkone.service.prometheus.alerting.email