|
| 1 | +--- |
| 2 | +title: "New Relic 告警集成" |
| 3 | +description: "通过 Workflow Webhook 将 New Relic Issue 同步到 Flashduty On-call,并关联激活、更新和关闭事件。" |
| 4 | +keywords: ["告警集成", "New Relic", "Workflow", "Webhook", "Issue"] |
| 5 | +--- |
| 6 | + |
| 7 | +通过 New Relic Workflow Webhook 将 Issue 同步到 Flashduty On-call。一个 New Relic Issue 对应一条 Flashduty 告警;同一 Issue 后续发生等级变化、Alert Event 加入或关闭、Issue 合并、关闭时,会继续更新这条告警。 |
| 8 | + |
| 9 | +<div className="hide"> |
| 10 | + |
| 11 | +## 在 Flashduty On-call |
| 12 | +--- |
| 13 | +您可通过以下两种方式获取集成推送地址,任选其一即可。 |
| 14 | + |
| 15 | +### 使用专属集成 |
| 16 | + |
| 17 | +1. 进入 Flashduty 控制台,选择 **协作空间**,打开一个协作空间 |
| 18 | +2. 选择 **集成数据**,点击 **添加一个集成** |
| 19 | +3. 选择 **New Relic**,点击 **保存** |
| 20 | +4. 打开生成的集成卡片,复制 **推送地址** |
| 21 | + |
| 22 | +### 使用共享集成 |
| 23 | + |
| 24 | +1. 进入 Flashduty 控制台,选择 **集成中心 → 告警事件** |
| 25 | +2. 选择 **New Relic**,填写集成名称 |
| 26 | +3. 配置默认路由并选择协作空间;创建后可在 **路由** 中增加更多规则 |
| 27 | +4. 点击 **保存**,复制生成的 **推送地址** |
| 28 | + |
| 29 | +</div> |
| 30 | + |
| 31 | +## 在 New Relic 中配置 |
| 32 | +--- |
| 33 | + |
| 34 | +<Steps> |
| 35 | +<Step title="创建 Webhook Destination"> |
| 36 | + |
| 37 | +1. 登录 New Relic,进入 **Alerts → Enrich and Notify → Destinations** |
| 38 | +2. 创建一个 **Webhook** Destination |
| 39 | +3. 名称可填写 `Flashduty` |
| 40 | +4. 将 Flashduty 集成的完整推送地址粘贴到 Endpoint URL |
| 41 | + |
| 42 | +</Step> |
| 43 | + |
| 44 | +<Step title="创建 Workflow"> |
| 45 | + |
| 46 | +1. 进入 **Alerts → Enrich and Notify → Workflows**,点击创建 Workflow |
| 47 | +2. 设置 Issue 过滤条件,选择需要发送到 Flashduty 的 Policy、Condition、实体或标签 |
| 48 | +3. 添加刚创建的 Webhook Destination |
| 49 | +4. 在通知触发器中至少启用 **Activated** 和 **Closed** |
| 50 | +5. 建议同时启用 **Priority changed** 和 **Other updates**,以同步等级变化、Alert Event 增减及 Issue 合并后的最新快照 |
| 51 | + |
| 52 | +</Step> |
| 53 | + |
| 54 | +<Step title="配置 Payload"> |
| 55 | + |
| 56 | +将 Webhook 的自定义 Payload 替换为: |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "issue_id": "{{issueId}}", |
| 61 | + "issue_url": {{json issuePageUrl}}, |
| 62 | + "title": {{json issueTitle}}, |
| 63 | + "description": {{json accumulations.conditionDescription.[0]}}, |
| 64 | + "priority": "{{priority}}", |
| 65 | + "state": "{{state}}", |
| 66 | + "trigger_event": "{{triggerEvent}}", |
| 67 | + "is_correlated": {{isCorrelated}}, |
| 68 | + "account_id": {{nrAccountId}}, |
| 69 | + "incident_ids": {{json incidentIds}}, |
| 70 | + "sources": {{json accumulations.sources}}, |
| 71 | + "policy_names": {{json accumulations.policyName}}, |
| 72 | + "condition_names": {{json accumulations.conditionName}}, |
| 73 | + "entity_names": {{json entitiesData.names}}, |
| 74 | + "entity_ids": {{json entitiesData.ids}}, |
| 75 | + "workflow_name": {{json workflowName}} |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +<Warning> |
| 80 | +请保留 `issue_id`、`state` 和 `priority`。缺少 `issue_id` 时 Flashduty 会拒绝请求,因为随机 Key 无法保证后续更新和关闭命中同一条告警。 |
| 81 | +</Warning> |
| 82 | + |
| 83 | +</Step> |
| 84 | + |
| 85 | +<Step title="验证生命周期"> |
| 86 | + |
| 87 | +让 Alert Condition 进入阈值,确认 Flashduty 收到活动告警;提高优先级或产生新的 Alert Event,确认同一条告警收到更新;最后让 Issue 关闭,确认原告警恢复。 |
| 88 | + |
| 89 | +New Relic 的测试通知只能验证 Webhook 可达。Alert Key、更新和恢复必须通过真实 Issue 生命周期验证。 |
| 90 | + |
| 91 | +</Step> |
| 92 | +</Steps> |
| 93 | + |
| 94 | +## Alert Key 与 Issue 合并 |
| 95 | +--- |
| 96 | + |
| 97 | +Flashduty 直接使用 `issue_id`(New Relic 变量 `issueId`)作为 Alert Key。标题、优先级、Policy、Condition、实体和 `incident_ids` 的变化都不会改变 Alert Key。 |
| 98 | + |
| 99 | +`incident_ids` 是当前 Issue 聚合的 Alert Event ID 列表,只作为详情标签。它不能作为 Alert Key,否则一个 Alert Event 加入、关闭或相关性计算变化时会拆出新告警。 |
| 100 | + |
| 101 | +当 `trigger_event=MERGE_REQUEST` 时,Flashduty 将请求视为合并后目标 Issue 的一次普通更新,并继续使用 Payload 中的 `issue_id`。当前版本不调用 Flashduty 内部的告警合并能力,也不会推断或关闭来源 Issue。 |
| 102 | + |
| 103 | +## 状态和告警等级 |
| 104 | +--- |
| 105 | + |
| 106 | +恢复只根据 `state` 判断,与 `trigger_event` 和等级映射相互独立。 |
| 107 | + |
| 108 | +| New Relic 值 | Flashduty 状态或等级 | |
| 109 | +| :--- | :--- | |
| 110 | +| `state = CLOSED` | 恢复 | |
| 111 | +| `state = CREATED`、`ACTIVATED` | 活动告警 | |
| 112 | +| `priority = CRITICAL` | Critical | |
| 113 | +| `priority = HIGH` | Warning | |
| 114 | +| `priority = MEDIUM`、`LOW` | Info | |
| 115 | +| `priority` 为空或未知 | Warning | |
| 116 | + |
| 117 | +New Relic 的 Warning 阈值会生成 `HIGH` 优先级 Alert Event,因此 `HIGH` 映射为 Flashduty Warning。如需其他映射,可通过[告警处理 Pipeline](/zh/on-call/integration/alert-integration/alert-pipelines)调整。 |
| 118 | + |
| 119 | +## 增加自定义标签 |
| 120 | +--- |
| 121 | + |
| 122 | +如果需要传递更多 Workflow 变量,在默认 Payload 顶层增加 `custom_labels`: |
| 123 | + |
| 124 | +```json |
| 125 | +{ |
| 126 | + "issue_id": "{{issueId}}", |
| 127 | + "title": {{json issueTitle}}, |
| 128 | + "priority": "{{priority}}", |
| 129 | + "state": "{{state}}", |
| 130 | + "custom_labels": { |
| 131 | + "team": {{json accumulations.tag.team.[0]}}, |
| 132 | + "environment": {{json accumulations.tag.environment.[0]}}, |
| 133 | + "muting_state": "{{mutingState}}", |
| 134 | + "open_alert_events": {{openIncidentsCount}} |
| 135 | + } |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +- `custom_labels` 最多包含 50 个条目,key 建议使用 snake_case |
| 140 | +- 字符串、数字、布尔值、数组和对象都可接收;数组和对象会保存为 JSON 字符串 |
| 141 | +- 空值不会生成标签;基础字段优先,同名自定义标签不能覆盖基础标签 |
| 142 | +- 单次请求包含基础标签在内,最多生成 50 个标签 |
| 143 | +- 不要传递 API Key、Token、密码、Cookie 或其他敏感信息 |
| 144 | + |
| 145 | +## 排查问题 |
| 146 | +--- |
| 147 | + |
| 148 | +- **只收到测试通知,真实告警没有通知**:确认 Workflow 已启用,并且过滤条件能够命中真实 Issue |
| 149 | +- **Flashduty 返回参数错误**:确认 Payload 是有效 JSON,且包含非空的 `issue_id` 和支持的 `state` |
| 150 | +- **告警没有恢复**:确认 Destination 启用了 **Closed**,关闭 Payload 仍携带与激活时相同的 `issue_id` |
| 151 | +- **等级或合并变化没有更新**:启用 **Priority changed** 和 **Other updates** |
| 152 | +- **部分列表为空**:不同 Condition 和 Issue 类型提供的上下文不同,Flashduty 会忽略空标签 |
| 153 | + |
| 154 | +字段含义和可用变量请参阅 [New Relic Workflow variables](https://docs.newrelic.com/docs/alerts/get-notified/custom-variables-alert-event-workflows/)。 |
0 commit comments