我认为'webhook 接收器'可以帮助你。更多信息可以参考文档https://prometheus.io/docs/alerting/latest/configuration/#webhook_config
这是基于 blackbox_exporter 的指标抓取创建的 webhook 警报的示例。
- 普罗米修斯规则设置
您需要创建规则来触发警报,此处定义了一个名为“http_health_alert”的规则作为示例。
groups:
- name: http
rules:
- alert: http_health_alert
expr: probe_success == 0
for: 3m
labels:
type: http_health
annotations:
description: Health check for {{$labels.instance}} is down
- 警报管理器设置
'match' 设置为 http_health_alert,警报将通过 HTTP/POST 方法发送到'http://example.com/alert/receiver'(我想你会提前准备好)。警报会将 JSON 格式发布到配置的端点“http://example.com/alert/receiver”。并且您还可以针对不同的标签内容,在端点/程序中自定义不同的接收方式或接收信息。
global:
route:
group_by: [alertname, env]
group_wait: 30s
group_interval: 3m
repeat_interval: 1h
routes:
- match:
alertname: http_health_alert
group_by: [alertname, env]
group_wait: 30s
group_interval: 3m
repeat_interval: 1h
receiver: webhook_receiver
receivers:
- name: webhook_receiver
webhook_configs:
- send_resolved: true
url: http://example.com/alert/receiver
- name: other_receiver
email_configs:
- send_resolved: true
to: xx
from: xxx