发布时间: 2024-11-19 文章作者: myluzh 分类名称: Kubernetes 朗读文章
global: resolve_timeout: 5m # wechat wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/' wechat_api_secret: '3uxxxxxxxxxxxxxxxxxxxxxxxxWv4' wechat_api_corp_id: 'wwxxxxxxxxb1' inhibit_rules: - source_match: severity: critical target_match_re: severity: warning|info equal: - namespace - alertname - source_match: severity: warning target_match_re: severity: info equal: - namespace - alertname receivers: - name: wechat wechat_configs: - send_resolved: true agent_id: '1000002' to_party: '1' - name: null_receiver route: group_by: - namespace receiver: null_receiver group_interval: 1m group_wait: 10s repeat_interval: 1m routes: - match: namespace: dev-test receiver: wechat
当满足条件时,告警按 namespace 分组,按照配置的时间间隔进行通知发送,所有告警默认不发送通知,除非 namespace 为 dev-test 的告警会被发送到 wechat 接收器。
如果觉得间隔时间太短可以调整:global: resolve_timeout: 5m .... templates: - '/etc/alertmanager/config/*.tmpl' ....2、导入tmpl模板文件
wechat.tmpl内容:
{{ define "wechat.default.message" }} {{ if gt (len .Alerts.Firing) 0 -}} Alerts Firing: {{ range .Alerts }} 告警级别:{{ .Labels.severity }} 告警类型:{{ .Labels.alertname }} 故障主机: {{ .Labels.instance }} 告警主题: {{ .Annotations.summary }} 告警详情: {{ .Annotations.description }} 触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }} {{- end }} {{- end }} {{ if gt (len .Alerts.Resolved) 0 -}} Alerts Resolved: {{ range .Alerts }} 告警级别:{{ .Labels.severity }} 告警类型:{{ .Labels.alertname }} 故障主机: {{ .Labels.instance }} 告警主题: {{ .Annotations.summary }} 触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }} 恢复时间: {{ .EndsAt.Format "2006-01-02 15:04:05" }} {{- end }} {{- end }} 告警链接: {{ template "__alertmanagerURL" . }} {{- end }}3、验证模板是否导入
/alertmanager $ ls /etc/alertmanager/config/ alertmanager.yaml wechat.tmpl
# 收件人配置 .... receivers: - name: 'wechat' wechat_configs: .... message: '{{ template "wechat.default.message" . }}' ....
标签: Prometheus Alertmanager 企业微信 告警 wechat wechatapi
发表评论