Skip to content

Commit

Permalink
fix(monitor): filter alerts by monitor_resource_id (#20137)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Apr 25, 2024
1 parent 1dc8fcd commit 1adf085
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/apis/monitor/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type AlertListInput struct {
apis.StatusStandaloneResourceListInput
// 以报警是否启用/禁用过滤列表
// Enabled *bool `json:"enabled"`
MonitorResourceId []string `json:"monitor_resource_id"`
}

type AlertDetails struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/mcclient/options/monitor/commonalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitor/models/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1adf085

Please sign in to comment.