ChatGPT销售客服AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

PagerDuty 联动 Port AI 的 n8n 事件全生命周期自动化

PagerDuty webhook 事件 → Port 软件目录上下文查询 → OpenAI 严重度评估 → Slack 分级通知与 Jira 工单 → 解决后 MTTR 计算与事后分析自动化

经验丰富步骤流程提示词
给谁
拥有 PagerDuty、Port、Jira、Slack 账户的 SRE 或平台工程师,使用自托管 n8n 实例
你会得到
事件触发时自动拉取服务上下文、评估严重度、创建工单并通知团队;事件解决后自动计算 MTTR、生成事后分析模板、调度复盘会议并回写可靠性指标
你需要
n8n · slack · jira · port

硬约束

前置条件:自托管 n8n 实例(模板明确标注仅支持 Self-Hosted);Port 账户及软件目录已配置服务、值班表、部署历史;PagerDuty 具备 webhook 能力;Jira Cloud 项目权限;Slack 工作区 bot 权限;OpenAI API key。所需凭证类型:portIoApi、openAiApi、slackApi、jiraSoftwareCloudApi。费用:各平台按各自定价计费,OpenAI 按 token 计费。

他们做了什么

Port.io 在 n8n 官方模板市场发布了一个事件全生命周期管理工作流模板(ID 11610)。该模板通过 PagerDuty webhook 接收事件,利用 n8n 的 Switch 节点按事件类型分流:触发事件进入 Port 上下文查询 → OpenAI 严重度评估 → 条件路由至 Slack 通知与 Jira 工单创建;解决事件进入 MTTR 计算 → OpenAI 事后分析模板生成 → Port AI Agent 调度复盘会议 → 指标回写。模板包含 21 个节点(含 4 个注释便签),使用 Port 自定义节点 7 个、OpenAI 节点 2 个、Slack 节点 4 个、Jira 节点 1 个、核心控制节点 3 个。

效果如何

作者(Port.io)声明该模板可实现:事件触发时自动拉取服务上下文、评估严重度、创建带调查清单的 Jira 工单、按严重度分级通知 Slack;事件解决后自动计算 MTTR、生成结构化事后分析模板、通过 Port AI Agent 安排复盘会议并创建文档、将 MTTR 指标回写至 Port 服务目录。上述效果为作者自述(author_report),本站未实测验证。

值得知道

