新版本的 Prometheus 警报管理器增加了对松弛附件中字段部分的支持。我正在尝试设置一个go 模板来循环生成每个警报标签的字段。测试配置后,我收到语法错误“无法读取隐式映射对;缺少冒号”。有没有人尝试过同样的事情并成功了?非常感谢。我的配置如下:
global:
resolve_timeout: 5m
templates:
- '/etc/alertmanager/template/*.tmpl'
route:
# All alerts in a notification have the same value for these labels.
group_by: ['alertname', 'instance', 'pod']
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
receiver: 'slack-test'
routes:
# Go spam channel
- match:
alertname: DeadMansSwitch
receiver: 'null'
- name: 'slack-test'
slack_configs:
- channel: '#alert'
api_url: 'https://hooks.slack.com/services/XXXXX/XXXX/XXXX'
username: 'Prometheus Event Notification'
color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
title: '[`{{ .Labels.severity }}`] Server alert'
text: |-
{{ range .Alerts }}
{{ .Annotations.message }}
{{ end }}
short_fields: true
fields:
{{ range .Labels.SortedPairs }}
title:{{ .Name }}
value:`{{ .Value }}`
{{ end }}
send_resolved: true
#email_configs:
#- to: 'your_alert_email_address'
# send_resolved: true
- name: 'null'
试过这个也不行。
fields:
{{ range .Labels.SortedPairs }}
- title: {{ .Name }}
value: `{{ .Value }}`
{{ end }}