fix(monitor): filter alerts by monitor_resource_id (#20137)

This commit is contained in:
Zexi Li
2024-04-25 17:07:12 +08:00
committed by GitHub
parent 1dc8fcdce9
commit 1adf085b4b
3 changed files with 8 additions and 2 deletions
+1
View File
@@ -155,6 +155,7 @@ type AlertListInput struct {
apis.StatusStandaloneResourceListInput
// 以报警是否启用/禁用过滤列表
// Enabled *bool `json:"enabled"`
MonitorResourceId []string `json:"monitor_resource_id"`
}
type AlertDetails struct {
+3 -2
View File
@@ -27,8 +27,9 @@ import (
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"`
AlertType string `help:"common alert type" choices:"normal|system"`
Level string `help:"common alert notify level" choices:"normal|important|fatal"`
MonitorResourceId []string `help:"monitor resource id"`
}
func (o *CommonAlertListOptions) Params() (jsonutils.JSONObject, error) {
+4
View File
@@ -292,6 +292,10 @@ func (man *SAlertManager) ListItemFilter(
if err != nil {
return nil, errors.Wrap(err, "SEnabledResourceBaseManager.ListItemFilter")
}
if len(input.MonitorResourceId) != 0 {
sq := MonitorResourceAlertManager.Query("alert_id").In("monitor_resource_id", input.MonitorResourceId).SubQuery()
q = q.In("id", sq)
}
return q, nil
}