Skip to content
Snippets Groups Projects
Commit a0182069 authored by Blizter's avatar Blizter
Browse files

example external custom alertmanager template

parent 8b3fb3e2
Branches
Tags
No related merge requests found
# to know more about custom template language read alertmanager documentation
# inspired by : https://gist.github.com/milesbxf/e2744fc90e9c41b47aa47925f8ff6512
{{ define "slack.title" -}}
[{{ .Status | toUpper -}}
{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{- end -}}
] {{ template "__alert_severity_prefix_title" . }} {{ .CommonLabels.alertname }}
{{- end }}
{{ 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 }}
{{ define "slack.icon_emoji" }}:prometheus:{{ end }}
{{/* The test to display in the alert */}}
{{ define "slack.text" -}}
{{ range .Alerts }}
{{- if .Annotations.message }}
{{ .Annotations.message }}
{{- end }}
{{- if .Annotations.description }}
{{ .Annotations.description }}
{{- end }}
{{- end }}
{{- end }}
local configmap(name, namespace, data) = {
apiVersion: "v1",
kind: "ConfigMap",
metadate : {
name: name,
namespace: namespace,
},
data: data,
};
local kp =
// different libsonnet imported
{
configmap+:: {
'alert-templates': configmap(
'alertmanager-alert-template.tmpl',
$._config.namespace,
{"data": importstr 'alertmanager-alert-template.tmpl'},
)
},
alertmanager+:{
spec+:{
# the important field configmaps:
configMaps: ['alert-templates',], # goes to etc/alermanager/configmaps
},
},
};
{ [name + '-configmap']: kp.configmap[name] for name in std.objectFields(kp.configmap) }
# external alertmanager yaml
global:
resolve_timeout: 10m
slack_api_url: url
route:
group_by: ['job']
group_wait: 30s
group_interval: 5m
repeat_interval: 12h
receiver: 'null'
routes:
- match:
alertname: Watchdog
receiver: 'null'
receivers:
- name: 'null'
- name: slack
slack_configs:
- channel: '#alertmanager-testing'
send_resolved: true
title: '{{ template "slack.title" . }}'
icon_emoji: '{{ template "slack.icon_emoji" . }}'
color: '{{ template "slack.color" . }}'
text: '{{ template "slack.text" . }}
templates:
- '/etc/alertmanager/configmaps/alertmanager-alert-template.tmpl'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment