配置alertmanager钉钉告警
[root@prometheus ~]# wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v1.4.0/prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
[root@prometheus ~]# tar xf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# ln -sv /usr/local/prometheus-webhook-dingtalk-1.4.0.linux-amd64/ /usr/local/Prometheus_webhook-dingtalk
[root@prometheus ~]# mkdir -p /usr/local/Prometheus_webhook-dingtalk/template
[root@prometheus ~]# vim /usr/local/Prometheus_webhook-dingtalk/template/template.tmpl
{{ define "__subject" }}[Linux 基础监控告警:{{ .Alerts.Firing | len }}] {{ end }}
{{ define "__text_list" }}{{ range . }}
{{ range .Labels.SortedPairs }}
{{ if eq .Name "instance" }}> 实例: {{ .Value | html }}{{ end }}
{{ end }}
{{ range .Labels.SortedPairs }}
{{ if eq .Name "serverity" }}> 告警级别: {{ .Value | html }}{{ end }}
{{ if eq .Name "hostname" }}> 主机名称: {{ .Value | html }}{{ end }}
{{ end }}
{{ range .Annotations.SortedPairs }}
{{ if eq .Name "description" }}> 告警详情: {{ .Value | html }}{{ end }}
{{ end }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
{{"============================"}}
{{ end }}{{ end }}
{{ define "ding.link.title" }}{{ template "__subject" . }}{{ end }}
{{ define "ding.link.content" }}
{{ if gt (len .Alerts.Firing) 0 }}#### [{{ .Alerts.Firing | len }}]【Linux 报警触发】
{{ template "__text_list" .Alerts.Firing }}{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}#### [{{ .Alerts.Resolved | len }}]【Linux 报警恢复】
{{ end }}
{{ end }}
[root@prometheus ~]
[root@prometheus ~]
templates:
- /usr/local/Prometheus_webhook-dingtalk/template/*.tmpl
targets:
webhook:
url: https://oapi.dingtalk.com/robot/send?access_token=xxx
message:
title: '{{ template "ding.link.title" . }}'
text: '{{ template "ding.link.content" . }}'
[root@prometheus ~]# nohup /usr/local/Prometheus_webhook-dingtalk/prometheus-webhook-dingtalk
- 修改alertmanager.yml配置(添加接收者receivers)
[root@prometheus ~]
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.163.com:25'
smtp_from: 'xxx@163.com'
smtp_auth_username: 'xxx@163.com'
smtp_auth_password: 'xxxxx'
smtp_require_tls: false
templates:
- '/usr/local/Prometheus/alertmanager/template/*.tmpl'
route:
group_by: ["alertname"]
group_wait: 30s
group_interval: 30s
repeat_interval: 20m
receiver: Node_warning
receivers:
- name: 'Node_warning'
email_configs:
- to: 'xxx@126.com'
webhook_configs:
- url: http://127.0.0.1:8060/dingtalk/ops_dingding/send
send_resolved: true
[root@prometheus ~]# systemctl restart alertmanager