bugfix:commonalert

1.suggestrule cli 调整
This commit is contained in:
zhaoxiangchun
2020-09-25 10:41:45 +08:00
parent 475c81c58c
commit 6037c84a58
3 changed files with 52 additions and 40 deletions
+8 -39
View File
@@ -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))
}
+1 -1
View File
@@ -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,
@@ -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)
}