alertmanger钉钉微信告警-1

部署钉钉webhook

docker run -d -p 8060:8060 --name webhook timonwong/prometheus-webhook-dingtalk:latest --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=(你的钉钉token)

运行 alertmanger

docker run --name alertmanger -d  -p 9093:9093  -v /newmoni/alertmanager.yml:/etc/alertmanager/alertmanager.yml -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro prom/alertmanager:latest
global:
  resolve_timeout: 2m #微信报警
  wechat_api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
  wechat_api_secret: 'EKOIrYwBQKhIQgL0ZL-ekxYfD7MYc9ch8QXCY'
  wechat_api_corp_id: 'wx2a617f6ffb5c0'

templates:
  - '/alertmanager/*.tmpl' #微信和钉钉的模板
route:
  group_by: ['alertname']
  #group_by: [cluster,alertname]
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 30m
  receiver: 'webhook'
receivers:
- name: 'webhook'
  wechat_configs:
  - send_resolved: true
    to_party: '2'
    agent_id: '5'
  webhook_configs: #钉钉告警
  - url: 'http://10.22.8.5:8060/dingtalk/webhook1/send'
    #send_resolved: true
    send_resolved: true

钉钉模板

{{ define "ding.link.content" }}
{{ if gt (len .Alerts.Firing) 0 -}}
告警列表:
-----------
{{ template "__text_alert_list" .Alerts.Firing }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}
恢复列表:
{{ template "__text_resolve_list" .Alerts.Resolved }}
{{- end }}
{{- end }}

微信模板

/alertmanager $ cat wechat.tmpl

{{ define "wechat.default.message" }}
{{ range $i, $alert :=.Alerts }}
======DepOps告警======
告警状态:{{ .Status }}
告警级别:{{ $alert.Labels.severity }}
告警类型:{{ $alert.Labels.alertname }}
告警应用:{{ $alert.Annotations.summary }}
告警主机:{{ $alert.Labels.instance }}
告警详情:{{ $alert.Annotations.description }}
触发阀值:{{ $alert.Annotations.value }}
告警时间:{{ $alert.StartsAt.Format "2006-01-02 15:04:05" }}
==========end========
{{ end }}
{{ end }}

微信告警
alertmanger钉钉微信告警-1_第1张图片
钉钉告警
PS:好像不需要模板
alertmanger钉钉微信告警-1_第2张图片

你可能感兴趣的:(Prometheus)