You need to enable JavaScript to run this app.
导航

通用 Webhook 格式说明

最近更新时间2024.02.02 17:21:37

首次发布时间2023.07.05 16:23:15

托管 Prometheus 支持您使用通用 Webhook 接收告警信息。本文为您介绍通用 Webhook 的格式。

背景

您可以在托管 Promethues 服务中创建告警通知策略,并指定使用通用 Webhook 接收告警信息。详情请参见 创建告警通知策略

在此场景下,在接收端如何解析通用 Webhook 发来的信息格式,并明确不同字段表示的含义,尤为重要。

格式示例

以下为通用 Webhook 的格式示例。

{
  "status": "firing",
  "alerts": [
    {
      "status": "firing",
      "labels": {
        "account_id": "200000000",
        "internal_label_alert_id": "7f55f4xxx",
        "internal_label_alert_level": "P0",
        "alertname": "aec4cc4a-5457-4a31-b378-0442d140e6b8", 
        "__name__": "container_memory_usage_bytes",        
        "node": "192.168.1.158"
      },
      "annotations": {
        "__alerting_resource_current_value__": "1",
        "__alerting_rule_levels__": "[{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P0\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":5},{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P1\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":6},{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P2\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":7}]",
        "__alerting_rule_query__": "{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"PromQL\":\"container_memory_usage_bytes{container=\\\"\\\"}\",\"WorkspaceID\":\"046afaa0-8dc4-446a-bf36-df2d7a8aab99\"}",
        "__alerting_rule_type__": "vmp/PromQL"
      },
      "startsAt": "2022-11-24T19:31:00+08:00",
      "endsAt": "0001-01-01T00:00:00Z",
      "generatorURL": "",
      "fingerprint": "81e649cc69c24b6d"
    }
  ],
  "groupLabels": {
    "internal_label_alert_level": "P0",
    "alertname": "aec4cc4a-5457-4a31-b378-0442d140e6b8"
  },
  "commonLabels": {
    "account_id": "200000000",
    "internal_label_alert_id": "7f55f4-0dd81796416f412f-c20ca4036a7f4260",
    "internal_label_alert_level": "P0",
    "alertname": "aec4cc4a-5457-4a31-b378-0442d140e6b8",
    "__name__": "container_memory_usage_bytes",       
    "node": "192.168.1.158"
  },
  "commonAnnotations": {
   "__alerting_resource_current_value__":"1",
    "__alerting_rule_levels__": "[{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P0\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":5},{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P1\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":6},{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"Level\":\"P2\",\"For\":\"0s\",\"Comparator\":\"\\u003c\",\"Threshold\":7}]",
    "__alerting_rule_query__": "{\"AlertingRuleID\":\"aec4cc4a-5457-4a31-b378-0442d140e6b8\",\"PromQL\":\"container_memory_usage_bytes{container=\\\"\\\"}\",\"WorkspaceID\":\"046afaa0-8dc4-446a-bf36-df2d7a8aab99\"}",
    "__alerting_rule_type__": "vmp/PromQL",
  },
  "alertingRuleName": "name"
}

参数说明

通用 Webhook 中的参数说明如下表所示。

字段名称类型示例值说明

status

string

firing

Webhook 的状态,取值:

  • firing:告警中
  • resolved:已解决
alertslist Alert告警事件详情。
groupLabelsmap<string,string>-Webhook 通知聚合发送的 labels。
commonLabelsmap<string,string>-告警事件共同的 labels。
commonAnnotationsmap<string,string>-告警事件共同的 annotations。
alertingRuleNamestringCPU 使用率超过 80%。告警规则名称。

Alert

Alert 的结构如下表所示。

字段名称类型示例值说明

status

string

firing

告警事件的状态,取值:

  • firing:告警中
  • resolved:已解决

labels

map<string,string>

{
    "account_id": "200000000",
    "internal_label_alert_id": "7f55f4xxxx",
    "internal_label_alert_level": "P1",
    "alertname": "aec4cc4a-5457-4a31-b378-0442d140e6b8",
    "__name__": "container_memory_usage_bytes",
    "node": "192.168.1.158",
    "job": "kubelet-cadvisor"
}
  • 告警事件元信息,包括:
    • 内置信息。

      • account_id :火山引擎账号(主账号)的 ID。

      • alertname :告警规则的 ID。

      • internal_label_alert_id :当前告警事件的 ID。

      • internal_label_alert_level :当前告警事件的等级。

    • PromQL 查询结果的 labels,例如:

    "__name__": "container_memory_usage_bytes"
    "node": "192.168.1.158"
    "job": "kubelet-cadvisor"
    

annotations

map<string,string>

{
    "__alerting_resource_current_value__": "1",
    "__alerting_rule_levels__": "[{\"AlertingRuleID\":\"aec4cc4axxxx"}]",
    "__alerting_rule_query__": "{\"AlertingRuleID\":\"aec4cc4axxx"}",
    "__alerting_rule_type__": "vmp/PromQL"
}
  • 告警事件元信息,包括:
    • 规则元信息。

      • __alerting_rule_levels__ :告警规则的等级配置。

      • __alerting_rule_query__:告警规则的 PromQL 配置。

      • __alerting_rule_type__:告警规则类型。

    • __alerting_resource_current_value__:事件的当前值。

startsAtstring2022-11-24T19:31:00+08:00告警事件的触发时间。

endsAt

string

0001-01-01T00:00:00Z

告警事件的结束时间。

说明

当告警事件的状态statusfiring时,endsAt默认为0001-01-01T00:00:00Z,该值无实际意义。