在 prometheus alertmanager 通知中提及 slack 用户
mention slack users in prometheus alertmanager notification
所以我有一个通用标签 opsteam
,一旦 alertmanager 被解雇,它应该让 DM 处于松弛状态。但是在 slack 中,我得到的用户名是纯文本,没有突出显示,这些用户没有收到任何消息。
nodeSelector:
prometheus: "true"
enabled: true
retention: "30d"
extraFlags:
- web.enable-lifecycle
- web.enable-admin-api
strategy:
type: RollingUpdate
global:
scrape_interval: 30s
external_labels:
env: prod
client: client
cluster: project-prod-eks
opsteam: "@U0325FRAD @U01GN7KJHU"
如果我将 opsteam: "@U0325FRAD @U01GN7KJHU"
更改为 opsteam: "@john @jim"
,它也没有任何效果。
所以这是我的自定义松弛通知
notifications.tmpl: |
{{ define "__alert_silence_link" -}}
{{ .ExternalURL }}/#/silences/new?filter=%7B
{{- range .CommonLabels.SortedPairs -}}
{{- if ne .Name "alertname" -}}
{{- .Name }}%3D"{{- .Value -}}"%2C%20
{{- end -}}
{{- end -}}
alertname%3D"{{- .CommonLabels.alertname -}}"%7D
{{- end }}
{{ define "__alert_severity" -}}
{{- if eq .CommonLabels.severity "critical" -}}
*Severity:* `Critical` {{ if eq .Status "firing" }}:fire:{{- else -}}:ok:{{- end -}}
{{- else if eq .CommonLabels.severity "warning" -}}
*Severity:* `Warning`
{{- else if eq .CommonLabels.severity "info" -}}
*Severity:* `Info`
{{- else -}}
*Severity:* :question: {{ .CommonLabels.severity }}
{{- end }}
{{- end }}
{{ define "__alert_client_details" -}}
*Env:* {{ .CommonLabels.env }}
*Client:* {{ .CommonLabels.client }}
*Cluster:* {{ .CommonLabels.cluster }}
{{- end }}
{{ define "slack.title" -}}
[{{ .Status | toUpper -}}
{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
] {{ .CommonLabels.cluster }} - {{ .CommonLabels.alertname }}
{{- end }}
{{ define "slack.text" -}}
{{ .CommonLabels.opsteam }} <<-----------------WANT THEM TO BE User Mentions!!!!!
{{ template "__alert_severity" . }}
{{ template "__alert_client_details" . }}
{{- if (index .Alerts 0).Annotations.summary }}
{{- "\n" -}}
*Summary:* {{ (index .Alerts 0).Annotations.summary }}
{{- end }}
{{ range .Alerts }}
{{- if .Annotations.description }}
{{ .Annotations.description }}{{- "\n" -}}
{{- end }}
{{- if .Annotations.message }}
{{ .Annotations.message }}{{- "\n" -}}
{{- end }}
{{- end }}
{{- end }}
{{ define "slack.color" -}}
{{ if eq .Status "firing" -}}
{{ if eq .CommonLabels.severity "warning" -}}
warning
{{- else if eq .CommonLabels.severity "critical" -}}
danger
{{- else -}}
#439FE0
{{- end -}}
{{ else -}}
good
{{- end }}
{{- end }}
是的,我的消息只是 slack 中的文本。
在 Slack 中有一个给定的格式来嵌入用户名。
https://api.slack.com/reference/surfaces/formatting#mentioning-users
<@userId>
所以我有一个通用标签 opsteam
,一旦 alertmanager 被解雇,它应该让 DM 处于松弛状态。但是在 slack 中,我得到的用户名是纯文本,没有突出显示,这些用户没有收到任何消息。
nodeSelector:
prometheus: "true"
enabled: true
retention: "30d"
extraFlags:
- web.enable-lifecycle
- web.enable-admin-api
strategy:
type: RollingUpdate
global:
scrape_interval: 30s
external_labels:
env: prod
client: client
cluster: project-prod-eks
opsteam: "@U0325FRAD @U01GN7KJHU"
如果我将 opsteam: "@U0325FRAD @U01GN7KJHU"
更改为 opsteam: "@john @jim"
,它也没有任何效果。
所以这是我的自定义松弛通知
notifications.tmpl: |
{{ define "__alert_silence_link" -}}
{{ .ExternalURL }}/#/silences/new?filter=%7B
{{- range .CommonLabels.SortedPairs -}}
{{- if ne .Name "alertname" -}}
{{- .Name }}%3D"{{- .Value -}}"%2C%20
{{- end -}}
{{- end -}}
alertname%3D"{{- .CommonLabels.alertname -}}"%7D
{{- end }}
{{ define "__alert_severity" -}}
{{- if eq .CommonLabels.severity "critical" -}}
*Severity:* `Critical` {{ if eq .Status "firing" }}:fire:{{- else -}}:ok:{{- end -}}
{{- else if eq .CommonLabels.severity "warning" -}}
*Severity:* `Warning`
{{- else if eq .CommonLabels.severity "info" -}}
*Severity:* `Info`
{{- else -}}
*Severity:* :question: {{ .CommonLabels.severity }}
{{- end }}
{{- end }}
{{ define "__alert_client_details" -}}
*Env:* {{ .CommonLabels.env }}
*Client:* {{ .CommonLabels.client }}
*Cluster:* {{ .CommonLabels.cluster }}
{{- end }}
{{ define "slack.title" -}}
[{{ .Status | toUpper -}}
{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
] {{ .CommonLabels.cluster }} - {{ .CommonLabels.alertname }}
{{- end }}
{{ define "slack.text" -}}
{{ .CommonLabels.opsteam }} <<-----------------WANT THEM TO BE User Mentions!!!!!
{{ template "__alert_severity" . }}
{{ template "__alert_client_details" . }}
{{- if (index .Alerts 0).Annotations.summary }}
{{- "\n" -}}
*Summary:* {{ (index .Alerts 0).Annotations.summary }}
{{- end }}
{{ range .Alerts }}
{{- if .Annotations.description }}
{{ .Annotations.description }}{{- "\n" -}}
{{- end }}
{{- if .Annotations.message }}
{{ .Annotations.message }}{{- "\n" -}}
{{- end }}
{{- end }}
{{- end }}
{{ define "slack.color" -}}
{{ if eq .Status "firing" -}}
{{ if eq .CommonLabels.severity "warning" -}}
warning
{{- else if eq .CommonLabels.severity "critical" -}}
danger
{{- else -}}
#439FE0
{{- end -}}
{{ else -}}
good
{{- end }}
{{- end }}
是的,我的消息只是 slack 中的文本。
在 Slack 中有一个给定的格式来嵌入用户名。
https://api.slack.com/reference/surfaces/formatting#mentioning-users
<@userId>