fix(climc): add list monitorresource cmd (#16046)

This commit is contained in:
Zexi Li
2023-02-27 22:00:10 +08:00
committed by GitHub
parent 9e4349d13b
commit e8037f7bc3
4 changed files with 17 additions and 5 deletions

View File

@@ -22,4 +22,5 @@ import (
func init() {
cmd := NewResourceCmd(modules.MonitorResourceManager)
cmd.GetProperty(new(options.MonitorResourceJointAlertOptions))
cmd.List(new(options.MonitorResourceListOptions))
}

View File

@@ -42,7 +42,7 @@ func init() {
func NewMonitorResourceManager() *SMonitorResourceManager {
man := modules.NewMonitorV2Manager("monitorresource", "monitorresources",
[]string{"id", "name", "res_type", "res_id", "alert_state"},
[]string{"id", "name", "res_type", "res_id", "alert_state", "status"},
[]string{})
return &SMonitorResourceManager{
ResourceManager: &man,

View File

@@ -30,3 +30,14 @@ func (o *MonitorResourceJointAlertOptions) Params() (jsonutils.JSONObject, error
func (o *MonitorResourceJointAlertOptions) Property() string {
return "alert"
}
type MonitorResourceListOptions struct {
options.BaseListOptions
ResType string `help:"filter by resource type" json:"res_type"`
ResId []string `help:"filter by resource id" json:"res_id"`
ResName string `help:"filter by resource name" json:"res_name"`
}
func (o *MonitorResourceListOptions) Params() (jsonutils.JSONObject, error) {
return options.ListStructToParams(o)
}

View File

@@ -499,14 +499,14 @@ func (manager *SMonitorResourceManager) SyncManually(ctx context.Context) {
func (manager *SMonitorResourceManager) SyncResources(ctx context.Context, mss *MonitorResModelSets) error {
userCred := auth.AdminCredential()
errs := make([]error, 0)
log.Infoln("start sync")
log.Infof("start sync monitorresource")
aliveIds := make([]string, 0)
for _, set := range mss.ModelSetList() {
setRv := reflect.ValueOf(set)
needSync, typ := manager.GetSetType(set)
log.Infof("Type: %s,length: %d", typ, len(setRv.MapKeys()))
log.Infof("Type: %s, length: %d", typ, len(setRv.MapKeys()))
if !needSync {
log.Infof("Type: %s don't sync", typ)
log.Infof("Type: %s don't need sync", typ)
continue
}
for _, kRv := range setRv.MapKeys() {
@@ -517,7 +517,7 @@ func (manager *SMonitorResourceManager) SyncResources(ctx context.Context, mss *
}
res, err := MonitorResourceManager.GetMonitorResources(input)
if err != nil {
return errors.Wrap(err, "GetMonitorResources err")
return errors.Wrapf(err, "GetMonitorResources by input: %s", jsonutils.Marshal(input).String())
}
if mRv.IsValid() {
aliveIds = append(aliveIds, kRv.String())