community.general.pagerduty_alert 模块 – 触发、确认或解决 PagerDuty 事件

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,有关详细信息,请参见 要求

要在剧本中使用它,请指定:community.general.pagerduty_alert

概要

  • 此模块将允许您通过发送事件来触发、确认或解决 PagerDuty 事件

要求

执行此模块的主机需要满足以下要求。

  • PagerDuty API 访问

参数

参数

注释

api_key

字符串

PagerDuty API 密钥(只读访问),在 PagerDuty 网站上生成。

如果 api_version=v1,则为必需项。

api_version

字符串

在 community.general 7.4.0 中添加

我们希望用来运行该模块的 API 版本。

V1 在我们可以用来触发事件的选项方面更加有限。

V2 有更多变量,例如,severitysourcecustom_details 等。

选项

  • "v1" ← (默认)

  • "v2"

client

字符串

触发此事件的监视客户端的名称。

client_url

字符串

触发此事件的监视客户端的 URL。

component

字符串

在 community.general 7.4.0 中添加

负责该事件的源计算机的组件,例如 mysqleth0

custom_details

字典

在 community.general 7.4.0 中添加

有关事件和受影响系统的其他详细信息。

带有自定义键和值的字典。

desc

字符串

对于 state=triggered - 必需。导致此触发的问题的简短描述。当生成电话、短信和警报电子邮件时,将使用此字段(或截断版本)。它还将显示在 PagerDuty UI 中的事件表中。最大长度为 1024 个字符。

对于 state=acknowledgedstate=resolved - 将出现在与此事件关联的事件日志中的文本。

默认: "通过 Ansible 创建"

incident_class

字符串

在 community.general 7.4.0 中添加

事件的类/类型,例如 ping failurecpu load

incident_key

字符串

标识应应用此 state 的事件。

对于 state=triggered - 如果没有使用此键打开(即未解决的)事件,则将创建一个新事件。如果已存在具有匹配键的打开事件,则此事件将附加到该事件的日志中。事件键提供了一种简单的“去重”问题报告方法。如果没有提供 incident_key,则将由 PagerDuty 生成。

对于 state=acknowledgedstate=resolved - 这应该是事件首次由触发事件打开时您收到的 incident_key。引用已解决或不存在的事件的确认事件将被丢弃。

integration_key

字符串

您的“通用 API”服务之一的 GUID。

这是 PagerDuty 服务的“集成”选项卡上列出的“集成密钥”。

字符串

在 community.general 7.4.0 中添加

link_url 的简短描述。

字符串

在 community.general 7.4.0 中添加

与警报相关的链接 URL。例如,网站或作业链接。

name

字符串

PagerDuty 唯一的子域名。已过时。它不与 PagerDuty REST v2 API 一起使用。

service_id

字符串

将触发、确认或解决事件的 PagerDuty 服务的 ID。

如果 api_version=v1,则为必需项。

service_key

字符串

您的“通用 API”服务之一的 GUID。已过时。请使用 integration_key

severity

字符串

在 community.general 7.4.0 中添加

事件描述的有关受影响系统的状态的感知严重性。

state=triggerapi_version=v2 的情况下是必需的。

选项

  • "critical" ← (默认)

  • "warning"

  • "error"

  • "info"

source

字符串

在 community.general 7.4.0 中添加

受影响系统的唯一位置,最好是主机名或 FQDN。

state=triggerapi_version=v2 的情况下是必需的。

state

string / required

要发送的事件类型。

选项

  • "triggered"

  • "acknowledged"

  • "resolved"

属性

属性

支持

描述

check_mode

支持: 完全

可以在 check_mode 中运行,并返回更改的状态预测,而无需修改目标。

diff_mode

支持:

当处于差异模式时,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

示例

- name: Trigger an incident with just the basic options
  community.general.pagerduty_alert:
    name: companyabc
    integration_key: xxx
    api_key: yourapikey
    service_id: PDservice
    state: triggered
    desc: problem that led to this trigger

- name: Trigger an incident with more options
  community.general.pagerduty_alert:
    integration_key: xxx
    api_key: yourapikey
    service_id: PDservice
    state: triggered
    desc: problem that led to this trigger
    incident_key: somekey
    client: Sample Monitoring Service
    client_url: http://service.example.com

- name: Acknowledge an incident based on incident_key
  community.general.pagerduty_alert:
    integration_key: xxx
    api_key: yourapikey
    service_id: PDservice
    state: acknowledged
    incident_key: somekey
    desc: "some text for incident's log"

- name: Resolve an incident based on incident_key
  community.general.pagerduty_alert:
    integration_key: xxx
    api_key: yourapikey
    service_id: PDservice
    state: resolved
    incident_key: somekey
    desc: "some text for incident's log"

- name: Trigger an v2 incident with just the basic options
  community.general.pagerduty_alert:
    integration_key: xxx
    api_version: v2
    source: My Ansible Script
    state: triggered
    desc: problem that led to this trigger

- name: Trigger an v2 incident with more options
  community.general.pagerduty_alert:
    integration_key: xxx
    api_version: v2
    source: My Ansible Script
    state: triggered
    desc: problem that led to this trigger
    incident_key: somekey
    client: Sample Monitoring Service
    client_url: http://service.example.com
    component: mysql
    incident_class: ping failure
    link_url: https://pagerduty.com
    link_text: PagerDuty

- name: Acknowledge an incident based on incident_key using v2
  community.general.pagerduty_alert:
    api_version: v2
    integration_key: xxx
    incident_key: somekey
    state: acknowledged

- name: Resolve an incident based on incident_key
  community.general.pagerduty_alert:
    api_version: v2
    integration_key: xxx
    incident_key: somekey
    state: resolved

作者

  • Amanpreet Singh (@ApsOps)

  • Xiao Shen (@xshen1)