1. 模板明确标注仅适用于 Self-Hosted n8n 实例,Cloud 用户可能受限。 2. Port 节点参数中 model='gpt-5' 为 Port 平台内部模型标识,非 OpenAI 公开发布的 GPT-5 产品;OpenAI 节点实际调用 gpt-4o-mini。 3. 需要 Port 自定义节点已安装于 n8n 实例,该节点非 n8n 内置节点。 4. 所有 Slack 消息模板中的频道名默认从 Port 上下文读取,若缺失则回退到 #incidents;领导层升级固定发送至 #leadership-alerts。 5. Jira 项目键默认 INC,可在 Parse Context 节点的 jira_project_key 字段自定义。 6. 事后分析会议安排依赖 Port AI Agent 的日历集成能力,需提前在 Port 中配置 Confluence/Notion 空间与日历集成。 7. 来源未提供各平台(Port、OpenAI、PagerDuty、Jira、Slack)的具体费用信息,实际运行将按各服务商定价计费。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • Extract Context (New Incident) 节点:绑定portIoApi 凭证。
  • Parse Context (New Incident) 节点:绑定portIoApi 凭证。
  • Assess Severity 节点:绑定OpenAI API 凭证。
  • Notify Team Channel 节点:绑定Slack API 凭证。
  • Escalate to Leadership 节点:绑定Slack API 凭证。
  • Create Jira Incident Ticket 节点:绑定jiraSoftwareCloudApi 凭证。
  • Notify Jira Created 节点:绑定Slack API 凭证。
  • Extract Context (Resolved) 节点:绑定portIoApi 凭证。
  • Parse Context (Resolved) 节点:绑定portIoApi 凭证。
  • Generate Post-Mortem Template 节点:绑定OpenAI API 凭证。
  • Schedule Post-Mortem via Port 节点:绑定portIoApi 凭证。
  • Parse Schedule Response 节点:绑定portIoApi 凭证。
  • Notify Incident Resolved 节点:绑定Slack API 凭证。
  • Log MTTR to Port 节点:绑定portIoApi 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #11610(约 21 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 配置 PagerDuty Webhook 与事件路由

    在 n8n 中创建 Webhook 节点,路径设为 pagerduty/incident,方法为 POST。在 PagerDuty 中配置 webhook 指向该 URL。添加 Switch 节点,按 body.event.event_type 路由:incident.triggered 走触发流,incident.resolved 走解决流。

  2. 查询 Port 软件目录获取事件上下文

    添加 Port 自定义节点(agentIdentifier: context_retriever_agent),输入事件 ID、标题、服务名、紧急程度和创建时间。节点向 Port 目录查询:服务层级、SLA、负责人、值班工程师、近 48 小时部署、依赖关系、Runbook 链接、监控面板、历史事件。输出为指定 JSON 格式,缺失字段留空。

    运行提示词 · 来源原文。Port 自定义节点 'Extract Context (New Incident)' 的 prompt 字段

    =A PagerDuty incident has been triggered.
    
    Incident Details:
    - ID: {{ $('On PagerDuty Incident').item.json.body.event.data.id }}
    - Title: {{ $('On PagerDuty Incident').item.json.body.event.data.title }}
    - Service: {{ $('On PagerDuty Incident').item.json.body.event.data.service.name }}
    - Urgency: {{ $('On PagerDuty Incident').item.json.body.event.data.urgency }}
    - Created At: {{ $('On PagerDuty Incident').item.json.body.event.data.created_at }}
    
    Query the Port catalog for comprehensive context about this incident.
    
    Retrieve:
    1. Affected service details (tier, criticality, SLA)
    2. Service owners and current on-call engineers
    3. Recent deployments (last 48 hours)
    4. Related pull requests or configuration changes
    5. Dependencies and upstream/downstream services
    6. Known vulnerabilities or ongoing issues
    7. Runbook URLs and monitoring dashboards
    8. Past similar incidents and resolution patterns
    9. Team's Slack channel
    
    Output as JSON:
    {
      "service_name": "",
      "service_tier": "tier1|tier2|tier3",
      "sla_minutes": 0,
      "owners": [],
      "on_call_engineers": [],
      "slack_channel": "",
      "recent_deployments": [],
      "recent_changes": [],
      "dependencies": [],
      "runbook_url": "",
      "dashboard_url": "",
      "past_incidents_summary": "",
      "known_issues": [],
      "jira_project_key": ""
    }
    
    Rules:
    - Only include data that exists in Port
    - Use empty strings/arrays if not found
  3. OpenAI 评估严重度与升级建议

    添加 OpenAI 节点(model: gpt-4o-mini),将 Port 上下文与事件标题、服务名、紧急程度一并送入。模型返回 JSON:严重度等级(critical/high/medium/low)、是否升级、升级原因、可能根因、推荐行动、调查清单。

    运行提示词 · 来源原文。OpenAI 节点 'Assess Severity' 的 chat messages[0].content 字段

    =You are an incident management expert. Assess this incident and determine if immediate escalation is needed.
    
    Incident:
    - Title: {{ $('On PagerDuty Incident').item.json.body.event.data.title }}
    - Service: {{ $('On PagerDuty Incident').item.json.body.event.data.service.name }}
    - Urgency: {{ $('On PagerDuty Incident').item.json.body.event.data.urgency }}
    
    Context from Port:
    {{ $json.result.message }}
    
    Consider:
    1. Is this a production service?
    2. Were there recent deployments that could be related?
    3. Are there known issues affecting this service?
    4. What is the SLA requirement?
    
    Provide your response as JSON:
    {
      "severity_assessment": "critical|high|medium|low",
      "needs_escalation": true or false,
      "escalation_reason": "reason if needs_escalation is true",
      "likely_cause": "brief assessment of likely cause",
      "recommended_actions": ["action 1", "action 2", "action 3"],
      "investigation_checklist": ["check 1", "check 2", "check 3"]
    }
    
    Return ONLY the JSON object.
  4. Slack 分级通知团队与领导层

    添加 If 节点判断 needs_escalation。无论是否升级,均向团队 Slack 频道发送事件详情、严重度、值班人、可能根因、推荐行动、近期变更及资源链接;若需升级,额外向 #leadership-alerts 发送升级通知。频道名从 Port 上下文读取,缺失则默认 #incidents。

    运行提示词 · 来源原文。Slack 节点 'Notify Team Channel' 的 text 字段

    =:rotating_light: *INCIDENT ALERT*
    
    *{{ $('On PagerDuty Incident').item.json.body.event.data.title }}*
    
    *Service:* {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().service_name }} ({{ $('Parse Context (New Incident)').item.json.result.message.parseJson().service_tier }})
    *Urgency:* {{ $('On PagerDuty Incident').item.json.body.event.data.urgency }}
    *Severity Assessment:* {{ $('Assess Severity').item.json.message.content.parseJson().severity_assessment }}
    
    *On-Call:* {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().on_call_engineers.join(', ') || 'Check PagerDuty' }}
    
    *Likely Cause:*
    {{ $('Assess Severity').item.json.message.content.parseJson().likely_cause }}
    
    *Recommended Actions:*
    {{ $('Assess Severity').item.json.message.content.parseJson().recommended_actions.map((a, i) => (i+1) + '. ' + a).join('\n') }}
    
    *Recent Changes:*
    {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().recent_deployments.slice(0,3).map(d => '- ' + d).join('\n') || 'None in last 48h' }}
    
    *Resources:*
    {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().runbook_url ? '<' + $('Parse Context (New Incident)').item.json.result.message.parseJson().runbook_url + '|Runbook>' : '' }} {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().dashboard_url ? '| <' + $('Parse Context (New Incident)').item.json.result.message.parseJson().dashboard_url + '|Dashboard>' : '' }}
    
    :pagerduty: <{{ $('On PagerDuty Incident').item.json.body.event.data.html_url }}|View in PagerDuty>

    运行提示词 · 来源原文。Slack 节点 'Escalate to Leadership' 的 text 字段

    =:rotating_light::rotating_light: *INCIDENT ESCALATION*
    
    *{{ $('On PagerDuty Incident').item.json.body.event.data.title }}*
    
    *Service:* {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().service_name }} ({{ $('Parse Context (New Incident)').item.json.result.message.parseJson().service_tier }})
    *Escalation Reason:* {{ $('Assess Severity').item.json.message.content.parseJson().escalation_reason }}
    
    *Team Channel:* {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().slack_channel || '#incidents' }}
    *On-Call:* {{ $('Parse Context (New Incident)').item.json.result.message.parseJson().on_call_engineers.join(', ') || 'Check PagerDuty' }}
    
    :pagerduty: <{{ $('On PagerDuty Incident').item.json.body.event.data.html_url }}|View in PagerDuty>
    
    _Response team has been notified._
  5. 创建 Jira 事件工单并通知

    添加 Jira 节点,项目键从 Port 上下文读取(默认 INC),工单类型 Bug,优先级按严重度映射(critical→Highest, high→High, 其他→Medium)。描述包含完整事件详情、服务上下文、AI 评估、调查清单、推荐行动、近期变更、资源链接及历史事件摘要。工单创建后向团队频道发送确认消息。

    运行提示词 · 来源原文。Slack 节点 'Notify Jira Created' 的 text 字段

    =:jira: *Incident Ticket Created*
    
    {{ $json.key }}
    
    Track investigation and resolution in Jira.
  6. 解决后提取上下文并生成事后分析模板

    事件解决后,Port 节点(agentIdentifier: context_retriever_agent)查询服务详情、负责人、Slack 频道、事件窗口内变更、Confluence/Notion 空间、日历集成信息,并计算 incident_duration_minutes。随后 OpenAI 节点(gpt-4o-mini)基于上下文生成结构化事后分析 JSON 模板,含时间线、影响、根因分析占位、行动项、经验教训。

    运行提示词 · 来源原文。Port 节点 'Extract Context (Resolved)' 的 prompt 字段

    =A PagerDuty incident has been resolved.
    
    Incident Details:
    - ID: {{ $('On PagerDuty Incident').item.json.body.event.data.id }}
    - Title: {{ $('On PagerDuty Incident').item.json.body.event.data.title }}
    - Service: {{ $('On PagerDuty Incident').item.json.body.event.data.service.name }}
    - Created At: {{ $('On PagerDuty Incident').item.json.body.event.data.created_at }}
    - Resolved At: {{ $('On PagerDuty Incident').item.json.body.event.data.resolved_at || new Date().toISOString() }}
    
    Query the Port catalog for post-incident context.
    
    Retrieve:
    1. Service details and owners
    2. Team's Slack channel
    3. Changes made during the incident window
    4. Confluence/Notion space for post-mortems
    5. Calendar integration details for scheduling
    
    Calculate incident_duration_minutes from created_at to resolved_at.
    
    Output as JSON:
    {
      "service_name": "",
      "owners": [],
      "slack_channel": "",
      "confluence_space": "",
      "calendar_id": "",
      "incident_duration_minutes": 0,
      "changes_during_incident": [],
      "stakeholders_to_invite": []
    }
    
    Only include data that exists in Port.

    运行提示词 · 来源原文。OpenAI 节点 'Generate Post-Mortem Template' 的 chat messages[0].content 字段

    =Create a post-mortem document template for this resolved incident.
    
    Incident:
    - ID: {{ $('On PagerDuty Incident').item.json.body.event.data.id }}
    - Title: {{ $('On PagerDuty Incident').item.json.body.event.data.title }}
    - Service: {{ $json.result.message.parseJson().service_name }}
    - Duration: {{ $json.result.message.parseJson().incident_duration_minutes }} minutes
    - Created: {{ $('On PagerDuty Incident').item.json.body.event.data.created_at }}
    - Resolved: {{ $('On PagerDuty Incident').item.json.body.event.data.resolved_at }}
    
    Context:
    {{ $json.result.message }}
    
    Create a structured post-mortem template as JSON:
    {
      "title": "Post-Mortem: [incident title]",
      "summary": "Brief 2-3 sentence summary",
      "timeline": [
        {"time": "HH:MM", "event": "Incident detected"},
        {"time": "HH:MM", "event": "Response initiated"},
        {"time": "HH:MM", "event": "Root cause identified"},
        {"time": "HH:MM", "event": "Resolution applied"},
        {"time": "HH:MM", "event": "Incident resolved"}
      ],
      "impact": "Description of customer/business impact",
      "root_cause_analysis": "[To be filled during post-mortem meeting]",
      "action_items": [
        {"action": "Suggested action 1", "owner": "TBD", "due_date": "TBD"},
        {"action": "Suggested action 2", "owner": "TBD", "due_date": "TBD"}
      ],
      "lessons_learned": "[To be filled during post-mortem meeting]",
      "meeting_attendees": []
    }
    
    Return ONLY the JSON object.
  7. Port AI Agent 调度复盘会议并通知团队

    添加 Port 节点(agentIdentifier: post_mortem_scheduler_agent),输入事件详情、持续时间、已解决时间、利益相关者列表及事后分析模板内容。Agent 任务:创建事后分析文档、安排 2-3 个工作日内会议、邀请相关人员、在会议邀请中附加文档链接。返回 JSON 含文档创建状态、会议时间、受邀人列表。解析响应后向团队频道发送解决通知,包含 MTTR、文档链接和会议详情。

    运行提示词 · 来源原文。Port 节点 'Schedule Post-Mortem via Port' 的 prompt 字段

    =An incident has been resolved and needs a post-mortem meeting scheduled.
    
    Incident Details:
    - ID: {{ $('On PagerDuty Incident').item.json.body.event.data.id }}
    - Title: {{ $('On PagerDuty Incident').item.json.body.event.data.title }}
    - Service: {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().service_name }}
    - Duration: {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().incident_duration_minutes }} minutes
    - Resolved At: {{ $('On PagerDuty Incident').item.json.body.event.data.resolved_at }}
    
    Stakeholders to invite:
    {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().stakeholders_to_invite.join(', ') || $('Parse Context (Resolved)').item.json.result.message.parseJson().owners.join(', ') }}
    
    Post-Mortem Template:
    {{ $('Generate Post-Mortem Template').item.json.message.content }}
    
    Your tasks:
    1. Create a post-mortem document (in Confluence/Notion if available) with the template content
    2. Schedule a post-mortem meeting for 2-3 business days from now
    3. Invite relevant stakeholders (service owners, on-call engineers who responded)
    4. Include the incident details and post-mortem document link in the meeting invite
    
    Respond with JSON:
    {
      "document_created": true or false,
      "document_url": "URL if created",
      "meeting_scheduled": true or false,
      "meeting_time": "ISO timestamp",
      "attendees_invited": [],
      "status": "success|partial|failed",
      "message": "Summary of actions taken"
    }

    运行提示词 · 来源原文。Slack 节点 'Notify Incident Resolved' 的 text 字段

    =:white_check_mark: *INCIDENT RESOLVED*
    
    *{{ $('On PagerDuty Incident').item.json.body.event.data.title }}*
    
    *Service:* {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().service_name }}
    *Duration:* {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().incident_duration_minutes }} minutes
    *MTTR:* {{ Math.floor($('Parse Context (Resolved)').item.json.result.message.parseJson().incident_duration_minutes / 60) }}h {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().incident_duration_minutes % 60 }}m
    
    *Post-Mortem:*
    {{ $json.result.message.parseJson().document_url ? '<' + $json.result.message.parseJson().document_url + '|View Document>' : 'Document creation pending' }}
    
    *Post-Mortem Meeting:*
    {{ $json.result.message.parseJson().meeting_scheduled ? 'Scheduled for ' + $json.result.message.parseJson().meeting_time : 'Scheduling in progress' }}
    {{ $json.result.message.parseJson().attendees_invited.length > 0 ? 'Attendees: ' + $json.result.message.parseJson().attendees_invited.join(', ') : '' }}
    
    {{ $json.result.message.parseJson().message }}
    
    :pagerduty: <{{ $('On PagerDuty Incident').item.json.body.event.data.html_url }}|View in PagerDuty>
  8. 回写 MTTR 指标到 Port

    添加 Port 节点(agentIdentifier: metrics_logger_agent),输入事件 ID、服务名、MTTR(分钟)、解决时间。任务:更新 Port 中服务实体的最新 MTTR、递增事件计数、更新最后事件时间戳。返回 JSON 确认指标是否已记录。

    运行提示词 · 来源原文。Port 节点 'Log MTTR to Port' 的 prompt 字段

    =Log the incident resolution metrics to Port.
    
    Incident:
    - ID: {{ $('On PagerDuty Incident').item.json.body.event.data.id }}
    - Service: {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().service_name }}
    - MTTR: {{ $('Parse Context (Resolved)').item.json.result.message.parseJson().incident_duration_minutes }} minutes
    - Resolved At: {{ $('On PagerDuty Incident').item.json.body.event.data.resolved_at }}
    
    Update the service entity in Port with:
    1. Latest incident MTTR
    2. Increment incident count
    3. Update last incident timestamp
    
    Respond with JSON:
    {
      "metrics_logged": true or false,
      "service_updated": "",
      "message": ""
    }

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限

