Skip to content

Commit

Permalink
Try out nicer message template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Sep 21, 2023
1 parent 7a3415d commit d0ebc7f
Showing 1 changed file with 92 additions and 9 deletions.
101 changes: 92 additions & 9 deletions control-plane/roles/monitoring/templates/prometheus-stack-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,102 @@ alertmanager:
repeat_interval: 1h
slack_configs:
- channel: "{{ monitoring_slack_notification_channel }}"
send_resolved: true
color: '{{ template "slack.color" . }}'
title: '{{ template "slack.title" . }}'
text: '{{ template "slack.text" . }}'
{% if monitoring_slack_notification_icon_url is defined %}
icon_url: "{{ monitoring_slack_notification_icon_url }}"
{% endif %}
{% if monitoring_slack_notification_title is defined %}
title: "{{ monitoring_slack_notification_title | string }}"
{% endif %}
{% if monitoring_slack_notification_text is defined %}
text: "{{ monitoring_slack_notification_text | string }}"
{% endif %}
send_resolved: true
actions:
- type: button
text: 'Runbook :green_book:'
url: '{{ (index .Alerts 0).Annotations.runbook_url }}'
- type: button
text: 'Query :mag:'
url: '{{ (index .Alerts 0).GeneratorURL }}'
- type: button
text: 'Dashboard :chart_with_upwards_trend:'
url: '{{ (index .Alerts 0).Annotations.dashboard_url }}'
- type: button
text: 'Silence :no_bell:'
url: '{{ template "__alert_silence_link" . }}'
{% endif %}
templates:
- '/etc/alertmanager/config/*.tmpl'

templateFiles:
slack.tmpl: |-
{{/* taken from https://hodovi.cc/blog/creating-awesome-alertmanager-templates-for-slack/ */}}
{{/* Alertmanager Silence link */}}
{{ 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 }}
{{/* Severity of the alert */}}
{{ define "__alert_severity" -}}
{{- if eq .CommonLabels.severity "critical" -}}
*Severity:* `Critical`
{{- else if eq .CommonLabels.severity "warning" -}}
*Severity:* `Warning`
{{- else if eq .CommonLabels.severity "info" -}}
*Severity:* `Info`
{{- else -}}
*Severity:* :question: {{ .CommonLabels.severity }}
{{- end }}
{{- end }}
{{/* Title of the Slack alert */}}
{{ define "slack.title" -}}
[{{ .Status | toUpper -}}
{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
] {{ .CommonLabels.alertname }}
{{- end }}
{{/* Color of Slack attachment (appears as line next to alert )*/}}
{{ 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 }}
{{/* The text to display in the alert */}}
{{ define "slack.text" -}}
{{ template "__alert_severity" . }}
{{- if (index .Alerts 0).Annotations.summary }}
{{- "\n" -}}
*Summary:* {{ (index .Alerts 0).Annotations.summary }}
{{- end }}
{{ range .Alerts }}
{{- if .Annotations.description }}
{{- "\n" -}}
{{ .Annotations.description }}
{{- "\n" -}}
{{- end }}
{{- if .Annotations.message }}
{{- "\n" -}}
{{ .Annotations.message }}
{{- "\n" -}}
{{- end }}
{{- end }}
{{- end }}
coreDns:
enabled: false
Expand Down

0 comments on commit d0ebc7f

Please sign in to comment.