原文地址:Alertmanager - 发送测试通知(永久地址,保存网址不迷路 🙃)
问题描述
当进行 Alertmanager 设置之后,我们希望能够发送告警消息进行测试,以验证配置已生效。但是我们又不能直接关闭服务等待 Prometheus 触发告警消息 :-)
好在 Alertmanager 提供告警接口,允许我们以 HTTP 协议进行调用,来要求其发送告警信息。
该笔记将记录:在 Shell 中,调用 Alertmanager 服务来发送通知的方法,以及相关问题的处理方法。
解决方法
详细内容,参考 Clients | Prometheus 文档
下面是发送告警的简单示例:
#!/usr/bin/env bash alerts_message='[ { "labels": { "alertname": "DiskRunningFull", "dev": "sda1", "instance": "example1", "msgtype": "testing" }, "annotations": { "info": "The disk sda1 is running full", "summary": "please check the instance example1" } }, { "labels": { "alertname": "DiskRunningFull", "dev": "sda2", "instance": "example1", "msgtype": "testing" }, "annotations": { "info": "The disk sda2 is running full", "summary": "please check the instance example1", "runbook": "the following link http://test-url should be clickable" } } ]' curl -XPOST -d"$alerts_message" http://127.0.0.1:9093/api/v1/alerts
参考文献
send a dummy alert to prometheus-alertmanager · GitHub
alertmanager/send_alerts.sh at master · prometheus/alertmanager · GitHub