> ## 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.

# UptimeRobot 告警集成

> 通过 Webhook 将 UptimeRobot Monitor 的宕机和恢复通知同步到 Flashduty On-call。

通过 UptimeRobot Webhook 集成将 Monitor 的宕机（Down）、恢复（Up）以及 SSL 证书和域名到期提醒同步到 Flashduty On-call。同一个 Monitor 的宕机通知和随后的恢复通知对应同一条 Flashduty 告警。

<Note>
  UptimeRobot 仅在 Team 及以上付费套餐（如 Team、Scale、Enterprise）提供 Webhook 集成，Free 和 Solo 套餐无法添加。
</Note>

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

  ***

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

  ### 使用专属集成

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

  ### 使用共享集成

  1. 进入 Flashduty 控制台，选择 **集成中心 → 告警事件**
  2. 选择 **UptimeRobot**，填写集成名称
  3. 配置默认路由并选择协作空间；创建后可在 **路由** 中增加更多规则
  4. 点击 **保存**，复制生成的 **推送地址**
</div>

## 在 UptimeRobot 中配置

***

<Steps>
  <Step title="添加 Webhook 集成">
    1. 登录 UptimeRobot 控制台，在左侧导航选择 **Integrations**，点击 **Add Integration**
    2. 选择 **Webhook**
    3. 将 Flashduty 集成的完整推送地址粘贴到 **Webhook URL**
  </Step>

  <Step title="配置 POST value">
    1. 在 **Send default variables** 中不要勾选 **As query string** 和 **As POST parameters**
    2. 把下面的 JSON 粘贴到 **POST value**，并勾选 **Send as JSON (application/json)**

    ```json theme={null}
    {
      "monitor_id": "*monitorID*",
      "monitor_url": "*monitorURL*",
      "monitor_friendly_name": "*monitorFriendlyName*",
      "monitor_type": "*monitorType*",
      "alert_type": "*alertType*",
      "alert_type_friendly_name": "*alertTypeFriendlyName*",
      "alert_details": "*alertDetails*",
      "alert_duration": "*alertDuration*",
      "alert_datetime": "*alertDateTime*",
      "incident_start_time": "*incidentStartTime*",
      "incident_end_time": "*incidentEndTime*",
      "http_status_code": "*httpStatusCode*",
      "monitoring_regions": "*monitoringRegions*",
      "monitor_group": "*monitorGroup*",
      "monitor_tags": "*monitorTags*",
      "dashboard_url": "*dashboardUrl*",
      "ssl_expiry_date": "*sslExpiryDate*",
      "ssl_expiry_days_left": "*sslExpiryDaysLeft*",
      "domain_expire_date": "*domainExpireDate*"
    }
    ```

    <Warning>
      请保留 `monitor_id` 和 `alert_type`。缺少 `monitor_id` 或 `alert_type` 不是 `1`、`2`、`3` 时，Flashduty 会拒绝请求，因为无法判断事件状态，也无法把恢复通知关联到原告警。
    </Warning>
  </Step>

  <Step title="选择通知事件">
    在 **Events to notify about** 中同时勾选 **Down events** 和 **Up events**。只勾选 Down events 时，Flashduty 告警不会自动恢复。如需接收证书和域名到期提醒，再勾选 **SSL & Domain expiry**。点击 **Save** 保存。
  </Step>

  <Step title="关联 Monitor">
    编辑需要接入的 Monitor，在其通知设置中选择刚创建的 Webhook 集成并保存。只有关联了该集成的 Monitor 才会向 Flashduty 发送通知。
  </Step>

  <Step title="验证">
    在 Monitor 详情页点击 **Test Notification** 并选择该 Webhook，UptimeRobot 会依次发送一条模拟的 Down 和一条模拟的 Up 通知，可用于确认推送地址和 POST value 配置正确。真实宕机时，UptimeRobot 会在 Monitor 恢复后发送 Up 通知，关闭对应的 Flashduty 告警。
  </Step>
</Steps>

## Alert Key

***

Flashduty 使用 `*monitorID*`（即 `monitor_id`）作为 Alert Key。UptimeRobot 的 Down 和 Up 通知都携带同一个 Monitor ID，因此同一个 Monitor 的宕机、重复提醒和恢复会落在同一条告警上；不同 Monitor 生成不同的告警。

Monitor 名称、URL、告警详情、HTTP 状态码和时间的变化都不会改变 Alert Key。删除后重新创建的 Monitor 会得到新的 Monitor ID，与旧告警不再关联。

## 状态和告警等级

***

| UptimeRobot `*alertType*` | 含义              | Flashduty 状态或等级  |
| :------------------------ | :-------------- | :--------------- |
| `1`                       | Down，Monitor 宕机 | Critical         |
| `2`                       | Up，Monitor 恢复   | 恢复，原等级为 Critical |
| `3`                       | SSL 证书或域名即将到期   | Warning          |

空值或其他 `alert_type` 会被拒绝，避免把无法判断状态的请求写入错误的告警生命周期。

SSL 证书和域名到期提醒没有对应的恢复通知，每条提醒都会生成一条独立的 Warning 告警，不会自动恢复，处理后请手动关闭。

## 投递说明

***

* UptimeRobot 对 Down 和 Up 通知只发送一次：请求超时、连接失败或返回非 2xx 时不会重试。如果 Up 通知未送达，对应告警会保持活动状态，需要手动关闭
* 在 Monitor 设置中配置的重复提醒（recurring notifications）会以相同的 Monitor ID 再次发送 Down 通知，Flashduty 将其合并到已有告警

## 排查问题

***

* **Flashduty 返回参数错误**：确认已勾选 **Send as JSON (application/json)**，且 POST value 是有效 JSON，`monitor_id` 和 `alert_type` 保留原样
* **JSON 解析失败**：检查 Monitor 名称或告警详情是否包含双引号或反斜杠，这类字符可能让渲染后的 POST value 不再是合法 JSON
* **告警没有恢复**：确认在 **Events to notify about** 中勾选了 **Up events**，并检查 Up 通知发出时 Flashduty 推送地址是否可达
* **收不到任何通知**：确认 Monitor 已关联该 Webhook 集成，且 UptimeRobot 账号处于 Team 或更高套餐
* **自定义请求头**：UptimeRobot 支持为 Webhook 添加最多 10 个自定义请求头，Flashduty 通过推送地址中的 `integration_key` 鉴权，无需额外请求头

更多变量含义请参阅 [UptimeRobot Webhook Integration](https://help.uptimerobot.com/en/articles/14498593-webhook-integration)。
