monitor_resource.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. "time"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. "yunion.io/x/onecloud/pkg/apis/monitor"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. type MonitorResourceJointAlertOptions struct {
  23. }
  24. func (o *MonitorResourceJointAlertOptions) Params() (jsonutils.JSONObject, error) {
  25. return options.ListStructToParams(o)
  26. }
  27. func (o *MonitorResourceJointAlertOptions) Property() string {
  28. return "alert"
  29. }
  30. type MonitorResourceListOptions struct {
  31. options.BaseListOptions
  32. ResType string `help:"filter by resource type" json:"res_type"`
  33. ResId []string `help:"filter by resource id" json:"res_id"`
  34. ResName string `help:"filter by resource name" json:"res_name"`
  35. AlertStates []string `help:"filter by alert state" json:"alert_states"`
  36. StartTime time.Time `help:"start time for top query, format: 2025-01-01 00:00:00" json:"start_time"`
  37. EndTime time.Time `help:"end time for top query, format: 2025-01-01 00:00:00" json:"end_time"`
  38. Top int `help:"return top N resources by alert count (default: 5)" json:"top"`
  39. }
  40. func (o *MonitorResourceListOptions) Params() (jsonutils.JSONObject, error) {
  41. return options.ListStructToParams(o)
  42. }
  43. type MonitorResourceDoActionOptions struct {
  44. ID string `help:"ID of the resource"`
  45. ACTION string `help:"Action name"`
  46. Data string `json:"json string data"`
  47. }
  48. func (o *MonitorResourceDoActionOptions) GetId() string {
  49. return o.ID
  50. }
  51. func (o *MonitorResourceDoActionOptions) Params() (jsonutils.JSONObject, error) {
  52. var data jsonutils.JSONObject = jsonutils.NewDict()
  53. if len(o.Data) != 0 {
  54. d, err := jsonutils.ParseString(o.Data)
  55. if err != nil {
  56. return nil, errors.Wrapf(err, "parse string to data: %s", o.Data)
  57. }
  58. data = d
  59. }
  60. input := monitor.MonitorResourceDoActionInput{
  61. Action: o.ACTION,
  62. Data: data,
  63. }
  64. return jsonutils.Marshal(input), nil
  65. }