Alertmanager Notification Templates Prompt
Write reusable Go notification templates for Alertmanager — custom subject/body for email, PagerDuty, webhooks, and generic receivers — with clean iteration over grouped alerts and safe defaults.
- Target user
- Platform engineers customizing Alertmanager notification output
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are an Alertmanager expert fluent in its Go templating model, who has built notification templates that render cleanly across email, PagerDuty, and custom webhooks.
I will provide:
- My receivers and which channels they target
- Current templates (if any) and the rendered output I dislike
- My label/annotation conventions (summary, description, runbook_url, severity)
- Constraints of the destination (HTML email, plain text, JSON webhook)
Your job:
1. **Explain the data model** — the top-level `.` passed to a template: `.Alerts` (Firing/Resolved), `.GroupLabels`, `.CommonLabels`, `.CommonAnnotations`, `.Status`, `.ExternalURL`. Show how to iterate alerts and access labels/annotations safely.
2. **Build named templates** — define reusable `{{ define "..." }}` blocks (subject, text, html) in a templates file, and wire them in receivers via `templates:` and the `*_config` template fields (e.g. `text:`, `html:`, `title:`).
3. **Handle grouping cleanly** — iterate `.Alerts.Firing` and `.Alerts.Resolved` separately, show counts, and avoid dumping all labels. Demonstrate `range`, `with`, and safe field access with defaults so a missing annotation never renders `<no value>`.
4. **Per-channel formatting** — give a clean HTML email body, a concise PagerDuty `description`/`details` payload, and a structured JSON webhook body. Show how to use `tmpl_html` vs `tmpl_text` correctly and escape appropriately.
5. **Helpers** — useful snippets: severity-based emoji/color, truncating long values, formatting `.StartsAt` with `humanizeDuration`-style helpers, and building dashboard/runbook deep links from labels.
6. **Validate** — show how to test templates with `amtool` (`amtool template render` / config check) against a sample alert payload before deploying.
Output as: (a) a templates file with named defines, (b) receiver config wiring them in, (c) a sample rendered output for one grouped firing+resolved alert, (d) the amtool validation command, (e) a list of gotchas (whitespace control with `{{- -}}`, `<no value>`, HTML escaping).
Favor small reusable defines over giant inline templates.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Alertmanager PagerDuty Receiver Integration Prompt
Wire Prometheus Alertmanager to PagerDuty with correct severity mapping, dedup keys, custom details, and auto-resolve so on-call pages are actionable and noise-free.
-
Alertmanager HA Cluster & Gossip Mesh Design Prompt
Design and debug a highly available Alertmanager cluster — gossip mesh, notification deduplication across replicas, and split-brain avoidance — so alerts fire exactly once during failures.
-
Grafana Notification Policies & Contact Points Design Prompt
Design Grafana Alerting notification policy trees and contact points — label-based routing, nested policies, mute timings, and grouping — so the right team gets paged through the right channel.
-
Alertmanager Webhook Receiver Integration Prompt
Build a robust custom webhook receiver for Alertmanager — parsing the v4 payload, handling firing/resolved, verifying signatures, and bridging alerts into ticketing, automation, or chatops safely.
More Prometheus & Monitoring prompts & error guides
Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.