diff --git a/examples/alertmanager-alert-template.tmpl b/examples/alertmanager-alert-template.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..38196daf290ee9b90b2ab3aa26ac54c8d84af2a1 --- /dev/null +++ b/examples/alertmanager-alert-template.tmpl @@ -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 }} + diff --git a/examples/alertmanager-config-template-external.jsonnet b/examples/alertmanager-config-template-external.jsonnet new file mode 100644 index 0000000000000000000000000000000000000000..e32501c33fe361710ed0bc5a3c7cd63466c84ad8 --- /dev/null +++ b/examples/alertmanager-config-template-external.jsonnet @@ -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) } diff --git a/examples/alertmanager-config-with-template.yaml b/examples/alertmanager-config-with-template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b574b6661b9256c405c5c1ba69573d718f9e7558 --- /dev/null +++ b/examples/alertmanager-config-with-template.yaml @@ -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'