我正在尝试将Alertmananger警报发送到Slack,并且使用我自定义的模板成功做到了。
但是现在我想将警报发送到不同的频道,从而从配置文件中选择不同的Webhook,但我无法这样做并得到
component=configuration msg="Loading configuration file failed" file=/etc/alertmanager/config/alertmanager.yaml err="unsupported scheme \"\" for URL"
我正在从模板文件中选择Webhook,而问题主要在于加载变量“ slack.myorg.webhook”]
Alertmanager.yaml
global:
resolve_timeout: 5m
slack_api_url: '{{ template "slack.myorg.webhook" . }}'
route:
group_by: ['alertname']
...
...
...
templates: ['/etc/alertmanager/config/*.tmpl']
slack-myorg-template.tmpl
我将添加我的逻辑以选择某些标签上的webhook,直到现在才通过模板加载
# To identify from which cluster the alerts are comming
{{ define "slack.myorg.username" }}Minikube{{ end }}
# select webhook
{{ define "slack.myorg.webhook" }}https://hooks.slack.com/services/XXX/XX/XX{{ end }}
唯一的问题是slack.myorg.webhook无法通过调用'{{模板“ slack.myorg.webhook”完美地加载到slack_api_url中。 }}'。
我尝试过的其他事情
[slack_api_url
(以及slack_config中的api_url
)不支持模板。
https://github.com/prometheus/alertmanager/issues/2207#event-3127085200