mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(climc): add list monitorresource cmd (#16046)
This commit is contained in:
@@ -22,4 +22,5 @@ import (
|
||||
func init() {
|
||||
cmd := NewResourceCmd(modules.MonitorResourceManager)
|
||||
cmd.GetProperty(new(options.MonitorResourceJointAlertOptions))
|
||||
cmd.List(new(options.MonitorResourceListOptions))
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user