mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
climc: alarmevents: use options for param serialization
This commit is contained in:
@@ -5,51 +5,18 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 列出报警事件
|
||||
*/
|
||||
type AlarmEventListOptions struct {
|
||||
BaseListOptions
|
||||
NodeLabels string `help:"Service tree node labels"`
|
||||
MetricName string `help:"Metric name"`
|
||||
HostName string `help:"Host name"`
|
||||
HostIp string `help:"Host IP address"`
|
||||
AlarmLevel string `help:"Alarm level"`
|
||||
AlarmCondition string `help:"Concrete alarm rule"`
|
||||
Template string `help:"Template number of the alarm condition"`
|
||||
AckStatus string `help:"Alarm event ack status"`
|
||||
}
|
||||
R(&AlarmEventListOptions{}, "alarmevent-list", "List all alarm's event", func(s *mcclient.ClientSession, args *AlarmEventListOptions) error {
|
||||
params := FetchPagingParams(args.BaseListOptions)
|
||||
|
||||
if len(args.NodeLabels) > 0 {
|
||||
params.Add(jsonutils.NewString(args.NodeLabels), "node_labels")
|
||||
R(&options.AlarmEventListOptions{}, "alarmevent-list", "List all alarm's event", func(s *mcclient.ClientSession, opts *options.AlarmEventListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.MetricName) > 0 {
|
||||
params.Add(jsonutils.NewString(args.MetricName), "metric_name")
|
||||
}
|
||||
if len(args.HostName) > 0 {
|
||||
params.Add(jsonutils.NewString(args.HostName), "host_name")
|
||||
}
|
||||
if len(args.HostIp) > 0 {
|
||||
params.Add(jsonutils.NewString(args.HostIp), "host_ip")
|
||||
}
|
||||
if len(args.AlarmLevel) > 0 {
|
||||
params.Add(jsonutils.NewString(args.AlarmLevel), "alarm_level")
|
||||
}
|
||||
if len(args.AlarmCondition) > 0 {
|
||||
params.Add(jsonutils.NewString(args.AlarmCondition), "alarm_condition")
|
||||
}
|
||||
if len(args.Template) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Template), "template")
|
||||
}
|
||||
if len(args.AckStatus) > 0 {
|
||||
params.Add(jsonutils.NewString(args.AckStatus), "ack_status")
|
||||
}
|
||||
|
||||
result, err := modules.AlarmEvents.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user