forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification_template.go
189 lines (171 loc) · 6.94 KB
/
notification_template.go
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package deployer
const (
NotificationTmpl = `
{{- define "rancher.title" -}}
{{- if eq .CommonLabels.alert_type "event" }}
{{ .CommonLabels.event_type}} event of {{.GroupLabels.resource_kind}} occurred
{{- else if eq .CommonLabels.alert_type "systemService" }}
The system component {{ .GroupLabels.component_name}} is not running
{{- else if eq .CommonLabels.alert_type "nodeHealthy" }}
The kubelet on the node {{ .GroupLabels.node_name}} is not healthy
{{- else if eq .CommonLabels.alert_type "nodeCPU" }}
The CPU usage on the node {{ .GroupLabels.node_name}} is over {{ .CommonLabels.cpu_threshold}}%
{{- else if eq .CommonLabels.alert_type "nodeMemory" }}
The memory usage on the node {{ .GroupLabels.node_name}} is over {{ .CommonLabels.mem_threshold}}%
{{- else if eq .CommonLabels.alert_type "podNotScheduled" }}
The Pod {{ if .GroupLabels.namespace}}{{.GroupLabels.namespace}}:{{end}}{{.GroupLabels.pod_name}} is not scheduled
{{- else if eq .CommonLabels.alert_type "podNotRunning" }}
The Pod {{ if .GroupLabels.namespace}}{{.GroupLabels.namespace}}:{{end}}{{.GroupLabels.pod_name}} is not running
{{- else if eq .CommonLabels.alert_type "podRestarts" }}
The Pod {{ if .GroupLabels.namespace}}{{.GroupLabels.namespace}}:{{end}}{{.GroupLabels.pod_name}} restarts {{ .CommonLabels.restart_times}} times in {{ .CommonLabels.restart_interval}} sec
{{- else if eq .CommonLabels.alert_type "workload" }}
The workload {{ if .GroupLabels.workload_namespace}}{{.GroupLabels.workload_namespace}}:{{end}}{{.GroupLabels.workload_name}} has available replicas less than {{ .CommonLabels.available_percentage}}%
{{- else if eq .CommonLabels.alert_type "metric" }}
The metric {{ .CommonLabels.alert_name}} crossed the threshold
{{ end -}}
{{ end -}}
{{- define "wechat.text" -}}
{{ template "__wechat_text_list" . }}
{{ end -}}
{{- define "__wechat_text_list" -}}
{{ template "rancher.title" . }}
{{ template "__text_list" . }}
{{ end -}}
{{- define "slack.text" -}}
{{ template "__text_list" . }}
{{ end -}}
{{- define "__text_list" -}}
{{ range .Alerts.Firing }}
{{ template "__text_single" . }}
{{ end -}}
{{ end -}}
{{- define "__text_single" -}}
Alert Name: {{ .Labels.alert_name}}
Severity: {{ .Labels.severity}}
Cluster Name: {{.Labels.cluster_name}}
{{- if eq .Labels.alert_type "event" }}
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}
{{end -}}
Target: {{ if .Labels.target_namespace -}}{{.Labels.target_namespace}}:{{ end -}}{{.Labels.target_name}}
Count: {{ .Labels.event_count}}
Event Message: {{ .Labels.event_message}}
First Seen: {{ .Labels.event_firstseen}}
Last Seen: {{ .Labels.event_lastseen}}
{{- else if eq .Labels.alert_type "nodeCPU" }}
Used CPU: {{ .Labels.used_cpu}} m
Total CPU: {{ .Labels.total_cpu}} m
{{- else if eq .Labels.alert_type "nodeMemory" }}
Used Memory: {{ .Labels.used_mem}}
Total Memory: {{ .Labels.total_mem}}
{{- else if eq .Labels.alert_type "podRestarts" }}
Project Name: {{ .Labels.project_name}}
Namespace: {{ .Labels.namespace}}
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}
{{ end -}}
Container Name: {{ .Labels.container_name}}
{{- else if eq .Labels.alert_type "podNotRunning" }}
Project Name: {{ .Labels.project_name}}
Namespace: {{ .Labels.namespace}}
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}
{{ end -}}
Container Name: {{ .Labels.container_name}}
{{- else if eq .Labels.alert_type "podNotScheduled" }}
Project Name: {{ .Labels.project_name}}
Namespace: {{ .Labels.namespace}}
Pod Name: {{ .Labels.pod_name}}
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}
{{ end -}}
{{- else if eq .Labels.alert_type "workload" }}
Project Name: {{ .Labels.project_name}}
Available Replicas: {{ .Labels.available_replicas}}
Desired Replicas: {{ .Labels.desired_replicas}}
{{- else if eq .Labels.alert_type "metric" }}
{{- if .Labels.namespace }}
Namespace: {{ .Labels.namespace}}{{ end }}
{{- if .Labels.project_name }}
Project Name: {{ .Labels.project_name}}{{ end }}
{{- if .Labels.pod_name }}
Pod Name: {{ .Labels.pod_name}}{{ else if .Labels.pod -}}Pod Name: {{ .Labels.pod}}{{ end }}
Expression: {{ .Labels.expression}}
Description: Threshold Crossed: datapoint value {{ .Annotations.current_value}} was {{ .Labels.comparison}} to the threshold ({{ .Labels.threshold_value}}) for ({{ .Labels.duration}})
{{ end -}}
{{- if .Labels.logs }}
Logs: {{ .Labels.logs}}
{{ end -}}
{{ end -}}
{{- define "email.text" -}}
{{ template "__email_text_list" . }}
{{ end -}}
{{- define "__email_text_list" -}}
{{ range .Alerts.Firing }}
{{ template "__email_text_single" . }}
{{ end -}}
{{ end -}}
{{- define "__email_text_single" -}}
Alert Name: {{ .Labels.alert_name}}<br>
Severity: {{ .Labels.severity}}<br>
Cluster Name: {{.Labels.cluster_name}}<br>
{{- if eq .Labels.alert_type "event" }}
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}<br>
{{ end -}}
Target: {{ if .Labels.target_namespace -}}{{.Labels.target_namespace}}:{{end -}}{{ .Labels.target_name}}<br>
Count: {{ .Labels.event_count}}<br>
Event Message: {{ .Labels.event_message}}<br>
First Seen: {{ .Labels.event_firstseen}}<br>
Last Seen: {{ .Labels.event_lastseen}}<br>
{{- else if eq .Labels.alert_type "nodeCPU" }}
Used CPU: {{ .Labels.used_cpu}} m<br>
Total CPU: {{ .Labels.total_cpu}} m<br>
{{- else if eq .Labels.alert_type "nodeMemory" }}
Used Memory: {{ .Labels.used_mem}}<br>
Total Memory: {{ .Labels.total_mem}}<br>
{{- else if eq .Labels.alert_type "podRestarts" }}
Project Name: {{.Labels.project_name}}<br>
Namespace: {{ .Labels.namespace}}<br>
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}<br>
{{ end -}}
Container Name: {{.Labels.container_name}}<br>
{{- else if eq .Labels.alert_type "podNotRunning" }}
Project Name: {{.Labels.project_name}}<br>
Namespace: {{ .Labels.namespace}}<br>
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}<br>
{{ end -}}
Container Name: {{ .Labels.container_name}}<br>
{{- else if eq .Labels.alert_type "podNotScheduled" }}
Project Name: {{.Labels.project_name}}<br>
Namespace: {{ .Labels.namespace}}<br>
{{- if .Labels.workload_name }}
Workload Name: {{.Labels.workload_name}}<br>
{{ end -}}
Pod Name: {{ .Labels.pod_name}}<br>
{{- else if eq .Labels.alert_type "workload"}}
Project Name: {{.Labels.project_name}}<br>
Available Replicas: {{ .Labels.available_replicas}}<br>
Desired Replicas: {{ .Labels.desired_replicas}}<br>
{{- else if eq .Labels.alert_type "metric" }}
{{- if .Labels.project_name }}
Project Name: {{.Labels.project_name}}<br>
{{ end -}}
{{- if .Labels.pod_name }}
Pod Name: {{.Labels.pod_name}}{{ else if .Labels.pod -}}Pod Name: {{.Labels.pod}}<br>
{{ end -}}
{{- if .Labels.namespace }}
Namespace: {{.Labels.namespace}}<br>
{{ end -}}
Expression: {{.Labels.expression}}<br>
Description: Threshold Crossed: datapoint value {{ .Annotations.current_value}} was {{ .Labels.comparison}} to the threshold ({{ .Labels.threshold_value}}) for ({{ .Labels.duration}})<br>
{{ end -}}
{{- if .Labels.logs }}
Logs: {{ .Labels.logs}}
{{ end -}}
<br>
{{ end -}}
`
)