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

# PagerDuty 集成

> 将 PagerDuty 连接到 Devin，即可由事件触发自动化，并让 Devin 会话访问事件、服务和值班计划。

连接 PagerDuty 后，事件一旦触发，Devin 就能立即着手处理。PagerDuty 事件可触发 Devin [自动化](https://docs.devin.ai/zh/product-guides/automations.md)和 [Devin Oncall](https://docs.devin.ai/zh/product-guides/devin-oncall.md) 响应程序，而 PagerDuty MCP 服务器则让 Devin 会话能够访问事件、服务和值班计划。

“连接”中的 PagerDuty 页面包含三个部分，三者全部完成后，PagerDuty 即设置完毕：

* **连接**：Devin 用于发布事件备注和更新的 REST API 密钥。
* **Webhook**：将事件发送给 Devin 以触发自动化。
* **应用注册**：设置 PagerDuty MCP 服务器，并让成员连接各自的 PagerDuty 账户。

## 配置集成

1. 在 PagerDuty 中，前往 **Integrations > API Access Keys**，点击“Create New API Key”。创建一个具有完全访问权限的 **General Access** 密钥并复制。不接受用户 API 令牌。
2. 在 app.devin.ai 的 Devin 账户中，前往 [Settings > Connections > PagerDuty](https://app.devin.ai/settings/connections/pagerduty)，然后点击“Connect”。
3. 选择你的 **API region** (美国或欧盟) ，然后填写：
   * **Actor email**：Devin 的事件备注和更新将归属于此 PagerDuty 用户，建议使用专用的服务用户。
   * **General Access REST API key**：你在步骤 1 中创建的密钥。
4. 点击“Connect”。Devin 会自动在 PagerDuty 中创建 webhook 订阅，以接收事件通知。

## 配置 webhook 订阅

连接后，Devin 会在 PagerDuty 中创建一个账户级的 webhook 订阅，用于将以下事件发送给 Devin：

* `incident.triggered`
* `incident.acknowledged`
* `incident.resolved`
* `incident.priority_updated`
* `incident.reassigned`
* `incident.service_updated`

设置页面的 **Webhook** 部分会显示该订阅的状态。如果自动设置失败，请点击“Retry webhook setup”，或手动添加 webhook：

1. 在 **Webhook** 部分，点击“Add webhook”并复制 webhook URL。
2. 在 PagerDuty 中，前往 **Integrations > Generic Webhooks (v3)**，添加一个指向该 URL 的 webhook，并将作用域设置为 **Account**。
3. 选择上面列出的事件类型。
4. 复制 PagerDuty 仅显示一次的签名密钥，粘贴到 Devin 中，然后点击“Save”。

> [!NOTE]
>
> 断开 PagerDuty 连接会停止事件推送，并删除 Devin 创建的 webhook 订阅，但不会移除应用注册或 PagerDuty MCP 服务器。

## 将 Devin 注册为 OAuth app

PagerDuty MCP 服务器通过 OAuth 让每位成员登录。PagerDuty 不支持自动注册 OAuth 客户端，因此需要由 Admin 在 PagerDuty 中将 Devin 注册为一个 OAuth app，并在“连接”的 **App registration** 下添加它。保存该 app 注册信息后，系统就会为你设置好 PagerDuty MCP 服务器。

### 在 PagerDuty 中创建 app

1. 在 [Settings > 连接 > PagerDuty](https://app.devin.ai/settings/connections/pagerduty) 中，复制 **App registration** 部分显示的 **Redirect URI**。
2. 在 PagerDuty 中，前往 **Integrations > App Registration**，点击“New App”。输入名称 (例如 `Devin`) ，并选择 **OAuth 2.0**。
3. 选择 **Scoped OAuth**，并将 Devin 提供的 redirect URI 添加为 **Redirect URL**。
4. 在权限作用域中，选择你希望 Devin 拥有的作用域。我们建议选择 `abilities.read`、`escalation_policies.read`、`incidents.read`、`incidents.write`、`oncalls.read`、`priorities.read`、`schedules.read`、`services.read`、`teams.read` 和 `users.read`。
5. 完成 app 注册，然后复制 **client ID** 和 **客户端密钥**。

### 在 Devin 中添加应用注册

1. 在 **App registration** 部分，填入你的 PagerDuty 应用的 **Client ID** 和 **客户端密钥**。
2. 选择你的 PagerDuty 账户所属的 **API region** (美国或欧盟) 。
3. 将 **Scopes** 留空，即可使用 PagerDuty 应用上已配置的权限。若只需请求其中一部分，请输入以空格分隔的作用域列表，且这些作用域必须已在该应用上启用。
4. 点击“Save”。

随后，Devin 会为你所在区域添加 PagerDuty MCP 服务器。对于企业账户，只需为整个企业添加一次，所有组织均可使用；否则，它只会添加到你的组织中。如果已安装 PagerDuty MCP 服务器，Devin 不会重复添加。

> [!NOTE]
>
> 更改 client ID 或区域会断开每位成员的 PagerDuty 账户连接，成员需要重新连接。

### 已有的 PagerDuty MCP 服务器

使用自有 OAuth client ID 和 secrets 安装的 PagerDuty MCP 服务器仍可正常工作，已经通过它连接的成员也会保持连接状态。**App registration** 部分会显示警告，提示其尚未完全连接。

如需切换，请先添加 app registration，然后在该警告中点击 "Use app registration"。随后，成员需通过 app registration 重新连接各自的 PagerDuty 账户。

### 使用客户端凭据实现共享访问

企业管理员也可以改用 **Client credentials** 授权类型，将 PagerDuty 添加为企业 MCP 服务器。这样所有会话都会使用同一个共享的应用令牌，成员无需登录。使用此授权类型时，PagerDuty 要求填写 **OAuth scope** 字段，且其值必须以你的账户选择器开头：

```text theme={null}
as_account-<region>.<subdomain> <scopes>
```

其中 `<region>` 为 `us` 或 `eu`，`<subdomain>` 是你的 PagerDuty URL 中 `.pagerduty.com` 之前的部分；其后是该应用已启用的作用域列表，以空格分隔。PagerDuty MCP 服务器要求令牌包含 `users.read` 才会接受，因此应用必须拥有该作用域，并且该作用域必须出现在列表中。例如：`as_account-us.acme users.read incidents.read oncalls.read schedules.read services.read`。如果缺少该作用域或格式有误，将无法生成令牌，该服务器会在 Customize 中显示 **Connect**。

> [!NOTE]
>
> Client credentials 方式仅支持只读访问。即使已授予 `*.write` 作用域，PagerDuty 也会拒绝来自应用令牌的写入操作 (例如 `manage_incidents`) ，因为写入操作需要用户身份。请仅申请 `*.read` 作用域。如需写入权限，请使用个人连接，或使用以专用 PagerDuty 机器人用户身份连接的组织级 Authorization code 服务器。

## 连接你的 PagerDuty 用户账户

除了组织级集成外，每位团队成员还需将自己的 PagerDuty 账户关联到 Devin 账户。这样 Devin 就能以该成员的身份使用 PagerDuty MCP 服务器。创建 PagerDuty 自动化同样需要完成此关联。

要连接你的用户账户，请前往 [Personal 连接](https://app.devin.ai/account/connections)，点击 PagerDuty 旁边的“Connect”，并在 PagerDuty 中授权访问。请使用你的组织所连接的那个 PagerDuty 账户下的用户。

> [!NOTE]
>
> 只有在 admin 添加了[App registration](#register-devin-as-an-oauth-app)之后，成员才能进行连接。通过App registration实现的 PagerDuty MCP 访问始终是个人级的：Devin 不会为此使用共享的组织令牌，因此每位成员必须先连接自己的 PagerDuty 用户账户，Devin 才能在其会话中使用 PagerDuty 工具。唯一的例外是使用[客户端凭据](#shared-access-with-client-credentials)的企业 MCP 服务器。

## 从 PagerDuty 触发 Devin

Devin 通过[自动化](https://docs.devin.ai/zh/product-guides/automations.md)开始处理 PagerDuty 事件。连接 PagerDuty 后，你无需为每个自动化单独设置 webhook。

1. 进入 **Automations**，创建一个新的自动化。
2. 添加触发器，选择 **PagerDuty**，然后选择一个事件：
   * **Incident triggered**：新事件被创建。
   * **Incident acknowledged**：有人确认了某个事件。
   * **Incident resolved**：某个事件已解决。
   * **Incident updated**：某个事件的优先级、指派或服务发生变更。
3. 可根据需要添加条件，缩小匹配的事件范围：
   * **Service**、**Team** 和 **Priority**：选项从你的 PagerDuty 账户加载。
   * **Urgency** (`high` 或 `low`) 和 **Status**。
   * **Title**、**Escalation policy** 和 **Assignee**。
   * **Change** (`priority`、`assignment` 或 `service`) ：仅适用于 **Incident updated**。
4. 添加 **Start session** 动作，写明给 Devin 的指示，然后保存。

例如，若要排查结账服务上的高紧急度事件，可使用 **Incident triggered** 事件，并设置条件 **Service** 为 `checkout-api`、**Urgency** 为 `high`。然后添加类似这样的提示："调查此事件。检查 checkout-api 最近的部署和错误日志，找出可能的根本原因。"

> [!NOTE]
>
> 要创建或编辑带有 PagerDuty 触发器的自动化，你必须先[连接你的 PagerDuty 用户账户](#connecting-your-pagerduty-user-account)。你的 PagerDuty 用户必须属于你的组织所连接的那个 PagerDuty 账户。


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