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

This commit is contained in:
Zexi Li
2022-11-07 02:17:18 +08:00
committed by GitHub
parent f5feb853b2
commit 8958913af2
5 changed files with 28 additions and 17 deletions

View File

@@ -22,5 +22,5 @@ import (
func init() {
cmd := shell.NewResourceCmd(modules.MonitorResourceManager)
cmd.Get("", new(options.MonitorResourceJointAlertOptions))
cmd.GetProperty(new(options.MonitorResourceJointAlertOptions))
}

View File

@@ -188,13 +188,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 {

View File

@@ -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"
}

View File

@@ -565,7 +565,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)

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),
}
}