-
Notifications
You must be signed in to change notification settings - Fork 2
/
alerting_types.go
318 lines (261 loc) · 13.6 KB
/
alerting_types.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package v3
import (
"github.com/rancher/norman/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ClusterAlert struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterAlertSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type ProjectAlert struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ProjectAlertSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type AlertCommonSpec struct {
DisplayName string `json:"displayName,omitempty" norman:"required"`
Description string `json:"description,omitempty"`
Severity string `json:"severity,omitempty" norman:"required,options=info|critical|warning,default=critical"`
Recipients []Recipient `json:"recipients,omitempty" norman:"required"`
InitialWaitSeconds int `json:"initialWaitSeconds,omitempty" norman:"required,default=180,min=0"`
RepeatIntervalSeconds int `json:"repeatIntervalSeconds,omitempty" norman:"required,default=3600,min=0"`
}
type ClusterAlertSpec struct {
AlertCommonSpec
ClusterName string `json:"clusterName" norman:"type=reference[cluster]"`
TargetNode *TargetNode `json:"targetNode,omitempty"`
TargetSystemService *TargetSystemService `json:"targetSystemService,omitempty"`
TargetEvent *TargetEvent `json:"targetEvent,omitempty"`
}
type ProjectAlertSpec struct {
AlertCommonSpec
ProjectName string `json:"projectName" norman:"type=reference[project]"`
TargetWorkload *TargetWorkload `json:"targetWorkload,omitempty"`
TargetPod *TargetPod `json:"targetPod,omitempty"`
}
type Recipient struct {
Recipient string `json:"recipient,omitempty"`
NotifierName string `json:"notifierName,omitempty" norman:"required,type=reference[notifier]"`
NotifierType string `json:"notifierType,omitempty" norman:"required,options=slack|email|pagerduty|webhook|wechat"`
}
type TargetNode struct {
NodeName string `json:"nodeName,omitempty" norman:"type=reference[node]"`
Selector map[string]string `json:"selector,omitempty"`
Condition string `json:"condition,omitempty" norman:"required,options=notready|mem|cpu,default=notready"`
MemThreshold int `json:"memThreshold,omitempty" norman:"min=1,max=100,default=70"`
CPUThreshold int `json:"cpuThreshold,omitempty" norman:"min=1,default=70"`
}
type TargetPod struct {
PodName string `json:"podName,omitempty" norman:"required,type=reference[/v3/projects/schemas/pod]"`
Condition string `json:"condition,omitempty" norman:"required,options=notrunning|notscheduled|restarts,default=notrunning"`
RestartTimes int `json:"restartTimes,omitempty" norman:"min=1,default=3"`
RestartIntervalSeconds int `json:"restartIntervalSeconds,omitempty" norman:"min=1,default=300"`
}
type TargetEvent struct {
EventType string `json:"eventType,omitempty" norman:"required,options=Normal|Warning,default=Warning"`
ResourceKind string `json:"resourceKind,omitempty" norman:"required,options=Pod|Node|Deployment|StatefulSet|DaemonSet"`
}
type TargetWorkload struct {
WorkloadID string `json:"workloadId,omitempty"`
Selector map[string]string `json:"selector,omitempty"`
AvailablePercentage int `json:"availablePercentage,omitempty" norman:"required,min=1,max=100,default=70"`
}
type TargetSystemService struct {
Condition string `json:"condition,omitempty" norman:"required,options=etcd|controller-manager|scheduler,default=scheduler"`
}
type AlertStatus struct {
AlertState string `json:"alertState,omitempty" norman:"options=active|inactive|alerting|muted,default=active"`
}
type ClusterAlertGroup struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterGroupSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type ProjectAlertGroup struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ProjectGroupSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type ClusterGroupSpec struct {
ClusterName string `json:"clusterName" norman:"type=reference[cluster]"`
Recipients []Recipient `json:"recipients,omitempty" norman:"required"`
CommonGroupField
}
type ProjectGroupSpec struct {
ProjectName string `json:"projectName" norman:"type=reference[project]"`
Recipients []Recipient `json:"recipients,omitempty" norman:"required"`
CommonGroupField
}
type ClusterAlertRule struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterAlertRuleSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type ClusterAlertRuleSpec struct {
CommonRuleField
ClusterName string `json:"clusterName" norman:"type=reference[cluster]"`
GroupName string `json:"groupName" norman:"type=reference[clusterAlertGroup]"`
NodeRule *NodeRule `json:"nodeRule,omitempty"`
EventRule *EventRule `json:"eventRule,omitempty"`
SystemServiceRule *SystemServiceRule `json:"systemServiceRule,omitempty"`
MetricRule *MetricRule `json:"metricRule,omitempty"`
}
type ProjectAlertRule struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ProjectAlertRuleSpec `json:"spec"`
// Most recent observed status of the alert. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status AlertStatus `json:"status"`
}
type ProjectAlertRuleSpec struct {
CommonRuleField
ProjectName string `json:"projectName" norman:"type=reference[project]"`
GroupName string `json:"groupName" norman:"type=reference[projectAlertGroup]"`
PodRule *PodRule `json:"podRule,omitempty"`
WorkloadRule *WorkloadRule `json:"workloadRule,omitempty"`
MetricRule *MetricRule `json:"metricRule,omitempty"`
}
type CommonGroupField struct {
DisplayName string `json:"displayName,omitempty" norman:"required"`
Description string `json:"description,omitempty"`
TimingField
}
type CommonRuleField struct {
DisplayName string `json:"displayName,omitempty"`
Severity string `json:"severity,omitempty" norman:"required,options=info|critical|warning,default=critical"`
Inherited *bool `json:"inherited,omitempty" norman:"default=true"`
TimingField
}
type MetricRule struct {
Expression string `json:"expression,omitempty" norman:"required"`
Description string `json:"description,omitempty"`
Duration string `json:"duration,omitempty" norman:"required"`
Comparison string `json:"comparison,omitempty" norman:"type=enum,options=equal|not-equal|greater-than|less-than|greater-or-equal|less-or-equal,default=equal"`
ThresholdValue float64 `json:"thresholdValue,omitempty" norman:"required,type=float"`
}
type TimingField struct {
GroupWaitSeconds int `json:"groupWaitSeconds,omitempty" norman:"required,default=30,min=1"`
GroupIntervalSeconds int `json:"groupIntervalSeconds,omitempty" norman:"required,default=180,min=1"`
RepeatIntervalSeconds int `json:"repeatIntervalSeconds,omitempty" norman:"required,default=3600,min=1"`
}
type NodeRule struct {
NodeName string `json:"nodeName,omitempty" norman:"type=reference[node]"`
Selector map[string]string `json:"selector,omitempty"`
Condition string `json:"condition,omitempty" norman:"required,options=notready|mem|cpu,default=notready"`
MemThreshold int `json:"memThreshold,omitempty" norman:"min=1,max=100,default=70"`
CPUThreshold int `json:"cpuThreshold,omitempty" norman:"min=1,default=70"`
}
type PodRule struct {
PodName string `json:"podName,omitempty" norman:"required,type=reference[/v3/projects/schemas/pod]"`
Condition string `json:"condition,omitempty" norman:"required,options=notrunning|notscheduled|restarts,default=notrunning"`
RestartTimes int `json:"restartTimes,omitempty" norman:"min=1,default=3"`
RestartIntervalSeconds int `json:"restartIntervalSeconds,omitempty" norman:"min=1,default=300"`
}
type EventRule struct {
EventType string `json:"eventType,omitempty" norman:"required,options=Normal|Warning,default=Warning"`
ResourceKind string `json:"resourceKind,omitempty" norman:"required,options=Pod|Node|Deployment|StatefulSet|DaemonSet"`
}
type WorkloadRule struct {
WorkloadID string `json:"workloadId,omitempty"`
Selector map[string]string `json:"selector,omitempty"`
AvailablePercentage int `json:"availablePercentage,omitempty" norman:"required,min=1,max=100,default=70"`
}
type SystemServiceRule struct {
Condition string `json:"condition,omitempty" norman:"required,options=etcd|controller-manager|scheduler,default=scheduler"`
}
type Notifier struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
// Standard object’s metadata. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NotifierSpec `json:"spec"`
// Most recent observed status of the notifier. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status NotifierStatus `json:"status"`
}
type NotifierSpec struct {
ClusterName string `json:"clusterName" norman:"type=reference[cluster]"`
DisplayName string `json:"displayName,omitempty" norman:"required"`
Description string `json:"description,omitempty"`
SMTPConfig *SMTPConfig `json:"smtpConfig,omitempty"`
SlackConfig *SlackConfig `json:"slackConfig,omitempty"`
PagerdutyConfig *PagerdutyConfig `json:"pagerdutyConfig,omitempty"`
WebhookConfig *WebhookConfig `json:"webhookConfig,omitempty"`
WechatConfig *WechatConfig `json:"wechatConfig,omitempty"`
}
type Notification struct {
Message string `json:"message,omitempty"`
SMTPConfig *SMTPConfig `json:"smtpConfig,omitempty"`
SlackConfig *SlackConfig `json:"slackConfig,omitempty"`
PagerdutyConfig *PagerdutyConfig `json:"pagerdutyConfig,omitempty"`
WebhookConfig *WebhookConfig `json:"webhookConfig,omitempty"`
WechatConfig *WechatConfig `json:"wechatConfig,omitempty"`
}
type SMTPConfig struct {
Host string `json:"host,omitempty" norman:"required,type=hostname"`
Port int `json:"port,omitempty" norman:"required,min=1,max=65535,default=587"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Sender string `json:"sender,omitempty" norman:"required"`
DefaultRecipient string `json:"defaultRecipient,omitempty" norman:"required"`
TLS bool `json:"tls,omitempty" norman:"required,default=true"`
}
type SlackConfig struct {
DefaultRecipient string `json:"defaultRecipient,omitempty" norman:"required"`
URL string `json:"url,omitempty" norman:"required"`
}
type PagerdutyConfig struct {
ServiceKey string `json:"serviceKey,omitempty" norman:"required"`
}
type WebhookConfig struct {
URL string `json:"url,omitempty" norman:"required"`
}
type WechatConfig struct {
DefaultRecipient string `json:"defaultRecipient,omitempty" norman:"required"`
Secret string `json:"secret,omitempty" norman:"type=password,required"`
Agent string `json:"agent,omitempty" norman:"required"`
Corp string `json:"corp,omitempty" norman:"required"`
RecipientType string `json:"recipientType,omitempty" norman:"required,options=tag|party|user,default=party"`
}
type NotifierStatus struct {
}
type AlertSystemImages struct {
AlertManager string `json:"alertManager,omitempty"`
AlertManagerHelper string `json:"alertManagerHelper,omitempty"`
}