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..73b3ee4fd7cf521522b76aea16cd7a0a4decc4f5 --- /dev/null +++ b/examples/alertmanager-config-template-external.jsonnet @@ -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) } 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' diff --git a/examples/ingress-one-to-many.jsonnet b/examples/ingress-one-to-many.jsonnet new file mode 100644 index 0000000000000000000000000000000000000000..ee56090fa64a6e74b5d05a3ed36867529a40707d --- /dev/null +++ b/examples/ingress-one-to-many.jsonnet @@ -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) }