文档文档

OpsGenie v2 事件处理程序

OpsGenie 是一个面向 DevOps 和 ITOps 团队的事件响应编排平台。Kapacitor 可以配置为将警报消息发送到 OpsGenie。

此页面特定于 OpsGenie 的 v2 API。如果仍在使用其 v1 API,请参阅 OpsGenie v1 事件处理程序 文档。

配置

OpsGenie v2 事件处理程序的配置以及默认 选项 值在 kapacitor.conf 中设置。下面是一个配置示例

[opsgenie2]
  enabled = true
  api-key = "mysupersecretapikey"
  teams = ["team1", "team2"]
  recipients = ["recipient1", "recipient2"]
  url = "https://api.opsgenie.com/v2/alerts"
  recovery_action = "notes"
  details = false
  global = false

enabled

设置为 true 以启用 OpsGenie v2 事件处理程序。

api-key

您的 OpsGenie API 密钥。

teams

默认 OpsGenie 团队。可以按警报覆盖。

recipients

默认 OpsGenie 收件人。可以按警报覆盖。

url

OpsGenie API URL。通常不需要更改。

recovery_action

recovery_action 指定警报恢复时应采取的操作。有效值为:

  • notes - 向警报添加注释。
  • close - 关闭警报。
  • custom - 使用 .RecoveryAction() 方法在 TICK 脚本中指定 recovery_action

details

如果设置为 true,则警报的 details 字段将作为 OpsGenie 警报的 description 字段发送。如果设置为 false,则 details 将被编码为 description。

global

如果设置为 true,所有警报都将发送到 OpsGenie,而无需在 TICKscript 中指定 opsgenie2。团队和收件人仍然可以被覆盖。

选项

以下 OpsGenie v2 事件处理程序选项可以在 handler 文件 中设置,或者在使用 TICKscript 中的 .opsGenie2() 时设置。

名称类型描述
teams-listlist of strings团队列表。
recipients-listlist of strings收件人列表。

示例:处理程序文件

id: handler-id
topic: topic-name
kind: opsgenie2
options:
  teams-list:
    - 'team1'
    - 'team2'
  recipients-list:
    - 'recipient1'
    - 'recipient2'

示例:TICKscript

|alert()
  // ...
  .opsGenie2()
    .teams('team1', 'team2')
    .recipients('recipient1', 'recipient2')

OpsGenie 设置

要允许 Kapacitor 将警报发送到 OpsGenie,请创建一个 OpsGeneie API 集成。将生成的 API 密钥用作 kapacitor.conf[opsgenie2] 部分的 api-key

使用 OpsGenie 事件处理程序

kapacitor.conf 中启用并配置 OpsGenie v2 事件处理程序后,请在 TICKscript 中使用 .opsGenie2() 属性将警报发送到 OpsGenie,或者定义一个订阅主题并向 OpsGenie 发布警报的 OpsGenie v2 处理程序。

以下示例使用了 kapacitor.conf 中定义的以下 OpsGenie 配置

kapacitor.conf 中的 OpsGenie v2 设置

[opsgenie2]
  enabled = true
  api-key = "mysupersecretapikey"
  teams = ["engineering"]
  recipients = ["supervisor1", "supervisor2"]
  url = "https://api.opsgenie.com/v2/alerts"
  recovery_action = "close"
  global = false

从 TICKscript 发送警报到 OpsGenie

以下 TICKscript 使用 .opsGenie2() 事件处理程序,在空闲 CPU 使用率降至 10% 以下时,将消息“Hey, check your CPU”发送到 OpsGenie。

opsgenie2-cpu-alert.tick

stream
  |from()
    .measurement('cpu')
  |alert()
    .crit(lambda: 'usage_idle' < 10)
    .message('Hey, check your CPU')
    .opsGenie2()
      .teams('engineering', 'support')
      .recoveryAction('notes')

从定义的处理程序发送警报到 OpsGenie

以下设置将一条消息为“Hey, check your CPU”的警报发送到 cpu 主题。然后添加一个 OpsGenie v2 处理程序,该处理程序订阅 cpu 主题并将所有警报消息发布到 OpsGenie。

创建将警报消息发布到主题的 TICKscript。当空闲 CPU 使用率低于 10% 时,下面的 TICKscript 将警报消息发送到 cpu 主题。

cpu_alert.tick

stream
  |from()
    .measurement('cpu')
  |alert()
    .crit(lambda: 'usage_idle' < 10)
    .message('Hey, check your CPU')
    .topic('cpu')

添加并启用 TICKscript

kapacitor define cpu_alert -tick cpu_alert.tick
kapacitor enable cpu_alert

创建一个订阅 cpu 主题并使用 OpsGenie v2 事件处理程序将警报发送到 OpsGenie 的处理程序文件。

opsgenie2_cpu_handler.yaml

id: opsgenie-cpu-alert
topic: cpu
kind: opsgenie2
options:
  teams-list:
    - 'engineering'
    - 'support'

添加处理器

kapacitor define-topic-handler opsgenie2_cpu_handler.yaml

此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2