Configure Prometheus Alertmanager with custom webhook integrations for Slack, Microsoft Teams, and PagerDuty notifications

Intermediate 45 min May 30, 2026 59 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up Prometheus Alertmanager with webhook receivers for Slack, Microsoft Teams, and PagerDuty notifications. Configure routing rules, test notifications, and implement alert escalation workflows for comprehensive monitoring coverage.

Prerequisites

  • Prometheus server already installed and running
  • Slack workspace with webhook permissions
  • Microsoft Teams with webhook connector access
  • PagerDuty account with service integration
  • Basic understanding of YAML configuration

What this solves

Prometheus Alertmanager handles alerts sent by Prometheus servers and routes them to receiver endpoints like Slack, email, or PagerDuty. This tutorial configures webhook integrations for three popular notification channels, sets up routing rules to send different alerts to different teams, and implements escalation policies for critical incidents.

Step-by-step installation and configuration

Install Prometheus Alertmanager

Download and install the latest version of Alertmanager. This creates the alertmanager user and service files automatically.

wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
tar xvfz alertmanager-0.27.0.linux-amd64.tar.gz
sudo mv alertmanager-0.27.0.linux-amd64/alertmanager /usr/local/bin/
sudo mv alertmanager-0.27.0.linux-amd64/amtool /usr/local/bin/
sudo useradd --no-create-home --shell /bin/false alertmanager
sudo mkdir /etc/alertmanager
sudo mkdir /var/lib/alertmanager
sudo chown alertmanager:alertmanager /etc/alertmanager /var/lib/alertmanager
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
tar xvfz alertmanager-0.27.0.linux-amd64.tar.gz
sudo mv alertmanager-0.27.0.linux-amd64/alertmanager /usr/local/bin/
sudo mv alertmanager-0.27.0.linux-amd64/amtool /usr/local/bin/
sudo useradd --no-create-home --shell /bin/false alertmanager
sudo mkdir /etc/alertmanager
sudo mkdir /var/lib/alertmanager
sudo chown alertmanager:alertmanager /etc/alertmanager /var/lib/alertmanager

Create systemd service file

Configure Alertmanager to run as a systemd service with proper resource limits and automatic restarts.

[Unit]
Description=Alertmanager
Wants=network-online.target
After=network-online.target

[Service]
User=alertmanager
Group=alertmanager
Type=simple
ExecStart=/usr/local/bin/alertmanager \
    --config.file /etc/alertmanager/alertmanager.yml \
    --storage.path /var/lib/alertmanager/ \
    --web.external-url=http://localhost:9093 \
    --cluster.listen-address=""
Restart=always

[Install]
WantedBy=multi-user.target

Configure Slack webhook integration

Set up Slack webhook URL and configure message templates. Replace the webhook URL with your actual Slack incoming webhook.

global:
  smtp_smarthost: 'localhost:587'
  smtp_from: 'alertmanager@example.com'

route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 1h
  receiver: 'web.hook'
  routes:
  - match:
      service: critical
    receiver: pagerduty-critical
    routes:
    - match:
        severity: critical
      receiver: pagerduty-critical
      continue: true
    - match:
        severity: critical
      receiver: slack-critical
  - match:
      service: database
    receiver: slack-database
  - match:
      service: frontend
    receiver: teams-frontend

receivers:
  • name: 'web.hook'
slack_configs: - api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK' channel: '#alerts' title: 'Alertmanager Notification' text: 'Summary: {{ range .Alerts }}{{ .Annotations.summary }}{{ end }}' send_resolved: true
  • name: 'slack-critical'
slack_configs: - api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK' channel: '#critical-alerts' title: 'CRITICAL: {{ .GroupLabels.alertname }}' text: | {{ range .Alerts }} Alert: {{ .Annotations.summary }} Description: {{ .Annotations.description }} Severity: {{ .Labels.severity }} Instance: {{ .Labels.instance }} {{ end }} color: 'danger' send_resolved: true
  • name: 'slack-database'
slack_configs: - api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK' channel: '#database-alerts' title: 'Database Alert: {{ .GroupLabels.alertname }}' text: | {{ range .Alerts }} Database Issue: {{ .Annotations.summary }} Details: {{ .Annotations.description }} Server: {{ .Labels.instance }} Time: {{ .StartsAt.Format "2006-01-02 15:04:05" }} {{ end }} color: 'warning' send_resolved: true

Add Microsoft Teams webhook integration

Configure Teams webhook receiver with custom message cards. Add this receiver configuration to your existing alertmanager.yml file.

sudo tee -a /etc/alertmanager/alertmanager.yml << 'EOF'

  • name: 'teams-frontend'
webhook_configs: - url: 'https://outlook.office.com/webhook/YOUR-TEAMS-WEBHOOK-URL' send_resolved: true http_config: follow_redirects: true title: 'Frontend Alert: {{ .GroupLabels.alertname }}' text: | { "@type": "MessageCard", "@context": "https://schema.org/extensions", "summary": "Frontend Alert", "themeColor": "FF6B35", "sections": [ { "activityTitle": "{{ .GroupLabels.alertname }}", "activitySubtitle": "Frontend Service Alert", "facts": [ {{ range .Alerts }} { "name": "Alert", "value": "{{ .Annotations.summary }}" }, { "name": "Severity", "value": "{{ .Labels.severity }}" }, { "name": "Instance", "value": "{{ .Labels.instance }}" } {{ end }} ] } ] } EOF

