https://segmentfault.com/a/1190000015400227改天尝试一下
alertmanager
支持email,webhook等报警源支持,看到可以支持微信报警信息推送觉得有意思把玩一下,alertmanager
的0.15
版本微信报警推送有问题,后来我把版本降到0.14
后微信就能正常收到报警信息
Prometheus AlertManager
配置如下,alerting
与 global
同级# Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: - localhost:9093
rules
配置文件加入到Prometheus
配置文件中rule_files: - "/usr/local/prometheus/rules.yml"
rule.yml
文件groups: - name: prometheus_go_goroutines rules: - alert: go_goroutines_numbers expr: go_goroutines > 45 for: 15s annotations: summary: "prometheus的gorotine数据超过40!"
alertmanager
配置文件,加入微信配置信息global: resolve_timeout: 2m wechat_api_url: ‘https://qyapi.weixin.qq.com/cgi-bin/‘ wechat_api_secret: ‘xxx‘ wechat_api_corp_id: ‘xxx‘ route: group_by: [‘alertname‘] group_wait: 10s group_interval: 10s repeat_interval: 1h receiver: ‘wechat‘ receivers: - name: ‘wechat‘ wechat_configs: - send_resolved: true to_party: ‘1‘ agent_id: ‘1000002‘
wechat_api_url
: wechat
对外接口https://qyapi.weixin.qq.com/cgi-bin/
wechat_api_secret
: 企业微信("企业应用"-->"自定应用"[Prometheus
]--> "Secret") Prometheus
是本人自创建应用名称wechat_api_corp_id
: 企业信息("我的企业"--->"CorpID"[在底部])to_party
: 1
值是组的ID
你可通过链接去定制报警信息接收人或者组(https://work.weixin.qq.com/ap...agent_id
: 企业微信("企业应用"-->"自定应用"[Prometheus
]--> "AgentId") Prometheus
是本人自创建应用名称
invalid APISecret for CorpID
异常信息如下:
level=error ts=2019-06-20T08:33:42.779286895Z caller=dispatch.go:264 component=dispatchermsg="Notify for alerts failed" num_alerts=1 err="cancelling notify retry for "wechat"due to unrecoverable error: invalid APISecret for CorpID: xxxxxxxxxxx"
alertmanager
报警器推送源,在推送报invalid apisecret
,查看源码和官方文档发现wechat_config
会继续global wechat
配置,但是经过测试 wechat_config没有继承global wechat的配置所以才会出现上述异常global wechat
信息在wechat_config
中重新配置即可正常推送信息alertmanager
版本相关,本人测试时没有碰到,如有碰到可根据以上提供信息修改配置测试上善若水
提供异常信息和解决方案本人微信: 375419830