From 6037c84a58bbeded7d0dcedccc8fd414fc77651f Mon Sep 17 00:00:00 2001 From: zhaoxiangchun <1422928955@qq.com> Date: Fri, 25 Sep 2020 10:41:45 +0800 Subject: [PATCH] bugfix:commonalert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.suggestrule cli 调整 --- cmd/climc/shell/monitor/commonalert.go | 47 ++++----------------- pkg/mcclient/modules/mod_commonalert.go | 2 +- pkg/mcclient/options/monitor/commonalert.go | 43 +++++++++++++++++++ 3 files changed, 52 insertions(+), 40 deletions(-) create mode 100644 pkg/mcclient/options/monitor/commonalert.go diff --git a/cmd/climc/shell/monitor/commonalert.go b/cmd/climc/shell/monitor/commonalert.go index c53d4e9632..d14c418cec 100644 --- a/cmd/climc/shell/monitor/commonalert.go +++ b/cmd/climc/shell/monitor/commonalert.go @@ -1,47 +1,16 @@ package monitor import ( - "yunion.io/x/jsonutils" - - "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/cmd/climc/shell" "yunion.io/x/onecloud/pkg/mcclient/modules" - "yunion.io/x/onecloud/pkg/mcclient/options" + options "yunion.io/x/onecloud/pkg/mcclient/options/monitor" ) func init() { - type CommonAlertListOptions struct { - options.BaseListOptions - // 报警类型 - AlertType string `help:"common alert type" choices:"normal|system"` - Level string `help:"common alert notify level" choices:"normal|important|fatal"` - } - R(&CommonAlertListOptions{}, "commonalert-list", "List commonalert", func(s *mcclient.ClientSession, - args *CommonAlertListOptions) error { - params, err := options.ListStructToParams(args) - if err != nil { - return err - } - result, err := modules.CommonAlertManager.List(s, params) - if err != nil { - return nil - } - printList(result, modules.CommonAlertManager.GetColumns(s)) - return nil - }) - - type CommonAlertDeleteOptions struct { - ID string `help:"ID of alart"` - Force bool `help:"force to delete alert"` - } - R(&CommonAlertDeleteOptions{}, "commonalert-delete", "List commonalert", func(s *mcclient.ClientSession, - args *CommonAlertDeleteOptions) error { - params := jsonutils.NewDict() - params.Add(jsonutils.NewBool(args.Force), "force") - object, err := modules.CommonAlertManager.Delete(s, args.ID, params) - if err != nil { - return err - } - printObject(object) - return nil - }) + cmd := shell.NewResourceCmd(modules.CommonAlertManager) + cmd.List(new(options.CommonAlertListOptions)) + cmd.Show(new(options.CommonAlertShowOptions)) + cmd.Perform("enable", &options.CommonAlertShowOptions{}) + cmd.Perform("disable", &options.CommonAlertShowOptions{}) + cmd.Delete(new(options.CommonAlertDeleteOptions)) } diff --git a/pkg/mcclient/modules/mod_commonalert.go b/pkg/mcclient/modules/mod_commonalert.go index 1c7dda29d4..32e4adee95 100644 --- a/pkg/mcclient/modules/mod_commonalert.go +++ b/pkg/mcclient/modules/mod_commonalert.go @@ -21,7 +21,7 @@ func init() { func NewCommonAlertManager() *SCommonAlertManager { man := NewMonitorV2Manager("commonalert", "commonalerts", - []string{"id", "name", "level", "alert_type", "period", "recipients", "channel"}, + []string{"id", "name", "enabled", "level", "alert_type", "period", "recipients", "channel"}, []string{}) return &SCommonAlertManager{ ResourceManager: &man, diff --git a/pkg/mcclient/options/monitor/commonalert.go b/pkg/mcclient/options/monitor/commonalert.go new file mode 100644 index 0000000000..92174799cf --- /dev/null +++ b/pkg/mcclient/options/monitor/commonalert.go @@ -0,0 +1,43 @@ +package monitor + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type CommonAlertListOptions struct { + options.BaseListOptions + // 报警类型 + AlertType string `help:"common alert type" choices:"normal|system"` + Level string `help:"common alert notify level" choices:"normal|important|fatal"` +} + +func (o *CommonAlertListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} + +type CommonAlertShowOptions struct { + ID string `help:"ID of alart " json:"-"` +} + +func (o *CommonAlertShowOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +func (o *CommonAlertShowOptions) GetId() string { + return o.ID +} + +type CommonAlertDeleteOptions struct { + ID string `help:"ID of alart"` + Force bool `help:"force to delete alert"` +} + +func (o *CommonAlertDeleteOptions) GetId() string { + return o.ID +} + +func (o *CommonAlertDeleteOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +}