Skip to content
Snippets Groups Projects
Unverified Commit ddfbed0d authored by Paweł Krupa's avatar Paweł Krupa Committed by GitHub
Browse files

Merge pull request #813 from Blizter/example/alertmanager-custom-config

parents 3c8103b3 00ab4812
No related branches found
No related tags found
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',
metadata: {
name: name,
namespace: namespace,
},
data: data,
};
local kp =
// different libsonnet imported
{
values+:: {
common+: {
namespace: 'monitoring',
},
},
alertmanager+:: {
alertmanager+: {
spec+: {
// the important field configmaps:
configMaps: ['alert-templates'], // goes to etc/alermanager/configmaps
},
},
},
configmap+:: {
'alert-templates': configmap(
'alertmanager-alert-template.tmpl',
$.values.common.namespace, // could be $._config.namespace to assign namespace once
{ data: importstr 'alertmanager-alert-template.tmpl' },
),
},
};
{ [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'
local ingress(name, namespace, rules) = {
apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress',
metadata: {
name: name,
namespace: namespace,
annotations: {
'nginx.ingress.kubernetes.io/auth-type': 'basic',
'nginx.ingress.kubernetes.io/auth-secret': 'basic-auth',
'nginx.ingress.kubernetes.io/auth-realm': 'Authentication Required',
},
},
spec: { rules: rules },
};
local kp =
(import 'kube-prometheus/main.libsonnet') +
{
_config+:: {
namespace: 'monitoring',
grafana+:: {
config+: {
sections+: {
server+: {
root_url: 'http://grafana.example.com/',
},
},
},
},
},
// Configure External URL's per application
alertmanager+:: {
alertmanager+: {
spec+: {
externalUrl: 'http://alertmanager.example.com',
},
},
},
prometheus+:: {
prometheus+: {
spec+: {
externalUrl: 'http://prometheus.example.com',
},
},
},
// Create one ingress object that routes to each individual application
ingress+:: {
'kube-prometheus': ingress(
'kube-prometheus',
$._config.namespace,
[
{
host: 'alertmanager.example.com',
http: {
paths: [{
backend: {
service: {
name: 'alertmanager-main',
port: 'web',
},
},
}],
},
},
{
host: 'grafana.example.com',
http: {
paths: [{
backend: {
service: {
name: 'grafana',
port: 'http',
},
},
}],
},
},
{
host: 'alertmanager.example.com',
http: {
paths: [{
backend: {
service: {
name: 'prometheus-k8s',
port: 'web',
},
},
}],
},
},
]
),
},
} + {
// Create basic auth secret - replace 'auth' file with your own
ingress+:: {
'basic-auth-secret': {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name: 'basic-auth',
namespace: $._config.namespace,
},
data: { auth: std.base64(importstr 'auth') },
type: 'Opaque',
},
},
};
{ [name + '-ingress']: kp.ingress[name] for name in std.objectFields(kp.ingress) }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment