When an alert fires, trigger Autopilot to run a root cause analysis and post the findings directly to a Slack channel. If Autopilot returns no usable response, the workflow sends an error notice instead so the team knows to investigate manually.
Antes de usar este flujo de trabajo, asegúrese de tener:
- Un ID de problema de alerta de New Relic en formato UUID
- Un destino de Slack configurado en New Relic — consulte Crear destinos
- El UUID del destino y el nombre del canal de Slack objetivo
Sugerencia
When triggering this workflow from Alert Workflows, use {{ issueId }} as the value for the issueId input. This variable automatically passes the triggering alert's issue ID to the workflow.
Este flujo de trabajo completa los siguientes pasos:
- Envía un mensaje inicial de Slack para confirmar la alerta y avisar al equipo que el RCA está en marcha
- Runs Autopilot with a root cause analysis prompt scoped to the alert issue ID
- Checks whether Autopilot returned a usable response
- If Autopilot succeeds, reformats the response as Slack Block Kit blocks and posts findings to Slack
- If Autopilot fails, posts an error message with the issue ID
This workflow uses newrelic.autopilot.run and newrelic.notification.sendSlack.
Importante
Selector expression values must be written on a single line. Multi-line YAML block scalars (| or |-) aren't evaluated for selector expressions and silently produce no output.
Sugerencia
Autopilot's finalAnswer field can return as either a plain string or a JSON-encoded object depending on prompt context. The analysisText selector in this workflow handles both shapes automatically.
name: autopilotSlackRCAdescription: Automatically analyze New Relic alerts with Autopilot and send cleanly formatted findings to SlackworkflowInputs: issueId: type: String required: true validations: - errorMessage: Must be a valid New Relic issue ID in UUID format pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$' type: regex slackDestinationId: type: String required: true validations: - pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ errorMessage: "Invalid format. Please provide a valid UUID." type: regex channel: type: String required: truesteps: - name: notifyAlertReceived type: action action: newrelic.notification.sendSlack version: 1 inputs: destinationId: ${{ .workflowInputs.slackDestinationId }} channel: ${{ .workflowInputs.channel }} text: |- 🔔 *Alert Received — Starting Root Cause Analysis*
⏳ Running Autopilot for RCA, please wait...
- name: runAutopilot type: action action: newrelic.autopilot.run version: 1 inputs: prompt: >- Perform a root cause analysis for the following New Relic alert: Issue ID: ${{ .workflowInputs.issueId }} Provide your comprehensive analysis including Summary, Root Cause, and Remediation Actions. selectors: - name: analysisRaw expression: .response.finalAnswer - name: analysisText expression: '(.response.finalAnswer | if type=="string" then fromjson else . end).card.body | map(.value) | join("\n\n")' ignoreErrors: true
- name: checkAgentResponse type: switch switch: - condition: ${{ (.steps.runAutopilot.outputs.analysisRaw // "") != "" }} next: buildSlackBlocks next: sendAutopilotError
- name: buildSlackBlocks type: assign inputs: blocks: '${{ (.steps.runAutopilot.outputs.analysisText // "") | gsub("\\*\\*"; "*") | gsub("### "; "*") | gsub("## "; "*") as $text | ([ $text / "\n" ]) as $lines | [ { "type": "header", "text": { "type": "plain_text", "text": "✅ Autopilot RCA Complete" } }, { "type": "divider" } ] + [ $lines[][] | select(. != "") | { "type": "section", "text": { "type": "mrkdwn", "text": . } } ] }}' next: sendRcaFindings
- name: sendRcaFindings type: action action: newrelic.notification.sendSlack version: 1 inputs: destinationId: ${{ .workflowInputs.slackDestinationId }} channel: ${{ .workflowInputs.channel }} blocks: ${{ .steps.buildSlackBlocks.outputs.blocks }} next: end
- name: sendAutopilotError type: action action: newrelic.notification.sendSlack version: 1 inputs: destinationId: ${{ .workflowInputs.slackDestinationId }} channel: ${{ .workflowInputs.channel }} text: |- 🟥 *Autopilot RCA Failed*
Could not extract findings from Autopilot response for issue: ${{ .workflowInputs.issueId }} Please investigate manually. next: endCómo funciona
The runAutopilot step uses two selectors to handle finalAnswer shape variability at the data-extraction layer:
analysisRawcaptures the rawfinalAnswervalue. ThecheckAgentResponsestep uses this to determine whether Autopilot returned anything.analysisTextnormalizes the value — iffinalAnsweris a JSON-encoded string, it parses it first, then extracts text content from.card.body. ThebuildSlackBlocksstep usesanalysisTextdirectly, which keeps the formatting logic simple.
buildSlackBlocks converts **bold** and ###/## heading markers to Slack mrkdwn format, splits the result on newlines, and wraps each non-empty line in a Block Kit section block.
Temas relacionados
Descripción general de Autopilot
Aprenda cómo Autopilot investiga alertas e incidentes
Lógica condicional
Usar declaraciones de cambio para ramificar en caso de éxito o fracaso
Enviar notificaciones de Slack
Referencia completa para la acción sendSlack
Crear destinos
Configure el destino de Slack requerido por este flujo de trabajo
Solucionar problemas de automatización de flujo de trabajo
Solutions for common Autopilot and Slack integration issues