Merge pull request #813 from Blizter/example/alertmanager-custom-config
This commit is contained in:
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 }}
|
||||
|
||||
35
examples/alertmanager-config-template-external.jsonnet
Normal file
35
examples/alertmanager-config-template-external.jsonnet
Normal file
@@ -0,0 +1,35 @@
|
||||
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) }
|
||||
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'
|
||||
111
examples/ingress-one-to-many.jsonnet
Normal file
111
examples/ingress-one-to-many.jsonnet
Normal file
@@ -0,0 +1,111 @@
|
||||
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) }
|
||||
Reference in New Issue
Block a user