linux 微信告警消息secret,Prometheus AlertManager 微信报警配置

Prometheus AlertManager 微信报警配置

alertmanager支持email,webhook等报警源支持,看到可以支持微信报警信息推送觉得有意思把玩一下,alertmanager的0.15版本微信报警推送有问题,后来我把版本降到0.14后微信就能正常收到报警信息

微信企业号申请

进入企业号注册页面,一些信息可以随便填写,但是管理员信息必须真实有效

创建应用("企业应用"-->"创建应用")

Prometheus中AlertManager配置

Prometheus AlertManager配置如下,alerting 与 global同级

# Alertmanager configuration

alerting:

alertmanagers:

- static_configs:

- targets:

- localhost:9093

rules配置文件加入到Prometheus配置文件中

rule_files:

- "/usr/local/prometheus/rules.yml"

Prometheus rules配置

创建rule.yml文件

根据需求添加报警规则

groups:

- name: prometheus_go_goroutines

rules:

- alert: go_goroutines_numbers

expr: go_goroutines > 45

for: 15s

annotations:

summary: "prometheus的gorotine数据超过40!"

Prometheus AlertManager配置

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=dispatcher msg="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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值