这一段是提示词,页面不会在这里插入广告。

你正在搭建一个 n8n 工作流,用于自动化事件全生命周期管理。请先确认以下前提:
1. 你使用的是自托管 n8n 实例(模板标注不支持 Cloud)。
2. 已在 Port.io 注册并完成服务目录、值班表、部署历史的配置。
3. 已在 n8n 中安装 Port 自定义节点,并配置好 portIoApi、openAiApi、slackApi、jiraSoftwareCloudApi 四类凭证。
4. PagerDuty webhook 可访问你的 n8n 实例公网地址。
5. Slack 频道 #incidents 与 #leadership-alerts 已创建,Jira 项目键为 INC(或可自定义)。

确认后,按步骤导入 workflow.json 或按节点描述手动搭建,重点检查:
- Webhook 路径与 PagerDuty 配置一致;
- Switch 节点规则匹配 incident.triggered / incident.resolved;
- Port 节点的 agentIdentifier 与你在 Port 中配置的 AI Agent 名称一致;
- OpenAI 节点模型选择与你账户可用模型一致(模板使用 gpt-4o-mini)。

首次运行前,用 PagerDuty 的测试事件验证触发流,确认 Slack 能收到消息、Jira 能创建工单后,再测试解决流。

搭建前务必确认自托管环境;Port 自定义节点需单独安装;所有凭证需在 n8n 中提前配置并测试连通性。

来源

Automate Incident Management with PagerDuty, Port AI, Jira & Slack · portio · n8n.io · 2025-12-08

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例