我为 AlertManager 配置了 Slack 通知:
receivers:
- name: "team:slack"
slack_configs:
- channel: "alerts"
icon_emoji: !unsafe '{{ template "slack.my.icon" . }}'
color: !unsafe '{{ template "slack.my.color" . }}'
title: !unsafe '{{ template "slack.my.title" . }}'
title_link: !unsafe '{{ template "slack.my.link" . }}'
text: !unsafe '{{ template "slack.my.text" . }} (notify <!subteam^S04*****>)'
send_resolved: true
api_url: "https://hooks.slack.com/services/***/***/*****"
actions:
- type: button
text: "Runbook :green_book:"
url: !unsafe '{{ template "slack.my.runbook_url" . }}'
- type: button
text: "View :mag:"
url: !unsafe '{{ template "slack.my.alert_source_url" . }}'
- type: button
text: "Dashboard :chart_with_upwards_trend:"
url: !unsafe '{{ template "slack.my.dashboard_url" . }}'
- type: button
text: "Mute :no_bell:"
url: !unsafe '{{ template "__alert_silence_link" . }}'
- type: button
text: "Docs :books:"
url: !unsafe '{{ template "slack.my.doc_url" . }}'
奇怪的是,当在 Slack 移动应用程序中收到通知时 - 我看到所有 5 个按钮,但在 Slack 桌面应用程序中时 - 我只看到前 3 个按钮,没有静音和文档按钮。
这是我的越野车按钮自定义模板的一部分:
{{ define "__alert_silence_link" -}}
{{ .ExternalURL }}/#/silences/new?filter=%7B
{{- range .CommonLabels.SortedPairs -}}
{{- if ne .Name "alertname" -}}
{{- .Name }}%3D%22{{- .Value | urlquery -}}%22%2C%20
{{- end -}}
{{- end -}}
alertname%3D%22{{- .CommonLabels.alertname -}}%22%7D
{{- end }}
{{ define "slack.my.doc_url" }}
{{- if ne (index .Alerts 0).Annotations.doc_url "" -}}
{{- (index .Alerts 0).Annotations.doc_url -}}
{{- end -}}
{{- end }}
有什么办法可以解决吗?
您可以尝试为每个按钮添加名称属性