example external custom alertmanager template

This commit is contained in:
Blizter 2020-11-26 12:54:35 -05:00
parent 8b3fb3e2c5
commit a01820692c
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# 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 }}

View File

@ -0,0 +1,28 @@
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) }

View File

@ -0,0 +1,27 @@
# 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'