Inhibition, Silences & Notification Templates
Routing decides where alerts go. Three more Alertmanager features decide whether they go at all, and what the message says:
| Feature | Configured | Lives | Use |
|---|---|---|---|
| Inhibition | inhibit_rules in the config file |
permanently | "if A fires, don't notify about B" (the cluster is down → don't page for every service in it) |
| Silence | at runtime: UI, amtool silence add, API |
until it expires | planned maintenance, a known issue being worked on |
| Templates | templates: files + *_configs fields |
permanently | readable Slack/PagerDuty messages |
A live Alertmanager
The session starts Alertmanager on localhost (no cluster peers), posts four alerts with amtool alert add (the same API Prometheus uses), and looks at what is active, inhibited and silenced:
cat > alertmanager.yml <<'YML'
route:
receiver: default
group_by: [alertname, service]
receivers:
- name: default
inhibit_rules:
# while a service is paging, don't also notify its ticket-level alerts
- source_matchers: [severity="page"]
target_matchers: [severity="ticket"]
equal: [service]
# a whole cluster unreachable hides every per-service alert in that cluster
- source_matchers: [alertname="ClusterUnreachable"]
target_matchers: [alertname!="ClusterUnreachable"]
equal: [cluster]
YML
alertmanager --config.file=alertmanager.yml --storage.path=am-data \
--web.listen-address=127.0.0.1:9093 --cluster.listen-address= >am.log 2>&1 &
for i in $(seq 100); do curl -sf 127.0.0.1:9093/-/ready >/dev/null && break; sleep 0.2; done
am() { amtool --alertmanager.url=http://127.0.0.1:9093 "$@"; }
am alert add LinklyHighErrorRate severity=page service=linkly cluster=eu-1 \
--annotation='summary="5xx ratio 12%"' --start=2026-01-01T10:00:00Z
am alert add LinklySlowQueries severity=ticket service=linkly cluster=eu-1 --start=2026-01-01T10:01:00Z
am alert add PostgresDiskFilling severity=ticket service=postgres cluster=eu-1 --start=2026-01-01T10:02:00Z
am alert add RedisEvictions severity=ticket service=redis cluster=eu-1 --start=2026-01-01T10:03:00Z
sleep 1
state() { # every alert with its state and what suppresses it
am alert query --active --silenced --inhibited -o json |
jq -r '.[] | "\(.labels.alertname) \(.status.state) inhibitedBy=\(.status.inhibitedBy | length) silencedBy=\(.status.silencedBy | length)"' | sort
}
echo "--- before silences:"; state
am silence add service=postgres --author=ada --comment="OPS-142: resizing the volume" --duration=2h >/dev/null
am silence add 'alertname=~"Redis.*"' --author=ada --comment="known issue, fix in 1.5.1" --duration=24h >/dev/null
echo "--- silences:"
am silence query -o json | jq -r '.[] | "\([.matchers[] | "\(.name)\(if .isRegex then "=~" else "=" end)\(.value)"] | join(",")) by \(.createdBy): \(.comment)"' | sort
echo "--- after silences:"; state--- before silences:
LinklyHighErrorRate active inhibitedBy=0 silencedBy=0
LinklySlowQueries suppressed inhibitedBy=1 silencedBy=0
PostgresDiskFilling active inhibitedBy=0 silencedBy=0
RedisEvictions active inhibitedBy=0 silencedBy=0
--- silences:
alertname=~Redis.* by ada: known issue, fix in 1.5.1
service=postgres by ada: OPS-142: resizing the volume
--- after silences:
LinklyHighErrorRate active inhibitedBy=0 silencedBy=0
LinklySlowQueries suppressed inhibitedBy=1 silencedBy=0
PostgresDiskFilling suppressed inhibitedBy=0 silencedBy=1
RedisEvictions suppressed inhibitedBy=0 silencedBy=1
LinklySlowQueries(a ticket) is inhibited by the page for the sameservice; the Postgres and Redis tickets have other services, soequal: [service]doesn't apply to them. When the page resolves, the inhibition ends and the ticket is notified if it still fires.- The two silences hide the Postgres and Redis alerts. Silences match on labels with the same operators as routes; a regex silence like
alertname=~"Redis.*"is powerful and dangerous: make them as narrow as possible. - In production, always give silences a comment with a ticket reference and an end time. A silence that outlives its reason hides the next real incident.
amtool silence query --expiredandamtool silence expire <id>help clean up.
Prometheus re-sends firing alerts on every evaluation with an end time a few minutes ahead; if the alerts stop arriving (rule resolved, Prometheus down), Alertmanager resolves them when that end time passes. That's why amtool alert add alerts in this session would resolve on their own after a few minutes.
Inhibition pitfalls
- Without
equal, a page for any service inhibits tickets for all services. Always scope withequal. - If the source alert's labels also match the target matchers, an alert can inhibit itself; the second rule above excludes
ClusterUnreachablefrom its own targets for that reason. - Inhibited alerts are still visible in the UI and API (as above): inhibition stops notifications, not information.
Notification templates
Receivers have fields like title, text (Slack) or description, details (PagerDuty) that accept Go templates over the notification's data: .Status (firing/resolved), .Alerts (with .Firing, .Resolved), .CommonLabels, .CommonAnnotations, .GroupLabels, .ExternalURL. Define reusable templates in a file:
cat > linkly.tmpl <<'TMPL'
{{ define "linkly.title" -}}
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} ({{ .CommonLabels.service }})
{{- end }}
{{ define "linkly.text" -}}
{{ range .Alerts -}}
• {{ .Labels.instance }}: {{ .Annotations.summary }}
{{ end -}}
Runbook: {{ .CommonAnnotations.runbook_url }}
{{- end }}
TMPL
cat > data.json <<'JSON'
{
"receiver": "team-links-slack",
"status": "firing",
"alerts": [
{"status": "firing", "labels": {"alertname": "LinklyHighErrorRate", "service": "linkly", "instance": "api-1"},
"annotations": {"summary": "5xx ratio 12%", "runbook_url": "https://runbooks.example.com/linkly/errors"}},
{"status": "firing", "labels": {"alertname": "LinklyHighErrorRate", "service": "linkly", "instance": "api-2"},
"annotations": {"summary": "5xx ratio 9%", "runbook_url": "https://runbooks.example.com/linkly/errors"}}
],
"groupLabels": {"alertname": "LinklyHighErrorRate", "service": "linkly"},
"commonLabels": {"alertname": "LinklyHighErrorRate", "service": "linkly"},
"commonAnnotations": {"runbook_url": "https://runbooks.example.com/linkly/errors"},
"externalURL": "http://alertmanager.example.com"
}
JSON
amtool template render --template.glob='linkly.tmpl' --template.data=data.json \
--template.text='{{ template "linkly.title" . }}{{ "\n" }}{{ template "linkly.text" . }}'[FIRING:2] LinklyHighErrorRate (linkly)
• api-1: 5xx ratio 12%
• api-2: 5xx ratio 9%
Runbook: https://runbooks.example.com/linkly/errors
amtool template render lets you iterate on messages without sending anything. Wire them into receivers:
templates:
- /etc/alertmanager/templates/*.tmpl
receivers:
- name: team-links-slack
slack_configs:
- api_url_file: /etc/alertmanager/secrets/slack-links
channel: '#links-alerts'
send_resolved: true
title: '{{ template "linkly.title" . }}'
text: '{{ template "linkly.text" . }}'
- name: oncall-pagerduty
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pagerduty-links
description: '{{ template "linkly.title" . }}'
severity: criticalKeep secrets (webhook URLs, routing keys) in files (api_url_file, routing_key_file) or Kubernetes Secrets, never in the main config in Git. The resulting Slack message (sample):
[FIRING:2] LinklyHighErrorRate (linkly)
• api-1: 5xx ratio 12%
• api-2: 5xx ratio 9%
Runbook: https://runbooks.example.com/linkly/errorsTest yourself
What does equal: [service] do in an inhibit rule?
- Requires the service label to equal "service"
- Only inhibits targets whose
servicelabel value equals the source alert's - Groups by service
- Silences the service
When should you use a silence instead of an inhibit rule?
- For permanent dependencies between alerts
- For temporary, known situations such as maintenance, with an end time and a comment
- Never
- For routing
Where should a Slack webhook URL live?
- Inline in alertmanager.yml in Git
- In a file or Secret referenced with
api_url_file - In the alert's labels
- In the template