forked from Altinity/clickhouse-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus-alertmanager-template.yaml
128 lines (121 loc) · 3.17 KB
/
prometheus-alertmanager-template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
# Setup AlterManager Configuration with Slack Integration
apiVersion: v1
kind: Secret
metadata:
name: alertmanager-alertmanager
type: Opaque
stringData:
notifications.tmpl: |-
{{ define "__subject" }}
[{{ if eq .Status "firing" }}FIRE:{{len .Alerts.Firing}}{{ else }}OK{{ end }}] {{.GroupLabels.alertname}}
{{ end }}
{{ define "slack_message" }}
{{ range .Alerts.Firing -}}
{{- range .Annotations.SortedPairs }}
*{{ .Name }}*: {{ .Value }}
{{- end }}
{{ range .Labels.SortedPairs -}}
{{- if and (ne .Name "alertname") (ne .Name "severity") (ne .Name "tenant") }}
{{ .Name}} = `{{.Value}}`
{{- end }}
{{- end }}
---
{{ end }}
{{ range .Alerts.Resolved -}}
{{- range .Annotations.SortedPairs }}
{{- if (ne .Name "description") }}
*{{ .Name }}*: {{ .Value }}
{{- end }}
{{- end }}
{{- range .Labels.SortedPairs }}
{{- if and (ne .Name "alertname") (ne .Name "severity") (ne .Name "tenant") }}
{{ .Name }} = `{{ .Value }}`
{{- end }}
{{- end }}
---
{{ end }}
{{ 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 }}
alertmanager.yaml: |-
global:
resolve_timeout: 1m
templates:
- /etc/alertmanager/config/notifications.tmpl
route:
group_by: ['...']
group_wait: 0s
group_interval: 1s
repeat_interval: 6h
receiver: "slack"
receivers:
- name: "slack"
slack_configs:
- api_url: "${SLACK_WEBHOOK_URL}"
channel: "${SLACK_CHANNEL}"
text: '{{ template "slack_message" . }}'
color: '{{ template "slack_color" . }}'
send_resolved: true
---
# Setup AlertManager
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
name: alertmanager
labels:
alertmanager: alertmanager
spec:
replicas: 1
serviceAccountName: prometheus
externalUrl: ${ALERT_MANAGER_EXTERNAL_URL}
---
# Setup ClusterIP Service
# Service would be created in kubectl-specified namespace
# In order to get access outside of k8s it should be exposed as:
# kubectl --namespace ${PROMETHEUS_NAMESPACE} port-forward service/alertmanager 9093
# and point browser to http://localhost:9093
apiVersion: v1
kind: Service
metadata:
name: alertmanager
labels:
alertmanager: alertmanager
spec:
type: ClusterIP
ports:
- name: web
port: 9093
protocol: TCP
targetPort: web
selector:
alertmanager: alertmanager
---
# Setup AlertManager metrics scraping back to prometheus
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
alertmanager: alertmanager
name: alertmanager
spec:
endpoints:
- interval: 30s
port: web
namespaceSelector:
matchNames:
- ${PROMETHEUS_NAMESPACE}
selector:
matchLabels:
alertmanager: alertmanager