diff --git a/pkg/mcclient/modules/monitor/mod_monitor_resource.go b/pkg/mcclient/modules/monitor/mod_monitor_resource.go index 2c7e6d4da7..fc29e20dbb 100644 --- a/pkg/mcclient/modules/monitor/mod_monitor_resource.go +++ b/pkg/mcclient/modules/monitor/mod_monitor_resource.go @@ -42,7 +42,7 @@ func init() { func NewMonitorResourceManager() *SMonitorResourceManager { man := modules.NewMonitorV2Manager("monitorresource", "monitorresources", - []string{"id", "name", "res_type", "res_id", "alert_state", "status"}, + []string{"id", "name", "res_type", "res_id", "alert_state", "status", "data"}, []string{}) return &SMonitorResourceManager{ ResourceManager: &man, diff --git a/pkg/mcclient/options/monitor/monitor_resource_alert.go b/pkg/mcclient/options/monitor/monitor_resource_alert.go index 9615adacf7..42a9905c58 100644 --- a/pkg/mcclient/options/monitor/monitor_resource_alert.go +++ b/pkg/mcclient/options/monitor/monitor_resource_alert.go @@ -27,6 +27,7 @@ type MonitorResourceAlertListOptions struct { Alerting bool `help:"search alerting resource" json:"alerting"` SendState string `json:"send_state"` AllState bool `help:"Show all state" json:"all_state"` + Ip string `help:"IP address" json:"ip"` } func (o *MonitorResourceAlertListOptions) GetMasterOpt() string { diff --git a/pkg/monitor/models/monitor_resource_alert.go b/pkg/monitor/models/monitor_resource_alert.go index fec22a8373..cc04a96f40 100644 --- a/pkg/monitor/models/monitor_resource_alert.go +++ b/pkg/monitor/models/monitor_resource_alert.go @@ -16,6 +16,7 @@ package models import ( "context" + "strings" "time" "yunion.io/x/jsonutils" @@ -229,6 +230,30 @@ func (m *SMonitorResourceAlertManager) ListItemFilter(ctx context.Context, q *sq return q, nil } +func (m *SMonitorResourceAlertManager) CustomizeFilterList(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*db.CustomizeListFilters, error) { + filters := db.NewCustomizeListFilters() + + if query.Contains("ip") { + ip, _ := query.GetString("ip") + ipF := func(obj jsonutils.JSONObject) (bool, error) { + match := new(monitor.EvalMatch) + if err := obj.Unmarshal(match, "data"); err != nil { + log.Warningf("unmarshal data of object %s: %v", obj, err) + return false, nil + } + if tagIp, ok := match.Tags["ip"]; ok { + if strings.Contains(tagIp, ip) { + return true, nil + } + } + return false, nil + } + filters.Append(ipF) + } + + return filters, nil +} + func (man *SMonitorResourceAlertManager) FetchCustomizeColumns( ctx context.Context, userCred mcclient.TokenCredential,