Configure PagerDuty integration

Set up PagerDuty webhook for critical alerts with escalation policies. Replace the routing key with your actual PagerDuty integration key.

sudo tee -a /etc/alertmanager/alertmanager.yml << 'EOF'

  • name: 'pagerduty-critical'
pagerduty_configs: - routing_key: 'YOUR-PAGERDUTY-INTEGRATION-KEY' description: '{{ range .Alerts }}{{ .Annotations.summary }}{{ end }}' details: alert_count: '{{ len .Alerts }}' alerts: | {{ range .Alerts }} - Alert: {{ .Annotations.summary }} Description: {{ .Annotations.description }} Severity: {{ .Labels.severity }} Instance: {{ .Labels.instance }} Started: {{ .StartsAt.Format "2006-01-02 15:04:05" }} {{ end }} client: 'Alertmanager' client_url: 'http://your-alertmanager.example.com:9093' links: - href: 'http://your-prometheus.example.com:9090/graph?g0.expr={{ range .Alerts }}{{ .GeneratorURL }}{{ end }}' text: 'View in Prometheus' EOF

Set correct file permissions

Ensure Alertmanager can read its configuration file and has proper ownership of data directories.

sudo chown alertmanager:alertmanager /etc/alertmanager/alertmanager.yml
sudo chmod 640 /etc/alertmanager/alertmanager.yml
sudo chown -R alertmanager:alertmanager /var/lib/alertmanager
Never use chmod 777. It gives every user on the system full access to your files. The alertmanager service only needs read access to its config file (640) and full access to its data directory (owned by alertmanager user).

Validate configuration and start service

Test the configuration syntax before starting the service to catch any YAML formatting errors.

sudo /usr/local/bin/alertmanager --config.file=/etc/alertmanager/alertmanager.yml --config.check
sudo systemctl daemon-reload
sudo systemctl enable --now alertmanager
sudo systemctl status alertmanager

Configure Prometheus to send alerts

Update your Prometheus configuration to send alerts to Alertmanager. Add this to your prometheus.yml file.

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - localhost:9093

rule_files:
  - "alert_rules.yml"

Create sample alert rules

Define alert rules that will trigger notifications to test your webhook integrations.

groups:
  • name: example_alerts
rules: - alert: InstanceDown expr: up == 0 for: 1m labels: severity: critical service: critical annotations: summary: "Instance {{ $labels.instance }} is down" description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minute." - alert: HighMemoryUsage expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes > 0.8 for: 5m labels: severity: warning service: database annotations: summary: "High memory usage on {{ $labels.instance }}" description: "Memory usage is above 80% for more than 5 minutes on {{ $labels.instance }}." - alert: HighCPUUsage expr: 100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80 for: 2m labels: severity: warning service: frontend annotations: summary: "High CPU usage detected" description: "CPU usage is above 80% for more than 2 minutes."

Restart Prometheus to load new configuration

Reload Prometheus configuration to enable alert rules and Alertmanager integration.

sudo systemctl restart prometheus
sudo systemctl status prometheus

Test webhook notifications

Send test alerts using amtool

Use the Alertmanager tool to send test notifications and verify your webhook integrations work correctly.

# Test Slack critical alert
sudo -u alertmanager /usr/local/bin/amtool alert add alertname="TestCritical" service="critical" severity="critical" instance="test-server" summary="This is a test critical alert"

Test Teams frontend alert

sudo -u alertmanager /usr/local/bin/amtool alert add alertname="TestFrontend" service="frontend" severity="warning" instance="web-server" summary="Frontend test alert for Teams"

Test database Slack alert

sudo -u alertmanager /usr/local/bin/amtool alert add alertname="TestDatabase" service="database" severity="warning" instance="db-server" summary="Database test alert for Slack"

Verify webhook delivery

Check Alertmanager logs and your notification channels to confirm alerts are being delivered properly.

sudo journalctl -u alertmanager -f
curl -s http://localhost:9093/api/v1/alerts | python3 -m json.tool

Verify your setup

sudo systemctl status alertmanager
curl -s http://localhost:9093/-/healthy
curl -s http://localhost:9093/api/v1/status | python3 -m json.tool
sudo -u alertmanager /usr/local/bin/amtool config show

Access the Alertmanager web interface at http://your-server:9093 to view active alerts and test your routing rules. You can also silence alerts, view notification history, and manage alert groups from the web interface.

Common issues

Symptom Cause Fix
Service won't start YAML syntax error in config alertmanager --config.check to validate syntax
Slack notifications not received Invalid webhook URL Test webhook URL with curl -X POST webhook-url -d '{"text":"test"}'
PagerDuty alerts not triggering Wrong integration key Verify integration key in PagerDuty service settings
Teams webhook fails Message card JSON format error Validate JSON syntax in webhook payload
Alerts not routing correctly Label matching issues Check alert labels match route conditions exactly
Permission denied errors Wrong file ownership chown alertmanager:alertmanager /etc/alertmanager/*

Next steps

Running this in production?

Need this managed for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and tuned across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.