config.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package notify
  15. import (
  16. "reflect"
  17. "time"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/pkg/gotypes"
  20. "yunion.io/x/onecloud/pkg/apis"
  21. )
  22. type ConfigCreateInput struct {
  23. apis.DomainLevelResourceCreateInput
  24. // description: config type
  25. // required: true
  26. // example: feishu
  27. Type string `json:"type"`
  28. // description: config content
  29. // required: true
  30. // example: {"app_id": "123456", "app_secret": "feishu_nihao"}
  31. Content *SNotifyConfigContent `json:"content"`
  32. // description: attribution
  33. // required: true
  34. // enum: ["system","domain"]
  35. // example: system
  36. Attribution string `json:"attribution"`
  37. }
  38. type ConfigUpdateInput struct {
  39. // description: config content
  40. // required: true
  41. // example: {"app_id": "123456", "app_secret": "feishu_nihao"}
  42. Content *SNotifyConfigContent `json:"content"`
  43. }
  44. type ConfigDetails struct {
  45. apis.DomainLevelResourceDetails
  46. SConfig
  47. }
  48. type ConfigListInput struct {
  49. apis.DomainLevelResourceListInput
  50. Type string `json:"type"`
  51. Attribution string `json:"attribution"`
  52. }
  53. type ConfigValidateInput struct {
  54. // description: config type
  55. // required: true
  56. // example: feishu
  57. Type string `json:"type"`
  58. // description: config content
  59. // required: true
  60. // example: {"app_id": "123456", "app_secret": "feishu_nihao"}
  61. Content *SNotifyConfigContent `json:"content"`
  62. }
  63. type ConfigValidateOutput struct {
  64. IsValid bool `json:"is_valid"`
  65. Message string `json:"message"`
  66. }
  67. type ConfigManagerGetTypesInput struct {
  68. // description: View the available notification channels for the receivers
  69. // required: false
  70. Receivers []string `json:"receivers"`
  71. // description: View the available notification channels for the domains with these DomainIds
  72. // required: false
  73. DomainIds []string `json:"domain_ids"`
  74. // description: Operation of reduce
  75. // required: false
  76. // enum: ["union","merge"]
  77. Operation string `json:"operation"`
  78. }
  79. type ConfigManagerGetTypesOutput struct {
  80. Types []string `json:"types"`
  81. }
  82. type SsNotification struct {
  83. ContactType string `json:"contact_type"`
  84. Topic string `json:"topic"`
  85. Message string `json:"message"`
  86. Event SNotifyEvent `json:"event"`
  87. AdvanceDays int `json:"advance_days"`
  88. RobotUseTemplate bool `json:"robot_use_template"`
  89. }
  90. type SBatchSendParams struct {
  91. ContactType string `json:"contact_type"`
  92. Contacts []string `json:"contacts"`
  93. Topic string `json:"topic"`
  94. Message string `json:"message"`
  95. Priority string `json:"priority"`
  96. Lang string `json:"lang"`
  97. }
  98. type SNotifyReceiver struct {
  99. Contact string `json:"contact"`
  100. DomainId string `json:"domain_id"`
  101. Enabled bool `json:"enabled"`
  102. Lang string `json:"lang"`
  103. callback func(error)
  104. }
  105. func (self *SNotifyReceiver) Callback(err error) {
  106. if self.callback != nil && err != nil {
  107. self.callback(err)
  108. }
  109. }
  110. type SSendParams struct {
  111. ContactType string `json:"contact_type"`
  112. Contact string `json:"contact"`
  113. Topic string `json:"topic"`
  114. Message string `json:"message"`
  115. Priority string `json:"priority"`
  116. Title string `json:"title"`
  117. RemoteTemplate string `json:"remote_template"`
  118. Lang string `json:"lang"`
  119. Receiver SNotifyReceiver `json:"receiver"`
  120. }
  121. type SNotificationGroupSearchInput struct {
  122. StartTime time.Time `json:"start_time"`
  123. EndTime time.Time `json:"end_time"`
  124. GroupKey string `json:"group_key"`
  125. ReceiverId string `json:"receiver_id"`
  126. ContactType string `json:"contact_type"`
  127. }
  128. type SendParams struct {
  129. Title string `json:"title"`
  130. Message string `json:"message"`
  131. Priority string `json:"priority"`
  132. RemoteTemplate string `json:"remote_template"`
  133. Topic string `json:"topic"`
  134. Event string `json:"event"`
  135. Receivers SNotifyReceiver `json:"receivers"`
  136. EmailMsg SEmailMessage `json:"email_msg"`
  137. Header jsonutils.JSONObject `json:"header"`
  138. Body jsonutils.JSONObject `json:"body"`
  139. MsgKey string `json:"msg_key"`
  140. SecretKey string `json:"secret_key"`
  141. DomainId string `json:"domain_id"`
  142. RemoteTemplateParam SRemoteTemplateParam `json:"remote_template_param"`
  143. GroupKey string `json:"group_key"`
  144. // minutes
  145. GroupTimes uint `json:"group_times"`
  146. ReceiverId string `json:"receiver_id"`
  147. SendTime time.Time `json:"send_time"`
  148. }
  149. type SRemoteTemplateParam struct {
  150. Code string `json:"code"`
  151. Domain string `json:"domain"`
  152. User string `json:"user"`
  153. Type string `json:"type"`
  154. AlertName string `json:"alert_name"`
  155. }
  156. type SSMSSendParams struct {
  157. RemoteTemplate string `json:"remote_template"`
  158. RemoteTemplateParam SRemoteTemplateParam `json:"remote_template_param"`
  159. AppKey string `json:"app_key"`
  160. AppSecret string `json:"app_secret"`
  161. From string `json:"from"`
  162. To string `json:"to"`
  163. TemplateId string `json:"template_id"`
  164. TemplateParas string `json:"template_paras"`
  165. Signature string `json:"signature"`
  166. }
  167. type NotifyConfig struct {
  168. SNotifyConfigContent
  169. Attribution string `json:"attribution"`
  170. DomainId string `json:"domain_id"`
  171. }
  172. func (self *NotifyConfig) GetDomainId() string {
  173. if self.Attribution == CONFIG_ATTRIBUTION_SYSTEM {
  174. return CONFIG_ATTRIBUTION_SYSTEM
  175. }
  176. return self.DomainId
  177. }
  178. type SNotifyConfigContent struct {
  179. // Email
  180. Hostname string `json:"hostname"`
  181. Hostport int `json:"hostport"`
  182. Password string `json:"password"`
  183. SslGlobal bool `json:"ssl_global"`
  184. Username string `json:"username"`
  185. SenderAddress string `json:"sender_address"`
  186. //Lark
  187. AppId string `json:"app_id"`
  188. AppSecret string `json:"app_secret"`
  189. AccessToken string `json:"access_token"`
  190. AccessTokenExpireTime time.Time `json:"access_token_expire_time"`
  191. // workwx
  192. AgentId string `json:"agent_id"`
  193. CorpId string `json:"corp_id"`
  194. Secret string `json:"secret"`
  195. // dingtalk
  196. //AgentId string
  197. //AppSecret string
  198. AppKey string `json:"app_key"`
  199. // sms
  200. VerifiyCode string `json:"verifiy_code"`
  201. AlertsCode string `json:"alerts_code"`
  202. ErrorCode string `json:"error_code"`
  203. PhoneNumber string `json:"phone_number"`
  204. AccessKeyId string `json:"access_key_id"`
  205. AccessKeySecret string `json:"access_key_secret"`
  206. ServiceUrl string `json:"service_url"`
  207. Signature string `json:"signature"`
  208. SmsDriver string `json:"sms_driver"`
  209. }
  210. func (self SNotifyConfigContent) String() string {
  211. return jsonutils.Marshal(self).String()
  212. }
  213. func (self SNotifyConfigContent) IsZero() bool {
  214. return jsonutils.Marshal(self).Equals(jsonutils.Marshal(SNotifyConfigContent{}))
  215. }
  216. func init() {
  217. gotypes.RegisterSerializable(reflect.TypeOf(&SNotifyConfigContent{}), func() gotypes.ISerializable {
  218. return &SNotifyConfigContent{}
  219. })
  220. }