/
receiver_types.go
327 lines (291 loc) · 12.2 KB
/
receiver_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
319
320
321
322
323
324
325
326
327
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2beta2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// DingTalkChatBot is the configuration of ChatBot
type DingTalkChatBot struct {
// The webhook of ChatBot which the message will send to.
Webhook *Credential `json:"webhook"`
// Custom keywords of ChatBot
Keywords []string `json:"keywords,omitempty"`
// Secret of ChatBot, you can get it after enabled Additional Signature of ChatBot.
Secret *Credential `json:"secret,omitempty"`
// The phone numbers of the users which will be @.
AtMobiles []string `json:"atMobiles,omitempty"`
// The users who will be @.
AtUsers []string `json:"atUsers,omitempty"`
// Whether @everyone.
AtAll bool `json:"atAll,omitempty"`
}
// DingTalkConversation of conversation
type DingTalkConversation struct {
ChatIDs []string `json:"chatids"`
}
type DingTalkReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// DingTalkConfig to be selected for this receiver
DingTalkConfigSelector *metav1.LabelSelector `json:"dingtalkConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// Be careful, a ChatBot only can send 20 message per minute.
ChatBot *DingTalkChatBot `json:"chatbot,omitempty"`
// The conversation which message will send to.
Conversation *DingTalkConversation `json:"conversation,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// The name of the template to generate markdown title
TitleTemplate *string `json:"titleTemplate,omitempty"`
// template type: text or markdown
TmplType *string `json:"tmplType,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
type EmailReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// Receivers' email addresses
To []string `json:"to"`
// EmailConfig to be selected for this receiver
EmailConfigSelector *metav1.LabelSelector `json:"emailConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// The name of the template to generate email subject
SubjectTemplate *string `json:"subjectTemplate,omitempty"`
// template type: text or html, default type is html
TmplType *string `json:"tmplType,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
type SlackReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// SlackConfig to be selected for this receiver
SlackConfigSelector *metav1.LabelSelector `json:"slackConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// The channel or user to send notifications to.
Channels []string `json:"channels"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
// ServiceReference holds a reference to Service.legacy.k8s.io
type ServiceReference struct {
// `namespace` is the namespace of the service.
// Required
Namespace string `json:"namespace"`
// `name` is the name of the service.
// Required
Name string `json:"name"`
// `path` is an optional URL path which will be sent in any request to
// this service.
// +optional
Path *string `json:"path,omitempty"`
// If specified, the port on the service that hosting webhook.
// Default to 443 for backward compatibility.
// `port` should be a valid port number (1-65535, inclusive).
// +optional
Port *int32 `json:"port,omitempty"`
// Http scheme, default is http.
// +optional
Scheme *string `json:"scheme,omitempty"`
}
type WebhookReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// WebhookConfig to be selected for this receiver
WebhookConfigSelector *metav1.LabelSelector `json:"webhookConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// `url` gives the location of the webhook, in standard URL form
// (`scheme://host:port/path`). Exactly one of `url` or `service`
// must be specified.
//
// The `host` should not refer to a service running in the cluster; use
// the `service` field instead. The host might be resolved via external
// DNS in some api servers (e.g., `kube-apiserver` cannot resolve
// in-cluster DNS as that would be a layering violation). `host` may
// also be an IP address.
//
// Please note that using `localhost` or `127.0.0.1` as a `host` is
// risky unless you take great care to run this webhook on all hosts
// which run an apiserver which might need to make calls to this
// webhook. Such installs are likely to be non-portable, i.e., not easy
// to turn up in a new cluster.
//
// A path is optional, and if present may be any string permissible in
// a URL. You may use the path to pass an arbitrary string to the
// webhook, for example, a cluster identifier.
//
// Attempting to use a user or basic auth e.g. "user:password@" is not
// allowed. Fragments ("#...") and query parameters ("?...") are not
// allowed, either.
//
// +optional
URL *string `json:"url,omitempty"`
// `service` is a reference to the service for this webhook. Either
// `service` or `url` must be specified.
//
// If the webhook is running within the cluster, then you should use `service`.
//
// +optional
Service *ServiceReference `json:"service,omitempty"`
HTTPConfig *HTTPClientConfig `json:"httpConfig,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
type WechatReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// WechatConfig to be selected for this receiver
WechatConfigSelector *metav1.LabelSelector `json:"wechatConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// +optional
ToUser []string `json:"toUser,omitempty"`
ToParty []string `json:"toParty,omitempty"`
ToTag []string `json:"toTag,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// template type: text or markdown, default type is text
TmplType *string `json:"tmplType,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
type SmsReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// SmsConfig to be selected for this receiver
SmsConfigSelector *metav1.LabelSelector `json:"smsConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// Receivers' phone numbers
PhoneNumbers []string `json:"phoneNumbers"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
// PushoverUserProfile includes userKey and other preferences
type PushoverUserProfile struct {
// UserKey is the user (Pushover User Key) to send notifications to.
// +kubebuilder:validation:Pattern=`^[A-Za-z0-9]{30}$`
UserKey *string `json:"userKey"`
// Devices refers to device name to send the message directly to that device, rather than all of the user's devices
Devices []string `json:"devices,omitempty"`
// Title refers to message's title, otherwise your app's name is used.
// it is deprecated, now the title will be generated by the title template.
//
// Deprecated
Title *string `json:"title,omitempty"`
// Sound refers to the name of one of the sounds (https://pushover.net/api#sounds) supported by device clients
Sound *string `json:"sound,omitempty"`
}
type PushoverReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// PushoverConfig to be selected for this receiver
PushoverConfigSelector *metav1.LabelSelector `json:"pushoverConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// The name of the template to generate message title
TitleTemplate *string `json:"titleTemplate,omitempty"`
// The users profile.
Profiles []*PushoverUserProfile `json:"profiles"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
// FeishuChatBot is the configuration of ChatBot
type FeishuChatBot struct {
// The webhook of the ChatBot to which the message will be sent.
Webhook *Credential `json:"webhook"`
// Custom keywords of ChatBot
Keywords []string `json:"keywords,omitempty"`
// Secret of ChatBot, you can get it after enabling signature verification of ChatBot.
Secret *Credential `json:"secret,omitempty"`
}
type FeishuReceiver struct {
// whether the receiver is enabled
Enabled *bool `json:"enabled,omitempty"`
// FeishuConfig to be selected for this receiver
FeishuConfigSelector *metav1.LabelSelector `json:"feishuConfigSelector,omitempty"`
// Selector to filter alerts.
AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
// +optional
// +kubebuilder:validation:MaxItems=200
User []string `json:"user,omitempty"`
// +optional
// +kubebuilder:validation:MaxItems=200
Department []string `json:"department,omitempty"`
ChatBot *FeishuChatBot `json:"chatbot,omitempty"`
// The name of the template to generate notification.
// If the global template is not set, it will use default.
Template *string `json:"template,omitempty"`
// template type: text or post, default type is post
TmplType *string `json:"tmplType,omitempty"`
// Template file.
TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
}
// ReceiverSpec defines the desired state of Receiver
type ReceiverSpec struct {
DingTalk *DingTalkReceiver `json:"dingtalk,omitempty"`
Email *EmailReceiver `json:"email,omitempty"`
Slack *SlackReceiver `json:"slack,omitempty"`
Webhook *WebhookReceiver `json:"webhook,omitempty"`
Wechat *WechatReceiver `json:"wechat,omitempty"`
Sms *SmsReceiver `json:"sms,omitempty"`
Pushover *PushoverReceiver `json:"pushover,omitempty"`
Feishu *FeishuReceiver `json:"feishu,omitempty"`
}
// ReceiverStatus defines the observed state of Receiver
type ReceiverStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=nr,categories=notification-manager
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +genclient
// +genclient:nonNamespaced
// Receiver is the Schema for the receivers API
type Receiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ReceiverSpec `json:"spec,omitempty"`
Status ReceiverStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// ReceiverList contains a list of Receiver
type ReceiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Receiver `json:"items"`
}
func init() {
SchemeBuilder.Register(&Receiver{}, &ReceiverList{})
}