> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flashduty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Grafana 集成

> 通过 Webhook 将 Grafana 告警事件同步到 Flashduty On-call。

通过 Webhook 将 Grafana 告警事件同步到 Flashduty On-call。

## 在 Flashduty On-call

您可通过以下两种方式获取集成推送地址，任选其一即可。

### 使用专属集成

如果您只需将告警发往一个协作空间，选择此方式，配置更简单。

> [accordion] 查看专属集成的配置步骤
>
> 1. 进入 Flashduty 控制台，选择 **协作空间**，打开一个协作空间
> 2. 选择 **配置** → **集成数据** → **专属集成**，点击 **新增集成**
> 3. 选择 **Grafana** 集成，点击 **保存**，生成卡片。
> 4. 打开生成的集成卡片，复制 **推送地址**

### 使用共享集成

如果您需要根据告警事件的 Payload 将告警路由到不同协作空间，选择此方式。

> [accordion] 查看共享集成的配置步骤
>
> 1. 进入 Flashduty 控制台，选择 **集成中心 → 告警事件**
> 2. 选择 **Grafana** 集成：
>    * **集成名称**：为当前集成定义一个名称。
> 3. 配置默认路由并选择协作空间；创建后可在 **路由** 中增加更多规则
> 4. 点击 **保存**，复制生成的 **推送地址**

## 在 Grafana 中配置

Grafana 4–8 默认使用 Legacy Alerting，9 及以后默认使用 Grafana Alerting，11 起已移除 Legacy Alerting。两者的区别和切换方式见 [Grafana 官方文档](https://grafana.com/docs/grafana/v8.4/alerting/unified-alerting/opt-in/#opt-in-to-grafana-alerting)。

**1. 在 Grafana 中添加 Webhook contact point**

> [tab] Grafana 12
>
> **操作路径**：Grafana › Alerts & IRM › Alerting › Notification configuration › Contact points › + New contact point
>
> | 字段 | 填写 |
> | - | - |
> | Name（必填） | 自定义名称，例如 `Flashduty` |
> | Integration（必填） | `Webhook` |
> | URL（必填） | `{integration_url}` |
> | HTTP Method（可选，位于 Optional settings） | `POST` |
>
> 填写后点击 **Save contact point**。

> [tab] Grafana 9–11
>
> **操作路径**：Grafana › Alerts & IRM › Alerting › Contact points › + Add contact point
>
> Grafana 9–10 的入口为左侧菜单的 **Alerting**（铃铛图标）› **Contact points**。
>
> | 字段 | 填写 |
> | - | - |
> | Name（必填） | 自定义名称，例如 `Flashduty` |
> | Integration（必填） | `Webhook` |
> | URL（必填） | `{integration_url}` |
> | HTTP Method（可选，位于 Optional Webhook settings） | `POST` |
>
> 填写后点击 **Save contact point**。
>
> ![Grafana 中 Webhook contact point 的配置](https://download.flashcat.cloud/grafana-contact-point.png)

> [tab] Legacy Alerting（4–8）
>
> **操作路径**：Grafana › Alerting（铃铛图标）› Notification channels › Add channel
>
> | 字段 | 填写 |
> | - | - |
> | Name（必填） | 自定义名称，例如 `Flashduty` |
> | Type（必填） | `webhook` |
> | Url（必填） | `{integration_url}` |
> | Http Method | `POST` |
> | Default (send on all alerts)（可选） | 勾选后所有告警规则都通过该 channel 发送 |
>
> 填写后点击 **Save**。
>
> ![Grafana Legacy Alerting 中 webhook channel 的配置](https://download.flashcat.cloud/grafana-legacy-alerting.png)

**2. 在 Grafana 中把告警发送到该 contact point**

> [tab] Grafana 9 及以上
>
> **操作路径**：Grafana › Alerts & IRM › Alerting › Notification policies › Default policy › … › Edit
>
> Grafana 12 的 **Notification policies** 位于 **Notification configuration** 下。
>
> * 所有告警发往 Flashduty：将 **Default contact point** 设为上一步创建的 contact point，点击 **Save**。
> * 只发送部分告警：点击 **+New child policy**，在 **Matching labels** 中填写匹配条件，**Contact point** 选择上一步创建的 contact point，点击 **Save policy**。
>
> Grafana 11 及以上也可以不改通知策略：编辑告警规则，在 **Configure notifications** 中直接选择该 contact point。
>
> ![Grafana 通知策略中选择 Flashduty contact point](https://download.flashcat.cloud/grafana-notification-policy.png)

> [tab] Legacy Alerting（4–8）
>
> **操作路径**：Grafana › 面板告警规则 › Alert › Notifications › Send to
>
> 如果上一步已勾选 **Default (send on all alerts)**，跳过此步。否则在每条面板告警规则的 **Send to** 中选择上一步创建的 channel，保存面板。

**3. 在 Grafana 中发送测试通知并确认**

**操作路径**：Grafana › Alerts & IRM › Alerting › Contact points › 该 contact point › Edit › Test

选择预置的测试通知，点击 **Send test notification**。Grafana 12 的 **Contact points** 位于 **Notification configuration** 下。Legacy Alerting 没有该测试入口，请等待真实告警触发。

几秒后回到 Flashduty，集成显示 **最新事件时间**，说明配置成功。

## 状态和告警等级

Legacy Alerting 到 Flashduty 告警等级映射关系：

| Legacy Alerting | Flashduty |
| - | - |
| alerting | Warning |
| no\_data | Critical |
| ok | Ok |

Grafana Alerting 到 Flashduty 告警等级映射关系：

系统依次提取告警事件标签中的 `severity`、`priority` 和 `level`，取到的值作为 Grafana 自身的告警等级。如果都没有取到，告警等级设为 `warning`。

如需自定义等级，编辑告警规则，在 **Labels** 中添加 `severity` 标签（Grafana 12 位于 **Set folder and labels** 下），取值见下表：

![在 Grafana 告警规则中添加 severity 标签](https://download.flashcat.cloud/grafana-alert-rule.png)

| Grafana Alerting | Flashduty |
| - | - |
| critical | Critical |
| warning | Warning |
| warn | Warning |
| info | Info |
| acknowledged | Info |
| unknown | Info |
| unk | Info |
| ok | Ok |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.