You can customize alarm templates
- Creating a template File
[root@prometheus ~]# mkdir -p /usr/local/Prometheus_alertmanager/template [root@prometheus ~]# vim /usr/local/Prometheus_alertmanager/template/email.tmpl {{ define "email.html" }} {{ range .Alerts }} <pre> = = = = = = = = start = = = = = = = = = = alarm procedures: prometheus_alert alarm levels: {{. Labels. The severity}} the alarm types: {{. Labels. Alertname}} fault host: {{.identifiers. Instance}} Alarm subject: {{.identifiers. Summary}} Alarm details: {{.Identifiers. {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }} ========end========== </pre> {{ end }} {{ end }}Copy the code
Format “2006-01-02 15:04:05” must not be filled in, the time defined here is the birth time of go language!! If you fill in the wrong time, it will be garbled.
- Example Modify alertManager. yml configurations
root@prometheus ~]# vim /usr/local/Prometheus_alertmanager/alertmanager.yml global: resolve_timeout: 5m smtp_smarthost: 'smtp.163.com:25' # SMTP address smtp_from: '[email protected]' # who sent the email smtp_auth_username: '[email protected]' # email user smtp_auth_password: 'XXXXX' # email client authorization password smtp_require_TLS: false templates: # to specify the path of the mail template, you can use the relative path to the template / *. TMPL way - '/ usr/local/Prometheus/alertmanager/template / *. TMPL' route: Group_by: [" alertName "] # group_wait: 30s Repeat_interval: 30s # repeat_interval: 30s # receiver: Node_warning # Set default receiver, if you want to receive in groups, remove the following comment # routes: # -receiver: 'Node_warning' # continue: true # group_wait: 10s # match_re: # service: Mysql | Cassandra all service = # mysql or service = Cassandra alarm receiving end # assigned to the database - receiver: 'MySQL_warning # group_wait: 10s # match_re: # Fping -Receiver group # serverity: Warning Receivers: # 'Node_warning' email_configs: - send_resolved: true to: '[email protected]' html: '{{template "email.html".}}' # specifies the template to be used. If this is not specified, the default template headers: {Subject: "[WARN]CPU alarm "} # configure the email SubjectCopy the code
- Restart the alertmanager
[root@prometheus ~]# systemctl restart alertmanager
Copy the code
- Reload the Prometheus configuration
[root@prometheus Prometheus]# curl -XPOST http://localhost:9090/-/reload
Copy the code