|
@@ -30,34 +30,35 @@ func NewResultHandler() *DefaultResultHandler {
|
|
|
func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
|
|
func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
|
|
|
oldState := evalContext.Rule.State
|
|
oldState := evalContext.Rule.State
|
|
|
|
|
|
|
|
- exeuctionError := ""
|
|
|
|
|
|
|
+ executionError := ""
|
|
|
annotationData := simplejson.New()
|
|
annotationData := simplejson.New()
|
|
|
if evalContext.Error != nil {
|
|
if evalContext.Error != nil {
|
|
|
handler.log.Error("Alert Rule Result Error", "ruleId", evalContext.Rule.Id, "error", evalContext.Error)
|
|
handler.log.Error("Alert Rule Result Error", "ruleId", evalContext.Rule.Id, "error", evalContext.Error)
|
|
|
evalContext.Rule.State = m.AlertStateExecError
|
|
evalContext.Rule.State = m.AlertStateExecError
|
|
|
- exeuctionError = evalContext.Error.Error()
|
|
|
|
|
- annotationData.Set("errorMessage", exeuctionError)
|
|
|
|
|
|
|
+ executionError = evalContext.Error.Error()
|
|
|
|
|
+ annotationData.Set("errorMessage", executionError)
|
|
|
} else if evalContext.Firing {
|
|
} else if evalContext.Firing {
|
|
|
evalContext.Rule.State = m.AlertStateAlerting
|
|
evalContext.Rule.State = m.AlertStateAlerting
|
|
|
annotationData = simplejson.NewFromAny(evalContext.EvalMatches)
|
|
annotationData = simplejson.NewFromAny(evalContext.EvalMatches)
|
|
|
} else {
|
|
} else {
|
|
|
- // handle no data case
|
|
|
|
|
if evalContext.NoDataFound {
|
|
if evalContext.NoDataFound {
|
|
|
- evalContext.Rule.State = evalContext.Rule.NoDataState
|
|
|
|
|
|
|
+ if evalContext.Rule.NoDataState != m.NoDataKeepState {
|
|
|
|
|
+ evalContext.Rule.State = evalContext.Rule.NoDataState.ToAlertState()
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
evalContext.Rule.State = m.AlertStateOK
|
|
evalContext.Rule.State = m.AlertStateOK
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
countStateResult(evalContext.Rule.State)
|
|
countStateResult(evalContext.Rule.State)
|
|
|
- if evalContext.Rule.State != oldState {
|
|
|
|
|
|
|
+ if handler.shouldUpdateAlertState(evalContext, oldState) {
|
|
|
handler.log.Info("New state change", "alertId", evalContext.Rule.Id, "newState", evalContext.Rule.State, "oldState", oldState)
|
|
handler.log.Info("New state change", "alertId", evalContext.Rule.Id, "newState", evalContext.Rule.State, "oldState", oldState)
|
|
|
|
|
|
|
|
cmd := &m.SetAlertStateCommand{
|
|
cmd := &m.SetAlertStateCommand{
|
|
|
AlertId: evalContext.Rule.Id,
|
|
AlertId: evalContext.Rule.Id,
|
|
|
OrgId: evalContext.Rule.OrgId,
|
|
OrgId: evalContext.Rule.OrgId,
|
|
|
State: evalContext.Rule.State,
|
|
State: evalContext.Rule.State,
|
|
|
- Error: exeuctionError,
|
|
|
|
|
|
|
+ Error: executionError,
|
|
|
EvalData: annotationData,
|
|
EvalData: annotationData,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -91,6 +92,10 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (handler *DefaultResultHandler) shouldUpdateAlertState(evalContext *EvalContext, oldState m.AlertStateType) bool {
|
|
|
|
|
+ return evalContext.Rule.State != oldState
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func countStateResult(state m.AlertStateType) {
|
|
func countStateResult(state m.AlertStateType) {
|
|
|
switch state {
|
|
switch state {
|
|
|
case m.AlertStateAlerting:
|
|
case m.AlertStateAlerting:
|