Introduction#
Prometheus Alertmanager is powerful, but its routing configuration can be complex. Using n8n as an alert handler gives you more flexibility - route based on any criteria, enrich alerts with additional data, and integrate with any notification system.
Prerequisites#
- An n8n instance with public webhook URL
- Prometheus with Alertmanager configured
- PagerDuty account (for critical alerts)
- Slack workspace (for warnings)
Workflow Overview#
| |
Step-by-Step Setup#
Step 1: Configure Alertmanager#
Add n8n as a webhook receiver in alertmanager.yml:
| |
Step 2: Create the Webhook Endpoint#
- Add a Webhook node in n8n
- Set HTTP Method to
POST - Set path to
alertmanager - Response Mode:
On Received
Alertmanager sends payloads like:
| |
Step 3: Split Alerts#
Add a Split In Batches node to process each alert individually:
- Batch Size:
1 - Input:
{{ $json.alerts }}
Step 4: Route by Severity#
Add a Switch node based on severity:
Condition 1 - Critical:
| |
→ Route to PagerDuty
Condition 2 - Warning:
| |
→ Route to Slack
Default: → Route to Email
Step 5: Send to PagerDuty#
For critical alerts, add a PagerDuty node:
| |
Step 6: Send to Slack#
For warnings, add a Slack node:
Channel: #alerts
Message:
| |
Step 7: Send Email (Optional)#
For low-severity alerts:
To: ops-team@company.com
Subject: [{{ $json.labels.severity }}] {{ $json.labels.alertname }}
Body: Alert details
Advanced Routing#
Route by Team#
Different teams own different services:
| |
Business Hours Routing#
Reduce noise outside business hours:
| |
Alert Enrichment#
Add context from other sources:
| |
Handling Resolved Alerts#
Alertmanager sends status: resolved when alerts clear:
| |
Troubleshooting#
Alerts Not Arriving#
- Check Alertmanager logs for webhook errors
- Verify n8n webhook URL is accessible
- Test with curl:
curl -X POST your-webhook-url -d '{"test": true}'
Duplicate Alerts#
- Use
dedup_keyin PagerDuty - Implement deduplication in n8n with a cache
Missing Labels#
- Check your Prometheus alerting rules
- Ensure labels are propagated through Alertmanager
Best Practices#
- Use deduplication - Prevent alert storms
- Include runbook links - Speed up resolution
- Set appropriate severities - Reserve critical for true emergencies
- Test your routing - Use Alertmanager’s test endpoint
- Monitor your monitoring - Alert if n8n webhook fails
Conclusion#
Using n8n to handle Prometheus alerts gives you unlimited flexibility in routing, enrichment, and notification. You can adapt quickly to changing requirements without modifying Alertmanager configuration.
Download the complete workflow from our n8n Workflow Gallery.
