|
|
@@ -1,6 +1,7 @@
|
|
|
package alerting
|
|
|
|
|
|
import (
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
@@ -21,7 +22,9 @@ func NewEvalHandler() *DefaultEvalHandler {
|
|
|
|
|
|
func (e *DefaultEvalHandler) Eval(context *EvalContext) {
|
|
|
firing := true
|
|
|
- for _, condition := range context.Rule.Conditions {
|
|
|
+ firingEval := ""
|
|
|
+ for i := 0; i < len(context.Rule.Conditions); i++ {
|
|
|
+ condition := context.Rule.Conditions[i]
|
|
|
cr, err := condition.Eval(context)
|
|
|
if err != nil {
|
|
|
context.Error = err
|
|
|
@@ -33,15 +36,24 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
|
|
|
}
|
|
|
|
|
|
// calculating Firing based on operator
|
|
|
+ operator := "AND"
|
|
|
if cr.Operator == "or" {
|
|
|
firing = firing || cr.Firing
|
|
|
+ operator = "OR"
|
|
|
} else {
|
|
|
firing = firing && cr.Firing
|
|
|
}
|
|
|
|
|
|
+ if i > 0 {
|
|
|
+ firingEval = "[" + firingEval + " " + operator + " " + strconv.FormatBool(cr.Firing) + "]"
|
|
|
+ } else {
|
|
|
+ firingEval = strconv.FormatBool(firing)
|
|
|
+ }
|
|
|
+
|
|
|
context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...)
|
|
|
}
|
|
|
|
|
|
+ context.FiringEval = firingEval + " = " + strconv.FormatBool(firing)
|
|
|
context.Firing = firing
|
|
|
context.EndTime = time.Now()
|
|
|
elapsedTime := context.EndTime.Sub(context.StartTime) / time.Millisecond
|