Last active
October 8, 2024 21:59
-
-
Save tanmay-bhat/258653893723aed3e8b4e50bc744ee8c to your computer and use it in GitHub Desktop.
Grafana alert template to display message (alert) in slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ define "alert_severity_prefix_emoji" -}} | |
{{- if ne .Status "firing" -}} | |
:white_check_mark: | |
{{- else if eq .CommonLabels.severity "critical" -}} | |
:red_circle: | |
{{- else if eq .CommonLabels.severity "warning" -}} | |
:warning: | |
{{- end -}} | |
{{- end -}} | |
{{ define "slack.title" -}} | |
{{ template "alert_severity_prefix_emoji" . }} | |
[{{- .Status | toUpper -}}{{- if eq .Status "firing" }} x {{ .Alerts.Firing | len -}}{{- end }} | {{ .CommonLabels.env | toUpper -}} ] || {{ .CommonLabels.alertname -}} | |
{{- end -}} | |
{{- define "slack.text" -}} | |
{{- range .Alerts -}} | |
{{ if gt (len .Annotations) 0 }} | |
*Summary*: {{ .Annotations.summary}} | |
*Description*: {{ .Annotations.description }} | |
Labels: | |
{{ range .Labels.SortedPairs }}{{ if or (eq .Name "env") (eq .Name "instance") }}• {{ .Name }}: `{{ .Value }}` | |
{{ end }}{{ end }} | |
{{ end }} | |
{{ end }} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment