如下是警报和相应的Alertmanager配置文件设置(alertmanager.yml)的全部不一样示例。 每一个都使用Go模板系统。git
在这个例子中,咱们定制了Slack通知,以便向咱们组织的wiki发送一个URL,告知如何处理已发送的特定警报。github
global:
slack_api_url: '<slack_webhook_url>'
route:
receiver: 'slack-notifications'
group_by: [alertname, datacenter, app]
receivers:
- name: 'slack-notifications'
slack_configs:
- channel: '#alerts'
text: 'https://internal.myorg.net/wiki/alerts/{{ .GroupLabels.app }}/{{ .GroupLabels.alertname }}'
复制代码
在这个例子中,咱们再次定制发送给Slack接收器的文本,访问存储在Alertmanager发送的数据的CommonAnnotations
中的摘要和描述。web
警报api
groups:
- name: Instances
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
# Prometheus templates apply here in the annotation and label fields of the alert.
annotations:
description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
summary: 'Instance {{ $labels.instance }} down'
复制代码
接收器bash
- name: 'team-x'
slack_configs:
- channel: '#alerts'
# Alertmanager templates apply here.
text: "<!channel> \nsummary: {{ .CommonAnnotations.summary }}\ndescription: {{ .CommonAnnotations.description }}"
复制代码
最后,假设与前一个示例相同的警报,咱们定制咱们的接收器以覆盖从Alertmanager接收的全部警报,在新线路上打印它们各自的注释摘要和描述。app
接收器url
- name: 'default-receiver'
slack_configs:
- channel: '#alerts'
title: "{{ range .Alerts }}{{ .Annotations.summary }}\n{{ end }}"
text: "{{ range .Alerts }}{{ .Annotations.description }}\n{{ end }}"
复制代码
回到咱们的第一个例子,咱们还能够提供一个包含命名模板的文件,而后由Alertmanager加载,以免跨越多行的复杂模板。 在/alertmanager/template/myorg.tmpl
下建立一个文件,并在其中建立一个名为“slack.myorg.txt”的模板:spa
{{ define "slack.myorg.text" }}https://internal.myorg.net/wiki/alerts/{{ .GroupLabels.app }}/{{ .GroupLabels.alertname }}{{ end}}
复制代码
配置如今加载具备“text”字段的给定名称的模板,并提供自定义模板文件的路径:.net
global:
slack_api_url: '<slack_webhook_url>'
route:
receiver: 'slack-notifications'
group_by: [alertname, datacenter, app]
receivers:
- name: 'slack-notifications'
slack_configs:
- channel: '#alerts'
text: '{{ template "slack.myorg.text" . }}'
templates:
- '/etc/alertmanager/templates/myorg.tmpl'
复制代码
此博客文章中进一步详细说明了此示例。code
Prometheus官网地址:prometheus.io/ 个人Github:github.com/Alrights/pr…