Webhook icon
Schedule icon
WorkingDirectory icon
Commands icon
Script icon
Process icon
Request icon
If icon
Loop icon
Create icon
MailSend icon
Log icon
SlackIncomingWebhook icon

Bridge incident alerts into Mattermost and page the on-call

Posts severity-tagged Mattermost notes on incident status changes, tracks open incidents and pages the on-call with a ticket for opened sev1 or sev2 events.

Categories
Infrastructure

Incident tools that only talk to themselves leave the channel guessing. This flow receives every incident status change as a webhook event carrying the incident id, severity, status and summary, then becomes the bridge into Mattermost. A python step applies the event to a tracked state file, walks the opened, acknowledged and resolved lifecycle, counts how many incidents are still open and builds the severity-tagged channel payload that a core HTTP task posts to a Mattermost incoming webhook. When a sev1 or sev2 has just opened, a loop pages every on-call target through a second webhook, a labeled GitHub issue is filed and sev1 pages also reach the on-call mailbox; acknowledgements, resolutions and sev3 or sev4 events stay channel-only with a log line.

How it works

  1. incident_status_change (io.kestra.plugin.core.trigger.Webhook) accepts one JSON body of incident_id, severity, status and summary from the incident tool. daily_state_reconcile (io.kestra.plugin.core.trigger.Schedule, cron 0 6 * * *) sits disabled as the morning net to switch on once the webhook path is trusted.
  2. workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared directory for the state file and the bridge step that consumes it.
  3. write_incident_state (io.kestra.plugin.scripts.shell.Commands) drops incident-state.json from a heredoc of three tracked incidents, one opened, one acknowledged and one resolved, so the open count is measured against real history.
  4. bridge_incident (io.kestra.plugin.scripts.python.Script on the Process runner) reads the state file with the json module, merges the incoming event into it, walks the opened to acknowledged to resolved lifecycle with a transition note, counts the incidents still open, builds the #channel payload with the severity mark and prints one ::{"outputs": ...}:: line carrying verdict, channel_posted, severity, open_incidents and channel_payload.
  5. post_channel_message (io.kestra.plugin.core.http.Request) POSTs the built payload to the Mattermost incoming webhook stored in MATTERMOST_WEBHOOK_URL, so the channel always sees the lifecycle note for this event.
  6. escalation_gate (io.kestra.plugin.core.flow.If) fires only when the severity is sev1 or sev2 and the verdict is PAGE_ESCALATED. In that branch page_oncall (io.kestra.plugin.core.flow.Loop, concurrencyLimit: 1) walks page_targets and send_page (io.kestra.plugin.core.http.Request) POSTs a page to the second Mattermost webhook for each target, open_incident_issue (io.kestra.plugin.github.issues.Create) files the labeled ticket, and sev1_email_gate (io.kestra.plugin.core.flow.If) sends email_oncall (io.kestra.plugin.email.MailSend) only when the severity is sev1. The other branch records the quiet outcome with log_no_page (io.kestra.plugin.core.log.Log).
  7. The errors handler pings Slack when the run itself breaks, because a bridge that dies silently looks exactly like a calm incident day.

What you get

  • verdict (STRING): PAGE_ESCALATED for an opened sev1 or sev2, ACKNOWLEDGED for an acknowledgement, RESOLVED_ARCHIVED for a resolution with its archive note, CHANNEL_NOTIFIED for an opened sev3 or sev4 and INVALID_PAYLOAD when the event carries no usable id, severity or status.
  • channel_posted (BOOL): true whenever a real severity-tagged incident message was built for the channel, false on an unrecognized event.
  • severity (STRING): the normalized severity of the event, or unknown when none was supplied.
  • open_incidents (INT): incidents in the tracked state that are opened or acknowledged after this event is applied, so a resolved sev1 visibly drops the count.
  • A severity-tagged Mattermost post on every event, a page and a GitHub ticket for opened sev1 and sev2 incidents, plus an email for sev1 pages.

Who it's for

  • On-call rotations that live in Mattermost and want every incident tool event to arrive as a tagged channel note with a page behind it.
  • Incident commanders who need the open incident count and the lifecycle transition visible next to the severity tag.
  • Platform teams that want sev1 and sev2 openings to create tickets and pages automatically while lower severities stay quiet.

Why orchestrate this with Kestra

A chat message alone does not page anyone, and a page without a ticket leaves no trail. Kestra supplies the keyed webhook, the disabled morning net, the python lifecycle step that turns raw events into verdicts, the HTTP posts to two Mattermost webhooks, the loop over the on-call targets and the branch that separates a sev1 page from a sev3 note. The verdict, the posted flag, the severity and the open count are typed outputs a dashboard or a downstream postmortem flow can branch on, and the errors handler keeps a broken bridge visible.

Prerequisites

  • A Kestra instance with the GitHub, email and Slack plugins available to the worker.
  • A Mattermost incoming webhook for the incident channel and a second one wired to the on-call page targets.
  • A GitHub repository for incident tickets, with a token allowed to open labeled issues.
  • An SMTP relay reachable from the worker for the sev1 mailbox escalation.
  • The incident tool pointed at the webhook URL with the INCIDENT_WEBHOOK_KEY segment.

Secrets

  • INCIDENT_WEBHOOK_KEY: key segment guarding the webhook URL, so only your incident tool can post status changes.
  • MATTERMOST_WEBHOOK_URL: Mattermost incoming webhook that receives the severity-tagged channel note.
  • MATTERMOST_PAGE_WEBHOOK_URL: second Mattermost incoming webhook used by the loop to page the on-call targets.
  • GITHUB_TOKEN: token open_incident_issue uses to file the labeled incident ticket.
  • SMTP_FROM, SMTP_HOST, SMTP_USERNAME, SMTP_PASSWORD: SMTP relay and credentials used by the sev1 mailbox escalation.
  • SLACK_WEBHOOK_URL: Slack incoming webhook used for failure alerts.

Quick start

  1. Add the seven secrets to your namespace and import the flow.
  2. Point the incident tool at /api/v1/{tenant}/executions/webhook/{namespace}/mattermost-incident-bridge/{INCIDENT_WEBHOOK_KEY} with a JSON body of incident_id, severity, status and summary.
  3. Fire a sev2 with status opened and confirm the severity-tagged note in channel, one page per target in page_targets and a labeled GitHub issue.
  4. Fire the same incident with status acknowledged, then resolved, and watch verdict and open_incidents move through the lifecycle while the pages stop.

How to extend

  • Replace the state file heredoc with a io.kestra.plugin.jdbc.postgresql.Queries task against your incident database and keep the same python verdict, so the open count reflects production data.
  • Widen the page gate by adding severities to PAGE_SEVERITIES in bridge_incident and to the list in escalation_gate, without touching the channel post.
  • Add a postmortem subflow that runs when verdict is RESOLVED_ARCHIVED and severity is sev1, so every critical incident gets a review ticket.
  • Switch on daily_state_reconcile for a morning reconciliation that catches events the webhook missed.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.