Skip to content

Instantly share code, notes, and snippets.

@aditya-konarde
Created April 2, 2019 08:21
Show Gist options
  • Save aditya-konarde/c985c0528fffd0bf9188fa9afab19351 to your computer and use it in GitHub Desktop.
Save aditya-konarde/c985c0528fffd0bf9188fa9afab19351 to your computer and use it in GitHub Desktop.
# This builds the silence URL. We exclude the alertname in the range
# to avoid the issue of having trailing comma separator (%2C) at the end
# of the generated URL
{{ 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_prefix" -}}
{{ if ne .Status "firing" -}}
:green_apple:
{{- else if eq .Labels.severity "critical" -}}
:fire:
{{- else if eq .Labels.severity "warning" -}}
:warning:
{{- else if eq .Labels.severity "medium" -}}
:warning:
{{- else if eq .Labels.severity "test" -}}
:grey_exclamation:
{{- else -}}
:question:
{{- end }}
{{- end }}
{{ define "__alert_severity_prefix_title" -}}
{{ if ne .Status "firing" -}}
:green_apple:
{{- else if eq .Labels.severity "critical" -}}
:fire:
{{- else if eq .Labels.severity "warning" -}}
:warning:
{{- else if eq .Labels.severity "medium" -}}
:warning:
{{- else if eq .Labels.severity "test" -}}
:grey_exclamation:
{{- else -}}
:question:
{{- end }}
{{- end }}
{{/* First line of Slack alerts */}}
{{ define "slack.default.title" -}}
Alert: {{ .CommonLabels.alertname }}
{{- end }}
{{/* Color of Slack attachment (appears as line next to alert )*/}}
{{ define "slack.default.color" -}}
{{ if eq .Status "firing" -}}
{{ if eq .CommonLabels.severity "test" -}}
'#808080'
{{ else if eq .CommonLabels.severity "warning" -}}
warning
{{ else if eq .CommonLabels.severity "medium" -}}
warning
{{- else if eq .CommonLabels.severity "critical" -}}
danger
{{- else -}}
'#439FE0'
{{- end -}}
{{ else -}}
good
{{- end }}
{{- end }}
{{/* Emoji to display as user icon (custom emoji supported!) */}}
{{ define "slack.default.icon_emoji" }}:prometheus:{{ end }}
{{ define "slack.default.icon_url" }}https://avatars3.githubusercontent.com/u/3380462{{ end }}
{{/* The text to display in the alert */}}
{{ define "slack.default.text" -}}
{{ range .Alerts }}
{{ if eq .Status "firing" -}}
{{- if .Annotations.message }}- {{ .Annotations.message }}{{- end }}{{- if .Annotations.description }}{{ .Annotations.description }}{{- end }}
{{- end }}
{{ if eq .Status "resolved" -}}
{{- if .Annotations.message }}Resolved: {{ .Annotations.message }}{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- /* If none of the below matches, send to #sd-app-sre-alert-test, and we
can then assign the expected code_owner to the alert or map the code_owner
to the correct channel */ -}}
{{ define "__get_channel_for_code_owner" -}}
{{- if eq . "app-sre" -}}
sd-app-sre-alert
{{- else if eq . "telemeter" -}}
forum-monitoring
{{- else -}}
sd-app-sre-alert-test
{{- end -}}
{{- end }}
{{- /* Select the channel based on the code_owner. We only expect to get
into this template function if the code_owners label is present on an alert.
This is to defend against us accidentally breaking the routing logic. */ -}}
{{ define "slack.default.code_owner_channel" -}}
{{- if .CommonLabels.code_owner }}
{{ template "__get_channel_for_code_owner" .CommonLabels.code_owner }}
{{- else -}}
monitoring
{{- end }}
{{- end }}
{{ define "slack.default.link_button_text" -}}
{{- if .CommonAnnotations.link_text -}}
{{- .CommonAnnotations.link_text -}}
{{- else -}}
Link
{{- end }} :link:
{{- end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment