Skip to content

Instantly share code, notes, and snippets.

@mkopinsky
Created September 15, 2021 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkopinsky/9b982ba432b780c525ff3e65a78a5dac to your computer and use it in GitHub Desktop.
Save mkopinsky/9b982ba432b780c525ff3e65a78a5dac to your computer and use it in GitHub Desktop.
Slack template
{{ define "alert" }}
{{ if eq .Status "firing" }}:fire: {{ else }}:white_check_mark: {{ end -}}
*{{ .Labels.alertname }}* {{ if .Annotations.summary }} ({{ .Annotations.summary }}){{ end }}
{{- if eq .Status "firing" }}
> ```{{ .ValueString}}```
{{- end -}}
{{- if gt (len .Labels) 1 }}
> {{ range .Labels.SortedPairs }} *{{ .Name }}:* {{ .Value }} {{ end }}
{{ end }}
{{- if gt (len .Annotations) 0 }}
> {{ range .Annotations.SortedPairs }} *{{ .Name }}:* {{ .Value }} {{ end }}
{{ end -}}
> {{ if gt (len .GeneratorURL ) 0 }}<{{ .GeneratorURL }}|:pencil2: Alert>{{ end }} {{ if gt (len .SilenceURL ) 0 }}<{{ .SilenceURL }}|:no_bell: Silence>{{ end }} {{ if gt (len .DashboardURL ) 0 }}<{{ .DashboardURL }}|:earth_americas: Dashboard>{{ end }} {{ if gt (len .PanelURL ) 0 }}<{{ .PanelURL }}|:bar_chart: Panel>{{ end }}
{{ end }}
{{ define "message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{ len .Alerts.Firing }} firing:
{{- range .Alerts.Firing -}} {{ template "alert" .}} {{- end -}}
{{ end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{ len .Alerts.Resolved }} resolved:
{{- range .Alerts.Resolved -}} {{ template "alert" .}} {{- end -}}
{{ end }}
{{ end }}
@mkopinsky
Copy link
Author

mkopinsky commented Sep 15, 2021

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment