fix(monitor): only query enabled host for alerting (#15301)

This commit is contained in:
Zexi Li
2022-11-07 02:17:59 +08:00
committed by GitHub
parent f472e7aa57
commit 53161cb0f9
5 changed files with 28 additions and 17 deletions
+1 -1
View File
@@ -21,5 +21,5 @@ import (
func init() {
cmd := NewResourceCmd(modules.MonitorResourceManager)
cmd.Get("", new(options.MonitorResourceJointAlertOptions))
cmd.GetProperty(new(options.MonitorResourceJointAlertOptions))
}
+12 -7
View File
@@ -190,13 +190,18 @@ type EvalMatch struct {
type AlertTestRunOutput struct {
apis.Meta
Firing bool `json:"firing"`
EvalMatches []*EvalMatch `json:"eval_matches"`
Logs []*ResultLogEntry `json:"logs"`
Error error `json:"error"`
ConditionEvals string `json:"condition_evals"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Firing bool `json:"firing"`
IsTestRun bool `json:"is_test_run"`
IsDebug bool `json:"is_debug"`
EvalMatches []*EvalMatch `json:"eval_matches"`
AlertOKEvalMatches []*EvalMatch `json:"alert_ok_eval_matches"`
Logs []*ResultLogEntry `json:"logs"`
Error error `json:"error"`
ConditionEvals string `json:"condition_evals"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
NoDataFound bool `json:"no_data_found"`
PrevAlertState string `json:"prev_alert_state"`
}
type AlertPauseInput struct {
@@ -27,6 +27,6 @@ func (o *MonitorResourceJointAlertOptions) Params() (jsonutils.JSONObject, error
return options.ListStructToParams(o)
}
func (o *MonitorResourceJointAlertOptions) GetId() string {
func (o *MonitorResourceJointAlertOptions) Property() string {
return "alert"
}
+2 -1
View File
@@ -566,7 +566,8 @@ func (c *QueryCondition) getOnecloudResources() ([]jsonutils.JSONObject, error)
switch c.ResType {
case monitor.METRIC_RES_TYPE_HOST:
query := jsonutils.NewDict()
query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
query.Set("host_type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
query.Set("enabled", jsonutils.NewInt(1))
allResources, err = ListAllResources(&mc_mds.Hosts, query)
case monitor.METRIC_RES_TYPE_GUEST:
allResources, err = ListAllResources(&mc_mds.Servers, query)
+12 -7
View File
@@ -254,13 +254,18 @@ func (_ AlertRuleTester) DoTest(ruleDef *models.SAlert, userCred mcclient.TokenC
func (ctx *EvalContext) ToTestRunResult() *monitor.AlertTestRunOutput {
return &monitor.AlertTestRunOutput{
Firing: ctx.Firing,
EvalMatches: ctx.EvalMatches,
Logs: ctx.Logs,
Error: ctx.Error,
ConditionEvals: ctx.ConditionEvals,
StartTime: ctx.StartTime,
EndTime: ctx.EndTime,
Firing: ctx.Firing,
IsTestRun: ctx.IsTestRun,
IsDebug: ctx.IsDebug,
EvalMatches: ctx.EvalMatches,
AlertOKEvalMatches: ctx.AlertOkEvalMatches,
Logs: ctx.Logs,
Error: ctx.Error,
ConditionEvals: ctx.ConditionEvals,
StartTime: ctx.StartTime,
EndTime: ctx.EndTime,
NoDataFound: ctx.NoDataFound,
PrevAlertState: string(ctx.PrevAlertState),
}
}