id: pagerduty-incident-auto-triage
namespace: company.sre
inputs:
- id: incident_title
type: STRING
required: true
defaults: "Database connection pool exhaustion on payment-gateway"
description: "Brief summary of the detected incident"
- id: service_name
type: STRING
required: true
defaults: "payment-gateway"
description: "Affected service name"
- id: severity
type: SELECT
required: true
values:
- CRITICAL
- HIGH
- WARNING
- INFO
defaults: CRITICAL
description: "Initial alert severity from monitoring provider"
- id: error_logs
type: STRING
required: true
defaults: "ERROR [HikariPool-1] - Connection timeout after 30000ms. Active pool
size: 50/50. Thread starvation detected."
description: "Raw error log or stack trace payload"
triggers:
- id: webhook_alert
type: io.kestra.plugin.core.trigger.Webhook
key: "sre-incident-triage-key"
tasks:
- id: automated_diagnostics
type: io.kestra.plugin.scripts.python.Script
description: "Analyzes error logs against standard SRE runbooks and produces
diagnostic recommendations"
containerImage: python:3.11-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install kestra
env:
ERROR_LOGS: "{{ inputs.error_logs }}"
ALERT_SEVERITY: "{{ inputs.severity }}"
SERVICE_NAME: "{{ inputs.service_name }}"
script: |
import os
import re
from kestra import Kestra
logs = os.environ.get("ERROR_LOGS", "")
severity = os.environ.get("ALERT_SEVERITY", "INFO")
service = os.environ.get("SERVICE_NAME", "unknown")
# SRE pattern heuristics
pool_exhaustion = bool(re.search(r"connection timeout|pool size|pool exhaustion|starvation", logs, re.IGNORECASE))
oom_killed = bool(re.search(r"out of memory|oomkilled|heap space", logs, re.IGNORECASE))
if pool_exhaustion:
diagnosis = "Downstream database saturation or unclosed connection leak detected."
recommended_action = "Scale read replicas and flush idle connections on primary DB."
should_escalate = True
elif oom_killed:
diagnosis = "JVM/Process memory limit exceeded."
recommended_action = "Restart pod with 2x heap memory allocation."
should_escalate = True
else:
diagnosis = "Unclassified transient error signature."
recommended_action = "Check recent deployment diffs."
should_escalate = severity in ["CRITICAL", "HIGH"]
# Emit variables to downstream Kestra tasks
Kestra.outputs({
"diagnosis": diagnosis,
"recommended_action": recommended_action,
"escalate": should_escalate,
"status": "ANALYZED"
})
- id: evaluate_severity_and_escalate
type: io.kestra.plugin.core.flow.If
description: "Flowable condition determining whether to page on-call engineers
or log for regular review"
condition: "{{ outputs.automated_diagnostics.vars.escalate == true or
inputs.severity == 'CRITICAL' }}"
then:
- id: trigger_pagerduty_incident
type: io.kestra.plugin.pagerduty.PagerDutyAlert
description: "Creates an incident on PagerDuty via Events API v2"
url: "https://events.pagerduty.com/v2/enqueue"
payload: |
{
"routing_key": "{{ secret('PAGERDUTY_ROUTING_KEY') }}",
"event_action": "trigger",
"dedup_key": "kestra-incident-{{ inputs.service_name }}-{{ execution.id }}",
"payload": {
"summary": "[{{ inputs.severity }}] {{ inputs.incident_title }}",
"source": "kestra-sre-engine",
"severity": "critical",
"component": "{{ inputs.service_name }}",
"custom_details": {
"execution_id": "{{ execution.id }}",
"diagnosis": "{{ outputs.automated_diagnostics.vars.diagnosis }}",
"action_plan": "{{ outputs.automated_diagnostics.vars.recommended_action }}",
"flow_link": "{{ flow.namespace }}/{{ flow.id }}"
}
}
}
- id: dispatch_slack_war_room
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Dispatches an escalation notification to SRE Slack channel"
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "🚨 *CRITICAL SRE ESCALATION TRIGGERED*\n*Service:* {{ inputs.service_name }}\n*Incident:* {{ inputs.incident_title }}\n*Diagnosis:* {{ outputs.automated_diagnostics.vars.diagnosis }}\n*Recommended Action:* {{ outputs.automated_diagnostics.vars.recommended_action }}\n*PagerDuty Incident Created:* Yes (Dedup: `kestra-incident-{{ inputs.service_name }}-{{ execution.id }}`)"
}
else:
- id: log_routine_notice
type: io.kestra.plugin.core.log.Log
description: "Logs routine warnings that do not require human wake-up pages"
message: "Alert for service '{{ inputs.service_name }}' processed. Severity: {{
inputs.severity }}. Diagnosis: {{
outputs.automated_diagnostics.vars.diagnosis }}. No on-call page
required."
- id: finalize_incident_audit_record
type: io.kestra.plugin.core.output.OutputValues
description: "Publishes final structured incident telemetry for audit trail and
post-mortem analysis"
values:
execution_id: "{{ execution.id }}"
service: "{{ inputs.service_name }}"
severity: "{{ inputs.severity }}"
diagnosis: "{{ outputs.automated_diagnostics.vars.diagnosis }}"
action_plan: "{{ outputs.automated_diagnostics.vars.recommended_action }}"
escalated: "{{ outputs.automated_diagnostics.vars.escalate }}"
status: "COMPLETED"
errors:
- id: on_pipeline_failure_fallback
type: io.kestra.plugin.pagerduty.PagerDutyAlert
description: "Emergency fallback: pages on-call if the triage pipeline itself
encounters an unexpected failure"
url: "https://events.pagerduty.com/v2/enqueue"
payload: |
{
"routing_key": "{{ secret('PAGERDUTY_ROUTING_KEY') }}",
"event_action": "trigger",
"payload": {
"summary": "EMERGENCY: Kestra SRE Auto-Triage Pipeline Failed",
"source": "kestra-pipeline-monitor",
"severity": "error",
"custom_details": {
"failed_execution_id": "{{ execution.id }}",
"failed_flow": "{{ flow.id }}"
}
}
}