RousselTMLEARNING

Observability

Routing, grouping and receivers in Alertmanager

The Alertmanager routing tree: matchers, group_by, group_wait, group_interval, repeat_interval, continue, receivers (email, Slack, Teams, webhook, PagerDuty) and message templates.

1. The routing tree #

Each alert walks down the tree.

Principle #

Routing tree
An alert with team=db severity=critical goes down to dba-pager.

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: 1m

The three delays #

ParameterDefaultMeaning
group_wait30sWait before the first notification of a new group (to group alerts arriving together)
group_interval5mWait before notifying an already notified group that has received new alerts
repeat_interval4hReminder 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 *_file variants (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" . }}'

Related articles

Alertmanager: role, architecture and lifecycle of an alert

What Alertmanager does between Prometheus and your teams: deduplication, grouping, routing, silences and inhi…

Writing good Prometheus alerting rules (and testing them)

Design useful alerts: alert on symptoms, choose for and thresholds, severity and team labels, annotations and…

Silences, inhibitions and time intervals in Alertmanager

Reduce alert noise: one-off silences with amtool, inhibition rules (a critical alert mutes secondary alerts) …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!