Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
global:
smtp_smarthost: "smtp.example.com:587"
smtp_from: "alerts@example.com"
smtp_auth_username: "alerts@example.com"
smtp_auth_password_file: /etc/alertmanager/smtp_password
route:
receiver: ops-email
group_by: ["alertname", "instance"]
routes:
- matchers: ['severity="critical"']
receiver: oncall-slack
receivers:
- name: ops-email
email_configs:
- to: "ops@example.com"
send_resolved: true
- name: oncall-slack
slack_configs:
- api_url_file: /etc/alertmanager/slack_url
channel: "#oncall"
send_resolved: trueStep by step
- Write the secrets into files (not into the YAML, so the YAML can live in Git):
install -m 600 -o alertmanager /dev/null /etc/alertmanager/slack_url
install -m 600 -o alertmanager /dev/null /etc/alertmanager/smtp_passwordPut the Slack incoming webhook URL (Slack app → Incoming Webhooks → Add to channel) into slack_url, and the SMTP password into smtp_password.
- An alert rule in Prometheus — with
for:(no message for a 10-second blip) and a clear summary:
groups:
- name: web
rules:
- alert: SiteDown
expr: probe_success{job="blackbox"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} does not answer"(probe_success comes from the blackbox exporter; for servers use up == 0.)
- Routing (quick answer): everything goes to
ops-emailby default;severity="critical"goes to Slack.group_bymakes one message per alert name and server, not one per alert. - Test before you trust it — ask where an alert would go, then send a real test alert:
amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml severity=critical alertname=SiteDown
oncall-slack
amtool --alertmanager.url=http://127.0.0.1:9093 alert add TestAlert severity=critical instance=web1 --annotation=summary="Test from amtool"The Slack message should arrive within about 30 seconds (group_wait).
- Silence during maintenance — always with an end time and a reason:
amtool --alertmanager.url=http://127.0.0.1:9093 silence add instance=web1 --duration=2h --comment="Patch window OPS-311"- Good alerts: alert on what users feel (site down, errors, slow) and on what will break soon (disk in 4 hours) — not on every CPU spike. Every critical alert needs a short runbook link in its annotations.
Check that it worked
The test alert arrives in Slack (critical) and a warning test arrives by email; when the test alert expires you get the resolved message too. In Prometheus → Alerts your rules are listed (inactive = green).
Common problems
| Problem | Cause | Fix |
|---|---|---|
| The rule fires, no message arrives | Prometheus does not know Alertmanager, or the route sends it elsewhere. | Check alerting: in prometheus.yml; amtool config routes test …. |
Slack: invalid_token / 404 | Wrong or deleted webhook URL. | Make a new incoming webhook; write it to slack_url. |
Email: 535 authentication failed / TLS errors | SMTP login or port. | Port 587 + smtp_require_tls; check user and password file. |
| Too many messages (alert storm) | No grouping, rules without for:, warnings for everything. | group_by, for:, inhibit rules; delete noisy rules. |
| Same alert every few minutes | repeat_interval too short. | 4h for warnings, 1h for critical. |
| No "resolved" message | send_resolved not set. | Add send_resolved: true to the receiver. |
Go further
- Command pages: amtool, promtool.
- Next how-tos: Monitor a Linux server with Prometheus, Build a Grafana dashboard, Check when a TLS certificate expires, Write a runbook for on-call.
- Full guide: Alertmanager: routes, receivers, tests and silences. At work: Alertmanager, Alerts in DevOps.
- Practise: Lab: monitoring stack in one hour, Lab: a burn-rate alert from an SLO.
1Why does an alert rule need for: 2m?
So a short blip does not page anybody; the condition must be true for 2 minutes first.