このテンプレートは、New Relicの集計に対してAutopilotを実行し、根本原因分析をSlackチャンネルに投稿します。Autopilotが使用可能な応答を返さない場合、代わりにワークフローがエラー通知を送信します。共通の前提条件と設定の注意事項については、Autopilot RCAワークフローテンプレートをご覧ください。
このワークフローを使用する前に、以下のことを確認してください:
- New Relicで設定されたSlackの宛先 — 宛先の作成を参照してください
- 宛先のUUIDとターゲットのSlackチャンネル名
このワークフローでは、次の手順を完了します:
- 集計を認識し、RCAが進行中であることをチームに知らせるための最初のSlackメッセージを送信します
- 集計の課題IDにスコープされた根本原因分析プロンプトを使用して、Autopilotを実行します
- Autopilot が使用可能なレスポンスを返したかどうかを確認します
- 応答をSlack Block Kitブロックとして再フォーマットし、検出結果をSlackに投稿します(Autopilotが応答を返す場合)
- (Autopilot が応答を返さない場合)課題IDを含むエラーメッセージを投稿します
このワークフローはnewrelic.autopilot.runとnewrelic.notification.sendSlackを使用します。
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: end使い方
runAutopilotステップでは、データ抽出レイヤーにおけるfinalAnswerのシェイプのばらつきに対応するために、2つのセレクターを使用します:
analysisRawは生のfinalAnswer値をキャプチャします。checkAgentResponseステップでは、これを使用してAutopilotが何かを返したかどうかを判断します。analysisTextは値を正規化します —finalAnswerがJSONエンコードされた文字列の場合、最初にそれを解析し、次に.card.bodyからテキストコンテンツを抽出します。buildSlackBlocksステップでは、追加の解析を行わずにanalysisTextを直接使用します。
buildSlackBlocks **bold** および ###/## の見出しマーカーを Slack mrkdwn 形式に変換し、結果を改行で分割して、空ではない各行を Block Kit の section ブロックでラップします。
関連トピック
Autopilot RCAワークフローテンプレート
すべてのAutopilot RCAテンプレートに共通の前提条件と設定に関する注意事項
Autopilotの概要
Autopilotがアラートとインシデントを調査する方法について学習します
コンディショナル・ロジック
switch文を使用して、成功または失敗に応じて分岐します。
Slack通知の送信
sendSlackアクションの完全なリファレンス
目的地を作成する
このワークフローで必要なSlackの送信先を設定します。
AutopilotとEmailを使用した集計RCA
Slackの代わりにメールでRCAの調査結果を送信します。
ワークフロー自動化のトラブルシューティング
一般的なAutopilotとSlackのインテグレーションに関する問題の解決策