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

# Sentry 告警事件

> 通过 webhook 的方式同步 Sentry 告警事件到 Flashduty On-call，实现告警事件自动化降噪处理

<div className="hide">
  ## 在 Flashduty On-call

  ***

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

  ### 使用专属集成

  当您不需要将告警事件路由到不同的协作空间，优先选择此方式，更简单。

  <AccordionGroup>
    <Accordion title="展开">
      1. 进入 Flashduty 控制台，选择 **协作空间**，进入某个空间的详情页面
      2. 选择 **集成数据** tab，点击 **添加一个集成**，进入添加集成页面
      3. 选择 **Sentry** 集成，点击 **保存**，生成卡片。
      4. 点击生成的卡片，可以查看到 **推送地址**，复制备用，完成。
    </Accordion>
  </AccordionGroup>

  ### 使用共享集成

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

  <AccordionGroup>
    <Accordion title="展开">
      1. 进入 Flashduty 控制台，选择 **集成中心=>告警事件**，进入集成选择页面。
      2. 选择 **Sentry** 集成：
         * **集成名称**：为当前集成定义一个名称。
      3. 配置默认路由，并选择对应的协作空间（集成创建后可以前往 `路由` 进行更多路由规则的配置）。
      4. 点击 **保存** 后，复制当前页面的新生成的 **推送地址** 备用。
      5. 完成。
    </Accordion>
  </AccordionGroup>
</div>

## 在 Sentry

***

<div className="md-block">
  ## 一、前置说明

  Sentry 提供了两类告警机制：Issue Alerts 和 Metric Alerts。Issue Alerts 支持通过 Integrations 中的 WebHooks 实现通知功能，而 Metric Alerts 则限定于使用 Internal Integration 进行告警通知。值得注意的是 Internal Integration 不仅适用于 Metric Alerts，也兼容 Issue Alerts。鉴于 Internal Integration 的广泛适用性，我们决定统一采用这一方式，不再单独依赖 WebHooks，以此来简化告警通知的配置。

  ## 二、Sentry 告警推送配置

  ### 步骤1：添加 Flashduty Custom Integrations

  1. 登录 Sentry 管理控制台。
  2. 在左侧导航栏，找到 **Settings => Custom Integrations**。
  3. 点击 Create New Integration 并选择 **Internal Integration**。
  4. 在编辑页面。**Name 处填写 Flashduty，WebhookURL 处复制写入集成的推送地址**。
  5. 开启 **Alert Rule Action**，参考如下图配置：

  <img alt="drawing" width="600" src="https://fcpub-1301667576.cos.ap-nanjing.myqcloud.com/flashduty/doc/sentry-1.png" />

  5. 在 PERMISSIONS 配置中为 **Issue & Event 配置 Read 权限** 。
  6. 在 WEBHOOKS 配置中，勾选 **issue** ，**请不要勾选 error 和 comment**。
  7. 配置完成后，点击 Save Changes 完成创建。

  <img alt="drawing" width="600" src="https://fcpub-1301667576.cos.ap-nanjing.myqcloud.com/flashduty/doc/sentry-2.png" />

  **关于 WEBHOOKS 配置的特殊说明：**

  1. 勾选 **issue** 后 Flashduty On-call 可以接收 issue 的 resolved 事件，即在 issue 列表中对某个问题进行手动触发 resolved 时，我们会自动恢复 Flashduty On-call 中关联的故障。
  2. 不支持 issue 的其他事件，如 create、assigned、archived 和 unresolved。
  3. 如果同时勾选了 error 和 comment ，Flashduty 并不会接收和处理这类事件。

  ### 步骤2：在 Alerts 中使用 Flashduty Integration

  1. 在左侧导航栏，找到 **Alerts => Create Alert**。
  2. 选择要创建的 Alert 类型，如 Issue 。

  <img alt="drawing" width="600" src="https://fcpub-1301667576.cos.ap-nanjing.myqcloud.com/flashduty/doc/sentry-3.png" />

  3. 触发条件请按需配置。

  4. 在 **THEN perform these actions 处 Add action** 并选择 **Send a notification via**。

  <img alt="drawing" width="600" src="https://fcpub-1301667576.cos.ap-nanjing.myqcloud.com/flashduty/doc/sentry-4.png" />

  5. 通知渠道选择上面添加的 **Flashduty**。

  <img alt="drawing" width="600" src="https://fcpub-1301667576.cos.ap-nanjing.myqcloud.com/flashduty/doc/sentry-5.png" />

  6. 配置好其他选项后，点击 **Save Rule** 保存即可。
</div>

## 三、状态对照

<div className="md-block">
  | Sentry    | Flashduty | 状态 |
  | --------- | --------- | -- |
  | critical  | Critical  | 严重 |
  | warning   | Warning   | 警告 |
  | triggered | Warning   | 警告 |
  | resolved  | Ok        | 恢复 |
</div>
