kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/notification/v2beta1/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 v2beta1 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 ) 22 23 // Configuration of ChatBot 24 type DingTalkChatBot struct { 25 // The webhook of ChatBot which the message will send to. 26 Webhook *SecretKeySelector `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 *SecretKeySelector `json:"secret,omitempty"` 33 } 34 35 // Configuration of conversation 36 type DingTalkConversation struct { 37 ChatIDs []string `json:"chatids"` 38 } 39 40 type DingTalkReceiver struct { 41 // whether the receiver is enabled 42 Enabled *bool `json:"enabled,omitempty"` 43 // DingTalkConfig to be selected for this receiver 44 DingTalkConfigSelector *metav1.LabelSelector `json:"dingtalkConfigSelector,omitempty"` 45 // Selector to filter alerts. 46 AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"` 47 // Be careful, a ChatBot only can send 20 message per minute. 48 ChatBot *DingTalkChatBot `json:"chatbot,omitempty"` 49 // The conversation which message will send to. 50 Conversation *DingTalkConversation `json:"conversation,omitempty"` 51 } 52 53 type EmailReceiver struct { 54 // whether the receiver is enabled 55 Enabled *bool `json:"enabled,omitempty"` 56 // Receivers' email addresses 57 To []string `json:"to"` 58 // EmailConfig to be selected for this receiver 59 EmailConfigSelector *metav1.LabelSelector `json:"emailConfigSelector,omitempty"` 60 // Selector to filter alerts. 61 AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"` 62 } 63 64 type SlackReceiver struct { 65 // whether the receiver is enabled 66 Enabled *bool `json:"enabled,omitempty"` 67 // SlackConfig to be selected for this receiver 68 SlackConfigSelector *metav1.LabelSelector `json:"slackConfigSelector,omitempty"` 69 // Selector to filter alerts. 70 AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"` 71 // The channel or user to send notifications to. 72 Channels []string `json:"channels"` 73 } 74 75 // ServiceReference holds a reference to Service.legacy.k8s.io 76 type ServiceReference struct { 77 // `namespace` is the namespace of the service. 78 // Required 79 Namespace string `json:"namespace"` 80 81 // `name` is the name of the service. 82 // Required 83 Name string `json:"name"` 84 85 // `path` is an optional URL path which will be sent in any request to 86 // this service. 87 // +optional 88 Path *string `json:"path,omitempty"` 89 90 // If specified, the port on the service that hosting webhook. 91 // Default to 443 for backward compatibility. 92 // `port` should be a valid port number (1-65535, inclusive). 93 // +optional 94 Port *int32 `json:"port,omitempty"` 95 96 // Http scheme, default is http. 97 // +optional 98 Scheme *string `json:"scheme,omitempty"` 99 } 100 101 type WebhookReceiver struct { 102 // whether the receiver is enabled 103 Enabled *bool `json:"enabled,omitempty"` 104 // WebhookConfig to be selected for this receiver 105 WebhookConfigSelector *metav1.LabelSelector `json:"webhookConfigSelector,omitempty"` 106 // Selector to filter alerts. 107 AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"` 108 // `url` gives the location of the webhook, in standard URL form 109 // (`scheme://host:port/path`). Exactly one of `url` or `service` 110 // must be specified. 111 // 112 // The `host` should not refer to a service running in the cluster; use 113 // the `service` field instead. The host might be resolved via external 114 // DNS in some api servers (e.g., `kube-apiserver` cannot resolve 115 // in-cluster DNS as that would be a layering violation). `host` may 116 // also be an IP address. 117 // 118 // Please note that using `localhost` or `127.0.0.1` as a `host` is 119 // risky unless you take great care to run this webhook on all hosts 120 // which run an apiserver which might need to make calls to this 121 // webhook. Such installs are likely to be non-portable, i.e., not easy 122 // to turn up in a new cluster. 123 // 124 // A path is optional, and if present may be any string permissible in 125 // a URL. You may use the path to pass an arbitrary string to the 126 // webhook, for example, a cluster identifier. 127 // 128 // Attempting to use a user or basic auth e.g. "user:password@" is not 129 // allowed. Fragments ("#...") and query parameters ("?...") are not 130 // allowed, either. 131 // 132 // +optional 133 URL *string `json:"url,omitempty"` 134 135 // `service` is a reference to the service for this webhook. Either 136 // `service` or `url` must be specified. 137 // 138 // If the webhook is running within the cluster, then you should use `service`. 139 // 140 // +optional 141 Service *ServiceReference `json:"service,omitempty"` 142 143 HTTPConfig *HTTPClientConfig `json:"httpConfig,omitempty"` 144 } 145 146 type WechatReceiver struct { 147 // whether the receiver is enabled 148 Enabled *bool `json:"enabled,omitempty"` 149 // WechatConfig to be selected for this receiver 150 WechatConfigSelector *metav1.LabelSelector `json:"wechatConfigSelector,omitempty"` 151 // Selector to filter alerts. 152 AlertSelector *metav1.LabelSelector `json:"alertSelector,omitempty"` 153 // +optional 154 ToUser []string `json:"toUser,omitempty"` 155 ToParty []string `json:"toParty,omitempty"` 156 ToTag []string `json:"toTag,omitempty"` 157 } 158 159 // ReceiverSpec defines the desired state of Receiver 160 type ReceiverSpec struct { 161 DingTalk *DingTalkReceiver `json:"dingtalk,omitempty"` 162 Email *EmailReceiver `json:"email,omitempty"` 163 Slack *SlackReceiver `json:"slack,omitempty"` 164 Webhook *WebhookReceiver `json:"webhook,omitempty"` 165 Wechat *WechatReceiver `json:"wechat,omitempty"` 166 } 167 168 // ReceiverStatus defines the observed state of Receiver 169 type ReceiverStatus struct { 170 } 171 172 // +kubebuilder:object:root=true 173 // +kubebuilder:resource:scope=Cluster,shortName=nr,categories=notification-manager 174 // +kubebuilder:subresource:status 175 // +genclient 176 // +genclient:nonNamespaced 177 // Receiver is the Schema for the receivers API 178 type Receiver struct { 179 metav1.TypeMeta `json:",inline"` 180 metav1.ObjectMeta `json:"metadata,omitempty"` 181 182 Spec ReceiverSpec `json:"spec,omitempty"` 183 Status ReceiverStatus `json:"status,omitempty"` 184 } 185 186 // +kubebuilder:object:root=true 187 188 // ReceiverList contains a list of Receiver 189 type ReceiverList struct { 190 metav1.TypeMeta `json:",inline"` 191 metav1.ListMeta `json:"metadata,omitempty"` 192 Items []Receiver `json:"items"` 193 } 194 195 func init() { 196 SchemeBuilder.Register(&Receiver{}, &ReceiverList{}) 197 } 198 199 func (_ *Receiver) Hub() {}