Home AI SkillsAI Incident Summaries: Turn Alertmanager Alerts into Postmortems

AI Incident Summaries: Turn Alertmanager Alerts into Postmortems

by Knowledge Base Linux
AI incident summaries generated from monitoring alerts illustration

After a 2 a.m. incident, nobody wants to write the postmortem. The data exists — alerts, graphs, chat messages — but assembling it into a clear timeline takes an hour nobody has. AI incident summaries close that gap: when Prometheus Alertmanager fires, a small webhook service collects the alert details, asks an LLM to write a structured summary, and posts it to your team channel. Later, the same pipeline drafts the postmortem skeleton. This guide shows you how to build it.

How AI Incident Summaries Fit Your Alert Pipeline

Alertmanager already knows how to group, silence and route alerts. What it cannot do is explain them. The architecture we will build keeps Alertmanager in charge of detection and adds an AI layer purely for communication:

  1. Alertmanager fires an alert and sends the standard webhook payload to our receiver.
  2. The receiver enriches the payload with a few facts (host, severity, duration, related metric snapshot).
  3. An LLM turns the JSON into a readable incident summary: what, where, impact, first checks.
  4. The summary is posted to Slack/Telegram and archived, becoming the first draft of the postmortem.

Detection stays deterministic; only the wording is delegated to AI. That separation is what makes AI incident summaries safe to run in production.

Prerequisites

  • Prometheus and Alertmanager running (any recent version).
  • A Linux host with Python 3.10+ and pip for the webhook receiver.
  • An LLM API key, or a local model endpoint for sensitive environments.
  • A Slack incoming webhook or Telegram bot for delivery. (If you use Zabbix instead, its media-type webhooks can feed the same receiver.)

Step 1: Configure an Alertmanager Webhook Receiver

Add a receiver that points at our service (running on port 9099) alongside your existing routes:

receivers:
  - name: 'ai-summary'
    webhook_configs:
      - url: 'http://localhost:9099/alert'
        send_resolved: true
route:
  receiver: 'ai-summary'
  group_by: ['alertname', 'instance']
  group_wait: 30s
  repeat_interval: 4h

Reload Alertmanager after editing: curl -X POST http://localhost:9093/-/reload.

Step 2: Build the Receiver That Creates AI Incident Summaries

This Flask service accepts the Alertmanager payload, builds a strict prompt, and asks the LLM for a structured summary:

# receiver.py
import json, os, urllib.request
from flask import Flask, request

app = Flask(__name__)
LLM_KEY = os.environ["LLM_API_KEY"]

def summarize(alerts):
    lines = []
    for a in alerts:
        labels, ann = a.get("labels", {}), a.get("annotations", {})
        lines.append(f"- {a['status'].upper()}: {labels.get('alertname')} on "
                     f"{labels.get('instance')} severity={labels.get('severity')} "
                     f"summary={ann.get('summary','')} starts={a.get('startsAt')}")
    prompt = ("You are an SRE assistant. Write an incident summary from these alerts.\n"
              "Format:\nTITLE: one line\nIMPACT: one line\nTIMELINE: bullet list\n"
              "LIKELY CAUSES: max 3 bullets\nFIRST CHECKS: max 3 commands or dashboards\n"
              "Never invent metrics that are not in the data.\n\n" + "\n".join(lines))
    body = json.dumps({"model": "gpt-4o-mini",
        "messages": [{"role": "user", "content": prompt}], "temperature": 0.1}).encode()
    req = urllib.request.Request("https://api.openai.com/v1/chat/completions",
        data=body, headers={"Authorization": f"Bearer {LLM_KEY}",
        "Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=60) as r:
        return json.load(r)["choices"][0]["message"]["content"]

@app.post("/alert")
def alert():
    payload = request.get_json(force=True)
    text = summarize(payload.get("alerts", []))
    with open("/var/log/incident-summaries.md", "a") as f:
        f.write("\n\n---\n" + text)
    post_to_slack(text)   # your webhook call here
    return {"ok": True}

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=9099)

Install and run it:

pip install flask
export LLM_API_KEY="sk-..."
nohup python3 receiver.py > /var/log/ai-receiver.log 2>&1 &
AI incident summaries timeline used in a postmortem draft

Step 3: Turn AI Incident Summaries into Postmortem Drafts

Because every summary is archived in the same format, the postmortem writes itself. At the end of an incident, feed the archived summaries plus the resolution note back to the model:

PROMPT:
"Using these incident summaries and the resolution note below, draft a
postmortem with sections: Summary, Impact, Timeline, Root Cause,
What Went Well, What Went Poorly, Action Items (each with an owner
placeholder). Mark any fact you are unsure about as [VERIFY]."

The [VERIFY] markers are essential practice, the same discipline described in our monitoring guides: AI drafts, humans confirm. Reviewers then spend ten minutes correcting facts instead of an hour reconstructing the night.

Step 4: Keep the Summaries Honest

  • Include raw values: pass the actual metric snapshot (for example “CPU 97% at 02:14”) in the prompt, so the model never needs to invent numbers.
  • Low temperature: 0–0.2 keeps wording factual and repeatable.
  • Cap the input: summarize per alert group, not per thousand alerts, or a flapping storm will bury the signal.
  • Never auto-execute: the pipeline informs humans; it must never restart services or change infrastructure on its own.

Troubleshooting

No webhook arrives. Check Alertmanager’s own log and confirm the route references the new receiver; test the endpoint manually with curl -X POST localhost:9099/alert -d @sample.json.

Summaries arrive but sound generic. Your payload lacks context. Add annotations to your alert rules (summary, description, runbook URL) — the model can only use what you send.

Duplicate posts for one incident. Tune group_by and repeat_interval in Alertmanager, and have the receiver skip payloads whose groupKey it already processed within the repeat window.

The LLM call fails during the outage. Queue summaries to disk and retry with backoff; the archive file approach above already preserves the raw material for a later draft.

Conclusion

AI incident summaries take the most hated part of on-call work — writing it all up afterwards — and reduce it to reviewing a draft. Wire Alertmanager’s webhook into a small receiver, give the model structured facts and a strict format, and archive everything. Your alerts become clearer in the moment, your postmortems faster afterwards, and your team’s knowledge stops disappearing into chat history.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.