Stage 6 · Operate
Alerting with Alertmanager
Receivers and Templates
Sending alerts to Slack, email, webhooks, Opsgenie, and PagerDuty with Go templating.
Receiver Overview
Receivers define how and where Alertmanager sends notifications. Each receiver specifies one or more notification channels. Common channels include Slack, email, PagerDuty, Opsgenie, and generic webhooks.
receivers:
- name: "slack-warnings"
slack_configs:
- api_url: "https://hooks.slack.com/services/T00/B00/xxx"
channel: "#alerts-warnings"
- name: "email-oncall"
email_configs:
- to: "oncall@example.com"
from: "alertmanager@example.com"
smarthost: "smtp.example.com:587"
- name: "pagerduty-critical"
pagerduty_configs:
- service_key: "your-pagerduty-key"Slack Receiver
The Slack receiver sends notifications to a Slack channel using an incoming webhook URL. Configure the channel, title, and message template to control how alerts appear in Slack.
receivers:
- name: "slack-critical"
slack_configs:
- api_url: "https://hooks.slack.com/services/T00/B00/xxx"
channel: "#alerts-critical"
title: '{{ range .Alerts }}{{ .Labels.alertname }}{{ end }}'
text: >-
{{ range .Alerts }}
*Alert:* {{ .Labels.alertname }}
*Severity:* {{ .Labels.severity }}
*Instance:* {{ .Labels.instance }}
*Description:* {{ .Annotations.description }}
{{ end }}Email Receiver
The email receiver sends HTML or plain text emails. Configure SMTP settings, sender, recipients, and optionally a template for the email body. Email is useful for non-urgent alerts and audit trails.
receivers:
- name: "email-team"
email_configs:
- to: "team@example.com"
from: "alertmanager@example.com"
smarthost: "smtp.example.com:587"
auth_username: "alertmanager@example.com"
auth_password: "secret"
headers:
Subject: '[{{ .Status | toUpper }}] {{ .GroupLabels.alertname }}'Webhook Receiver
The webhook receiver sends a JSON payload to an HTTP endpoint. This integrates with any system that accepts webhooks, including custom incident management platforms, ChatOps tools, and automation systems.
receivers:
- name: "webhook-custom"
webhook_configs:
- url: "https://api.example.com/alerts"
send_resolved: true
http_config:
authorization:
type: "Bearer"
credentials: "your-api-token"Go Templates
Alertmanager uses Go templates to format notification content. Templates have access to the alert data including labels, annotations, and grouping information. You can define custom templates in template files.
template_files:
- "/etc/alertmanager/templates/*.tmpl"
# In alertmanager.yml
templates:
- "/etc/alertmanager/templates/*.tmpl"Template Functions
Go templates provide functions for formatting alert data. Common functions include toUpper, toLower, humanize, and the range iterator for looping over alerts and labels.
Use 'amtool template render' to test templates against sample alert data before deploying. This catches formatting errors and ensures notifications look correct in Slack, email, or other channels.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.