1. The routing tree #
Each alert walks down the tree.
Principle #
Each alert enters through the root route and then goes down into the first child route whose matchers match (recursively). If no child route matches, the current route applies. With continue: true, evaluation continues to sibling routes (to notify several recipients).
route:
receiver: defaut
group_by: [alertname, cluster]
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
routes:
- matchers: ['team="db"']
receiver: dba-mail
routes:
- matchers: ['severity="critical"']
receiver: dba-pager
- matchers: ['team="web"']
receiver: web-slack
- matchers: ['alertname="Watchdog"']
receiver: deadman
repeat_interval: 1mThe three delays #
| Parameter | Default | Meaning |
|---|---|---|
group_wait | 30s | Wait before the first notification of a new group (to group alerts arriving together) |
group_interval | 5m | Wait before notifying an already notified group that has received new alerts |
repeat_interval | 4h | Reminder for an unchanged group that is still active |
Good practice: Test a route without waiting for a real alert: amtool config routes test --config.file=alertmanager.yml team=db severity=critical shows the chosen receiver.2. Receivers #
Where notifications go.
Examples #
global:
smtp_smarthost: smtp.example.org:587
smtp_from: alertmanager@example.org
smtp_auth_username: alertmanager
smtp_auth_password_file: /etc/alertmanager/smtp_password
receivers:
- name: defaut
email_configs:
- to: ops@example.org
- name: dba-mail
email_configs:
- to: dba@example.org
- name: dba-pager
pagerduty_configs:
- routing_key_file: /etc/alertmanager/pagerduty_key
- name: web-slack
slack_configs:
- api_url_file: /etc/alertmanager/slack_url
channel: '#alertes-web'
send_resolved: true
title: '{{ .CommonLabels.alertname }} ({{ .Status }})'
text: '{{ range .Alerts }}• {{ .Annotations.summary }}{{ "\n" }}{{ end }}'
- name: teams
msteamsv2_configs:
- webhook_url_file: /etc/alertmanager/teams_url
- name: deadman
webhook_configs:
- url: https://hc-ping.com/<uuid>Other native integrations: Opsgenie, VictorOps, Pushover, Telegram, Discord, Webex, SNS, Jira, Rocket.Chat... and the generic webhook for everything else.
Good practice: Use the*_filevariants (api_url_file,routing_key_file) to keep secrets out of the versioned configuration file.
3. Message templates #
Readable notifications.
Templates #
# alertmanager.yml
templates: ['/etc/alertmanager/templates/*.tmpl']{{/* templates/slack.tmpl */}}
{{ define "slack.titre" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }}{{ end }}
{{ define "slack.texte" }}{{ range .Alerts }}
*{{ .Annotations.summary }}*
{{ if .Annotations.runbook_url }}Runbook : {{ .Annotations.runbook_url }}{{ end }}
{{ end }}{{ end }}slack_configs:
- title: '{{ template "slack.titre" . }}'
text: '{{ template "slack.texte" . }}'