Skip to content

Commit

Permalink
chore(alertmanager): improve slack templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lconsuegra committed Jul 22, 2024
1 parent 13f0315 commit 2633c21
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,30 @@ locals {

alertmanager_template_files = length(local.alertmanager.slack_routes) > 0 ? {
"slack.tmpl" = <<-EOT
{{ define "slack.title" -}}
[{{ .Status | toUpper }}
{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
] {{ .CommonLabels.alertname }}
{{ end }}
{{ define "slack.text" -}}
{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
{{- if .Annotations.description }}
*Severity:* `{{ .Labels.severity }}`
*Description:* {{ .Annotations.description }}
{{- end }}
*Graph:* <{{ .GeneratorURL }}|:chart_with_upwards_trend:>
*Labels:*
{{ range .Labels.SortedPairs }} - *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{- if .Annotations.runbook_url }}
*Runbook URL:* <{{ .Annotations.runbook_url }}|Click here>
{{- end }}
{{ define "slack.title" -}}
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }}
{{ end }}
{{ define "slack.text" -}}
{{ with index .Alerts 0 -}}
:chart_with_upwards_trend: *<{{ .GeneratorURL }}|Source Graph>*
{{ end }}
{{- range .Alerts -}}
*Severity:* `{{ .Labels.severity }}`
{{- if .Annotations.summary }}
*Alert:* {{ .Annotations.summary }}
{{- end }}
{{- if .Annotations.description }}
*Description:* {{ .Annotations.description }}
{{- end }}
{{- if .Annotations.runbook_url }}
*Runbook URL:* <{{ .Annotations.runbook_url }}|Click here>
{{- end }}
*Labels:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
{{ end }}
EOT
} : {}

Expand Down

0 comments on commit 2633c21

Please sign in to comment.