notification.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/onecloud/pkg/mcclient"
  17. "yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
  18. options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
  19. )
  20. func init() {
  21. nN := cmdN("notification")
  22. R(&options.NotificationListOptions{}, nN("list"), "List all alert notification",
  23. func(s *mcclient.ClientSession, args *options.NotificationListOptions) error {
  24. params, err := args.Params()
  25. if err != nil {
  26. return err
  27. }
  28. ret, err := monitor.Notifications.List(s, params)
  29. if err != nil {
  30. return err
  31. }
  32. printList(ret, monitor.Notifications.GetColumns(s))
  33. return nil
  34. })
  35. R(&options.NotificationDingDingCreateOptions{}, nN("create-dingding"),
  36. "Create dingding alert notification",
  37. func(s *mcclient.ClientSession, args *options.NotificationDingDingCreateOptions) error {
  38. params, err := args.Params()
  39. if err != nil {
  40. return err
  41. }
  42. ret, err := monitor.Notifications.Create(s, params.JSON(params))
  43. if err != nil {
  44. return err
  45. }
  46. printObject(ret)
  47. return nil
  48. })
  49. R(&options.NotificationFeishuCreateOptions{}, nN("create-feishu"),
  50. "Create feishu alert notification",
  51. func(s *mcclient.ClientSession, args *options.NotificationFeishuCreateOptions) error {
  52. params, err := args.Params()
  53. if err != nil {
  54. return err
  55. }
  56. ret, err := monitor.Notifications.Create(s, params.JSON(params))
  57. if err != nil {
  58. return err
  59. }
  60. printObject(ret)
  61. return nil
  62. })
  63. R(&options.NotificationShowOptions{}, nN("show"), "Show alert notification",
  64. func(s *mcclient.ClientSession, args *options.NotificationShowOptions) error {
  65. ret, err := monitor.Notifications.Get(s, args.ID, nil)
  66. if err != nil {
  67. return err
  68. }
  69. printObject(ret)
  70. return nil
  71. })
  72. R(&options.NotificationUpdateOptions{}, nN("update"), "Update alert notification",
  73. func(s *mcclient.ClientSession, args *options.NotificationUpdateOptions) error {
  74. params, err := args.Params()
  75. if err != nil {
  76. return err
  77. }
  78. ret, err := monitor.Notifications.Update(s, args.ID, params.JSON(params))
  79. if err != nil {
  80. return err
  81. }
  82. printObject(ret)
  83. return nil
  84. })
  85. R(&options.NotificationDeleteOptions{}, nN("delete"), "Show delete notification",
  86. func(s *mcclient.ClientSession, args *options.NotificationDeleteOptions) error {
  87. ret := monitor.Notifications.BatchDelete(s, args.ID, nil)
  88. printBatchResults(ret, monitor.Notifications.GetColumns(s))
  89. return nil
  90. })
  91. }