kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/notification/v2beta2/receiver_types.go (about)

     1  /*
     2  
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v2beta2
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  )
    22  
    23  // DingTalkChatBot is the configuration of ChatBot
    24  type DingTalkChatBot struct {
    25  	// The webhook of ChatBot which the message will send to.
    26  	Webhook *Credential `json:"webhook"`
    27  
    28  	// Custom keywords of ChatBot
    29  	Keywords []string `json:"keywords,omitempty"`
    30  
    31  	// Secret of ChatBot, you can get it after enabled Additional Signature of ChatBot.
    32  	Secret *Credential `json:"secret,omitempty"`
    33  	// The phone numbers of the users which will be @.
    34  	AtMobiles []string `json:"atMobiles,omitempty"`
    35  	// The users who will be @.
    36  	AtUsers []string `json:"atUsers,omitempty"`
    37  	// Whether @everyone.
    38  	AtAll bool `json:"atAll,omitempty"`
    39  }
    40  
    41  // DingTalkConversation of conversation
    42  type DingTalkConversation struct {
    43  	ChatIDs []string `json:"chatids"`
    44  }
    45  
    46  type DingTalkReceiver struct {
    47  	// whether the receiver is enabled
    48  	Enabled *bool `json:"enabled,omitempty"`
    49  	// DingTalkConfig to be selected for this receiver
    50  	DingTalkConfigSelector *metav1.LabelSelector `json:"dingtalkConfigSelector,omitempty"`
    51  	// Selector to filter alerts.
    52  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
    53  	// Be careful, a ChatBot only can send 20 message per minute.
    54  	ChatBot *DingTalkChatBot `json:"chatbot,omitempty"`
    55  	// The conversation which message will send to.
    56  	Conversation *DingTalkConversation `json:"conversation,omitempty"`
    57  	// The name of the template to generate notification.
    58  	// If the global template is not set, it will use default.
    59  	Template *string `json:"template,omitempty"`
    60  	// The name of the template to generate markdown title
    61  	TitleTemplate *string `json:"titleTemplate,omitempty"`
    62  	// template type: text or markdown
    63  	TmplType *string `json:"tmplType,omitempty"`
    64  	// Template file.
    65  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
    66  }
    67  
    68  type EmailReceiver struct {
    69  	// whether the receiver is enabled
    70  	Enabled *bool `json:"enabled,omitempty"`
    71  	// Receivers' email addresses
    72  	To []string `json:"to"`
    73  	// EmailConfig to be selected for this receiver
    74  	EmailConfigSelector *metav1.LabelSelector `json:"emailConfigSelector,omitempty"`
    75  	// Selector to filter alerts.
    76  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
    77  	// The name of the template to generate notification.
    78  	// If the global template is not set, it will use default.
    79  	Template *string `json:"template,omitempty"`
    80  	// The name of the template to generate email subject
    81  	SubjectTemplate *string `json:"subjectTemplate,omitempty"`
    82  	// template type: text or html, default type is html
    83  	TmplType *string `json:"tmplType,omitempty"`
    84  	// Template file.
    85  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
    86  }
    87  
    88  type SlackReceiver struct {
    89  	// whether the receiver is enabled
    90  	Enabled *bool `json:"enabled,omitempty"`
    91  	// SlackConfig to be selected for this receiver
    92  	SlackConfigSelector *metav1.LabelSelector `json:"slackConfigSelector,omitempty"`
    93  	// Selector to filter alerts.
    94  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
    95  	// The channel or user to send notifications to.
    96  	Channels []string `json:"channels"`
    97  	// The name of the template to generate notification.
    98  	// If the global template is not set, it will use default.
    99  	Template *string `json:"template,omitempty"`
   100  	// Template file.
   101  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   102  }
   103  
   104  // ServiceReference holds a reference to Service.legacy.k8s.io
   105  type ServiceReference struct {
   106  	// `namespace` is the namespace of the service.
   107  	// Required
   108  	Namespace string `json:"namespace"`
   109  
   110  	// `name` is the name of the service.
   111  	// Required
   112  	Name string `json:"name"`
   113  
   114  	// `path` is an optional URL path which will be sent in any request to
   115  	// this service.
   116  	// +optional
   117  	Path *string `json:"path,omitempty"`
   118  
   119  	// If specified, the port on the service that hosting webhook.
   120  	// Default to 443 for backward compatibility.
   121  	// `port` should be a valid port number (1-65535, inclusive).
   122  	// +optional
   123  	Port *int32 `json:"port,omitempty"`
   124  
   125  	// Http scheme, default is http.
   126  	// +optional
   127  	Scheme *string `json:"scheme,omitempty"`
   128  }
   129  
   130  type WebhookReceiver struct {
   131  	// whether the receiver is enabled
   132  	Enabled *bool `json:"enabled,omitempty"`
   133  	// WebhookConfig to be selected for this receiver
   134  	WebhookConfigSelector *metav1.LabelSelector `json:"webhookConfigSelector,omitempty"`
   135  	// Selector to filter alerts.
   136  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
   137  	// `url` gives the location of the webhook, in standard URL form
   138  	// (`scheme://host:port/path`). Exactly one of `url` or `service`
   139  	// must be specified.
   140  	//
   141  	// The `host` should not refer to a service running in the cluster; use
   142  	// the `service` field instead. The host might be resolved via external
   143  	// DNS in some api servers (e.g., `kube-apiserver` cannot resolve
   144  	// in-cluster DNS as that would be a layering violation). `host` may
   145  	// also be an IP address.
   146  	//
   147  	// Please note that using `localhost` or `127.0.0.1` as a `host` is
   148  	// risky unless you take great care to run this webhook on all hosts
   149  	// which run an apiserver which might need to make calls to this
   150  	// webhook. Such installs are likely to be non-portable, i.e., not easy
   151  	// to turn up in a new cluster.
   152  	//
   153  	// A path is optional, and if present may be any string permissible in
   154  	// a URL. You may use the path to pass an arbitrary string to the
   155  	// webhook, for example, a cluster identifier.
   156  	//
   157  	// Attempting to use a user or basic auth e.g. "user:password@" is not
   158  	// allowed. Fragments ("#...") and query parameters ("?...") are not
   159  	// allowed, either.
   160  	//
   161  	// +optional
   162  	URL *string `json:"url,omitempty"`
   163  
   164  	// `service` is a reference to the service for this webhook. Either
   165  	// `service` or `url` must be specified.
   166  	//
   167  	// If the webhook is running within the cluster, then you should use `service`.
   168  	//
   169  	// +optional
   170  	Service *ServiceReference `json:"service,omitempty"`
   171  
   172  	HTTPConfig *HTTPClientConfig `json:"httpConfig,omitempty"`
   173  	// The name of the template to generate notification.
   174  	// If the global template is not set, it will use default.
   175  	Template *string `json:"template,omitempty"`
   176  	// Template file.
   177  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   178  }
   179  
   180  type WechatReceiver struct {
   181  	// whether the receiver is enabled
   182  	Enabled *bool `json:"enabled,omitempty"`
   183  	// WechatConfig to be selected for this receiver
   184  	WechatConfigSelector *metav1.LabelSelector `json:"wechatConfigSelector,omitempty"`
   185  	// Selector to filter alerts.
   186  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
   187  	// +optional
   188  	ToUser  []string `json:"toUser,omitempty"`
   189  	ToParty []string `json:"toParty,omitempty"`
   190  	ToTag   []string `json:"toTag,omitempty"`
   191  	// The name of the template to generate notification.
   192  	// If the global template is not set, it will use default.
   193  	Template *string `json:"template,omitempty"`
   194  	// template type: text or markdown, default type is text
   195  	TmplType *string `json:"tmplType,omitempty"`
   196  	// Template file.
   197  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   198  }
   199  
   200  type SmsReceiver struct {
   201  	// whether the receiver is enabled
   202  	Enabled *bool `json:"enabled,omitempty"`
   203  	// SmsConfig to be selected for this receiver
   204  	SmsConfigSelector *metav1.LabelSelector `json:"smsConfigSelector,omitempty"`
   205  	// Selector to filter alerts.
   206  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
   207  	// Receivers' phone numbers
   208  	PhoneNumbers []string `json:"phoneNumbers"`
   209  	// The name of the template to generate notification.
   210  	// If the global template is not set, it will use default.
   211  	Template *string `json:"template,omitempty"`
   212  	// Template file.
   213  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   214  }
   215  
   216  // PushoverUserProfile includes userKey and other preferences
   217  type PushoverUserProfile struct {
   218  	// UserKey is the user (Pushover User Key) to send notifications to.
   219  	// +kubebuilder:validation:Pattern=`^[A-Za-z0-9]{30}$`
   220  	UserKey *string `json:"userKey"`
   221  	// Devices refers to device name to send the message directly to that device, rather than all of the user's devices
   222  	Devices []string `json:"devices,omitempty"`
   223  	// Title refers to message's title, otherwise your app's name is used.
   224  	// it is deprecated, now the title will be generated by the title template.
   225  	//
   226  	// Deprecated
   227  	Title *string `json:"title,omitempty"`
   228  	// Sound refers to the name of one of the sounds (https://pushover.net/api#sounds) supported by device clients
   229  	Sound *string `json:"sound,omitempty"`
   230  }
   231  
   232  type PushoverReceiver struct {
   233  	// whether the receiver is enabled
   234  	Enabled *bool `json:"enabled,omitempty"`
   235  	// PushoverConfig to be selected for this receiver
   236  	PushoverConfigSelector *metav1.LabelSelector `json:"pushoverConfigSelector,omitempty"`
   237  	// Selector to filter alerts.
   238  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
   239  	// The name of the template to generate notification.
   240  	// If the global template is not set, it will use default.
   241  	Template *string `json:"template,omitempty"`
   242  	// The name of the template to generate message title
   243  	TitleTemplate *string `json:"titleTemplate,omitempty"`
   244  	// The users profile.
   245  	Profiles []*PushoverUserProfile `json:"profiles"`
   246  	// Template file.
   247  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   248  }
   249  
   250  // FeishuChatBot is the configuration of ChatBot
   251  type FeishuChatBot struct {
   252  	// The webhook of the ChatBot to which the message will be sent.
   253  	Webhook *Credential `json:"webhook"`
   254  
   255  	// Custom keywords of ChatBot
   256  	Keywords []string `json:"keywords,omitempty"`
   257  
   258  	// Secret of ChatBot, you can get it after enabling signature verification of ChatBot.
   259  	Secret *Credential `json:"secret,omitempty"`
   260  }
   261  
   262  type FeishuReceiver struct {
   263  	// whether the receiver is enabled
   264  	Enabled *bool `json:"enabled,omitempty"`
   265  	// FeishuConfig to be selected for this receiver
   266  	FeishuConfigSelector *metav1.LabelSelector `json:"feishuConfigSelector,omitempty"`
   267  	// Selector to filter alerts.
   268  	AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"`
   269  	// +optional
   270  	// +kubebuilder:validation:MaxItems=200
   271  	User []string `json:"user,omitempty"`
   272  	// +optional
   273  	// +kubebuilder:validation:MaxItems=200
   274  	Department []string       `json:"department,omitempty"`
   275  	ChatBot    *FeishuChatBot `json:"chatbot,omitempty"`
   276  	// The name of the template to generate notification.
   277  	// If the global template is not set, it will use default.
   278  	Template *string `json:"template,omitempty"`
   279  	// template type: text or post, default type is post
   280  	TmplType *string `json:"tmplType,omitempty"`
   281  	// Template file.
   282  	TmplText *ConfigmapKeySelector `json:"tmplText,omitempty"`
   283  }
   284  
   285  // ReceiverSpec defines the desired state of Receiver
   286  type ReceiverSpec struct {
   287  	DingTalk *DingTalkReceiver `json:"dingtalk,omitempty"`
   288  	Email    *EmailReceiver    `json:"email,omitempty"`
   289  	Slack    *SlackReceiver    `json:"slack,omitempty"`
   290  	Webhook  *WebhookReceiver  `json:"webhook,omitempty"`
   291  	Wechat   *WechatReceiver   `json:"wechat,omitempty"`
   292  	Sms      *SmsReceiver      `json:"sms,omitempty"`
   293  	Pushover *PushoverReceiver `json:"pushover,omitempty"`
   294  	Feishu   *FeishuReceiver   `json:"feishu,omitempty"`
   295  }
   296  
   297  // ReceiverStatus defines the observed state of Receiver
   298  type ReceiverStatus struct {
   299  }
   300  
   301  // +kubebuilder:object:root=true
   302  // +kubebuilder:resource:scope=Cluster,shortName=nr,categories=notification-manager
   303  // +kubebuilder:subresource:status
   304  // +kubebuilder:storageversion
   305  // +genclient
   306  // +genclient:nonNamespaced
   307  // Receiver is the Schema for the receivers API
   308  type Receiver struct {
   309  	metav1.TypeMeta   `json:",inline"`
   310  	metav1.ObjectMeta `json:"metadata,omitempty"`
   311  
   312  	Spec   ReceiverSpec   `json:"spec,omitempty"`
   313  	Status ReceiverStatus `json:"status,omitempty"`
   314  }
   315  
   316  // +kubebuilder:object:root=true
   317  
   318  // ReceiverList contains a list of Receiver
   319  type ReceiverList struct {
   320  	metav1.TypeMeta `json:",inline"`
   321  	metav1.ListMeta `json:"metadata,omitempty"`
   322  	Items           []Receiver `json:"items"`
   323  }
   324  
   325  func init() {
   326  	SchemeBuilder.Register(&Receiver{}, &ReceiverList{})
   327  }