【发布时间】:2020-01-30 13:51:52
【问题描述】:
我想根据警报向 slack 发送解决通知。因此,我为每个警报创建了一个注释(“resolve”),它应该定义是否应该发送已解决的通知。
这是我的警报的外观:
- alert: JobsFailing
expr: rate(failed_jobs_submitter{job="my_job"}[10m]) > 0
for: 5m
labels:
severity: slack_critical
service: my_service
annotations:
identifier: 'my_service_jobs_failing'
description: 'Jobs are failing'
resolve: true
这是我的 alertmanager.yaml:
global:
resolve_timeout: 5m
slack_api_url: 'https://hooks.slack.com/services/...'
http_config:
proxy_url: 'some_proxy'
templates:
- /etc/config/notifications.tpl
route:
receiver: 'default-receiver'
group_wait: 5s
group_interval: 1m
repeat_interval: 6h
routes:
- receiver: slack_critical
match:
severity: slack_critical
receivers:
- name: default-receiver
- name: slack_critical
slack_configs:
- channel: '#alert_channel'
username: "Alert"
icon_emoji: ":monkey:"
send_resolved: {{ .Annotations.resolve }}
title: '{{ template "custom_title" . }}'
text: '{{ template "custom_slack_message" . }}'
我尝试对 .Annotations.resolve 使用字符串而不是布尔值
我尝试使用模板:
{{ define resolve_alert }}{{ if eq .Annotations.resolve "true"}}{{ else }}{{ if eq .Annotations.resolve "false" }}{{ end }}
和
send_resolved: {{ template resolve_alert . }}
我尝试了 if 子句:
{{ if eq .Annotations.resolve true }}send_resolved: true{{else}}send_resolved: false{{end}}
send_resolved: {{ if or .Annotations.resolve | default false }}
我希望 slack 配置能够获取值 .Annotations.resolve 并根据警报中定义的值向 slack 发送已解决的消息。使用 .Annotations.resolve 时得到的结果:
level=error ts=2019-10-01T09:08:12.284Z caller=coordinator.go:124 component=configuration msg="Loading configuration file failed" file=/etc/config/alertmanager.yml err="yaml: unmarshal errors:\n line 28: cannot unmarshal !!map into bool"
使用模板时得到的结果:
level=error ts=2019-09-30T14:39:29.294Z caller=coordinator.go:124 component=configuration msg="Loading configuration file failed" file=/etc/config/alertmanager.yml err="yaml: line 27: did not find expected key"
任何意见都非常感谢...
【问题讨论】:
标签: alert prometheus slack