mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(monitor): filter monitor_resource_alert by ip (#21221)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user