mirror of
https://github.com/prometheus-operator/kube-prometheus.git
synced 2025-11-01 16:41:02 +01:00
example external custom alertmanager template
This commit is contained in:
parent
8b3fb3e2c5
commit
a01820692c
37
examples/alertmanager-alert-template.tmpl
Normal file
37
examples/alertmanager-alert-template.tmpl
Normal 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 }}
|
||||
|
||||
28
examples/alertmanager-config-template-external.jsonnet
Normal file
28
examples/alertmanager-config-template-external.jsonnet
Normal 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) }
|
||||
27
examples/alertmanager-config-with-template.yaml
Normal file
27
examples/alertmanager-config-with-template.yaml
Normal 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'
|
||||
Loading…
x
Reference in New Issue
Block a user