Prometheus Alertmanager自定义警报消息

时间:2020-05-10 17:28:33

标签: prometheus prometheus-alertmanager

有什么方法可以更改字段或将字段添加到Prometheus AlertManager的默认警报json格式

我正在使用prometheus AlertManager发送警报,还使用webhooks通过HTTP POST发送警报 (https://prometheus.io/docs/alerting/configuration/#wechat_config)。 Prometheus Alertmanager生成警报的默认json格式,但是我需要更改json格式(只需将默认json放在一个“记录”键内,或者只需要在默认json消息中添加一个字段)。可以在json中添加新的关键字段吗?。

默认警报json格式

{
  "version": "4",
  "groupKey": <string>,    // key identifying the group of alerts (e.g. to deduplicate)
  "status": "<resolved|firing>",
  "receiver": <string>,
  "groupLabels": <object>,
  "commonLabels": <object>,
  "commonAnnotations": <object>,
  "externalURL": <string>,  // backlink to the Alertmanager.
  "alerts": [
    {
      "status": "<resolved|firing>",
      "labels": <object>,
      "annotations": <object>,
      "startsAt": "<rfc3339>",
      "endsAt": "<rfc3339>",
      "generatorURL": <string> // identifies the entity that caused the alert
    },
    ...
  ]
}

需要添加新字段

{
  "records":[
{ "value":

...

}
]
}

示例json(在json中添加了“记录和值”)

{
  "records":[
{ "value":
{
  "receiver": "email-logs",
  "status": "firing",
  "alerts": [
    {
      "status": "firing",
      "labels": {
        "alertname": "CPUUsageAbove20%",
        "instance": "node-exporter:9100",
        "job": "node-exporter",
        "monitor": "my-project",
        "severity": "warn",
        "team": "raptors"
      },
      "annotations": {
        "dashboard": "www.prometheus.io",
        "description": "CPU usage on node-exporter:9100 has reached 60"
      },
      "startsAt": "2020-04-30T08:03:17.309164516Z",
      "endsAt": "0001-01-01T00:00:00Z",
      "generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
      "fingerprint": "9c558a8c20c2ba08"
    }
  ],
  "groupLabels": {
    "alertname": "CPUUsageAbove20%",
    "team": "raptors"
  },
  "commonLabels": {
    "alertname": "CPUUsageAbove20%",
    "instance": "node-exporter:9100",
    "job": "node-exporter",
    "monitor": "my-project",
    "severity": "warn",
    "team": "raptors"
  },
  "commonAnnotations": {
    "dashboard": "www.prometheus.io",
    "description": "CPU usage on node-exporter:9100 has reached 60"
  },
  "externalURL": "http://5493399b56dc:9093",
  "version": "4",
  "groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}
}
]}

0 个答案:

没有答案