alert.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "fmt"
  17. "yunion.io/x/pkg/errors"
  18. monitorapi "yunion.io/x/onecloud/pkg/apis/monitor"
  19. "yunion.io/x/onecloud/pkg/mcclient"
  20. "yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
  21. options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
  22. )
  23. func init() {
  24. cmd := NewResourceCmd(monitor.Alerts)
  25. cmd.List(new(options.AlertListOptions))
  26. // cmd.Create(new(options.AlertCreateOptions))
  27. cmd.Show(new(options.AlertShowOptions))
  28. cmd.Update(new(options.AlertUpdateOptions))
  29. cmd.BatchDelete(new(options.AlertDeleteOptions))
  30. cmd.Perform("pause", new(options.AlertPauseOptions))
  31. aN := cmdN("alert")
  32. R(&options.AlertTestRunOptions{}, aN("test-run"), "Test run alert",
  33. func(s *mcclient.ClientSession, args *options.AlertTestRunOptions) error {
  34. data := new(monitorapi.AlertTestRunInput)
  35. if args.Debug {
  36. data.IsDebug = true
  37. }
  38. ret, err := monitor.Alerts.DoTestRun(s, args.ID, data)
  39. if err != nil {
  40. return errors.Wrap(err, "DoTestRun")
  41. }
  42. fmt.Printf("%s\n", ret.PrettyString())
  43. return nil
  44. })
  45. }