ds.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 monitor
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/apis/monitor"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type DataSourceCreateOptions struct {
  21. NAME string
  22. }
  23. type DataSourceListOptions struct {
  24. options.BaseListOptions
  25. }
  26. func (d DataSourceListOptions) Params() (jsonutils.JSONObject, error) {
  27. return d.BaseListOptions.Params()
  28. }
  29. type DataSourceDeleteOptions struct {
  30. ID string `json:"-"`
  31. }
  32. type NotificationListOptions struct {
  33. options.BaseListOptions
  34. }
  35. type NotificationShowOptions struct {
  36. ID string `help:"ID or name of the alert notification config" json:"-"`
  37. }
  38. type NotificationDeleteOptions struct {
  39. ID []string `help:"ID or name of the alert notification config" json:"-"`
  40. }
  41. type NotificationFields struct {
  42. Frequency string `help:"notify frequency, e.g. 5m, 1h"`
  43. IsDefault *bool `help:"set as default notification"`
  44. DisableResolveMessage *bool `help:"disable notify recover message"`
  45. SendReminder *bool `help:"send reminder"`
  46. }
  47. type NotificationCreateOptions struct {
  48. NAME string `help:"notification config name"`
  49. NotificationFields
  50. }
  51. func (opt NotificationCreateOptions) Params() (*monitor.NotificationCreateInput, error) {
  52. ret := &monitor.NotificationCreateInput{
  53. Name: opt.NAME,
  54. SendReminder: opt.SendReminder,
  55. DisableResolveMessage: opt.DisableResolveMessage,
  56. }
  57. if opt.IsDefault != nil && *opt.IsDefault {
  58. ret.IsDefault = true
  59. }
  60. return ret, nil
  61. }
  62. type NotificationDingDingCreateOptions struct {
  63. NotificationCreateOptions
  64. URL string `help:"dingding webhook url"`
  65. MsgType string `help:"message type" choices:"markdown|actionCard" default:"markdown"`
  66. }
  67. func (opt NotificationDingDingCreateOptions) Params() (*monitor.NotificationCreateInput, error) {
  68. out, err := opt.NotificationCreateOptions.Params()
  69. if err != nil {
  70. return nil, err
  71. }
  72. out.Type = monitor.AlertNotificationTypeDingding
  73. out.Settings = jsonutils.Marshal(monitor.NotificationSettingDingding{
  74. Url: opt.URL,
  75. MessageType: opt.MsgType,
  76. })
  77. return out, nil
  78. }
  79. type NotificationFeishuCreateOptions struct {
  80. NotificationCreateOptions
  81. APPID string `help:"feishu robot appId"`
  82. APPSECRET string `help:"feishu robt appSecret"`
  83. }
  84. func (opt NotificationFeishuCreateOptions) Params() (*monitor.NotificationCreateInput, error) {
  85. out, err := opt.NotificationCreateOptions.Params()
  86. if err != nil {
  87. return nil, err
  88. }
  89. out.Type = monitor.AlertNotificationTypeFeishu
  90. out.Settings = jsonutils.Marshal(monitor.NotificationSettingFeishu{
  91. AppId: opt.APPID,
  92. AppSecret: opt.APPSECRET,
  93. })
  94. return out, nil
  95. }
  96. type NotificationUpdateOptions struct {
  97. NotificationFields
  98. ID string `help:"ID or name of the alert notification config" json:"-"`
  99. DisableDefault *bool `help:"disable as default notification" json:"-"`
  100. ResolveMessage *bool `help:"enable notify recover message" json:"-"`
  101. DisableSendReminder *bool `help:"disable send reminder" json:"-"`
  102. }
  103. func (opt NotificationUpdateOptions) Params() (*monitor.NotificationUpdateInput, error) {
  104. if opt.DisableDefault != nil && *opt.DisableDefault {
  105. tmp := false
  106. opt.IsDefault = &tmp
  107. }
  108. if opt.ResolveMessage != nil && *opt.ResolveMessage {
  109. tmp := false
  110. opt.DisableDefault = &tmp
  111. }
  112. if opt.DisableSendReminder != nil && *opt.DisableSendReminder {
  113. tmp := false
  114. opt.SendReminder = &tmp
  115. }
  116. ret := &monitor.NotificationUpdateInput{
  117. IsDefault: opt.IsDefault,
  118. DisableResolveMessage: opt.DisableResolveMessage,
  119. SendReminder: opt.SendReminder,
  120. }
  121. return ret, nil
  122. }