mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(alerting): skip if operator does not exist
This commit is contained in:
parent
1f990da5c3
commit
e80000ce94
@ -19,6 +19,7 @@ var operators map[string]compareFn = map[string]compareFn{
|
|||||||
">=": func(num1, num2 float64) bool { return num1 >= num2 },
|
">=": func(num1, num2 float64) bool { return num1 >= num2 },
|
||||||
"<": func(num1, num2 float64) bool { return num1 < num2 },
|
"<": func(num1, num2 float64) bool { return num1 < num2 },
|
||||||
"<=": func(num1, num2 float64) bool { return num1 <= num2 },
|
"<=": func(num1, num2 float64) bool { return num1 <= num2 },
|
||||||
|
"": func(num1, num2 float64) bool { return false },
|
||||||
}
|
}
|
||||||
|
|
||||||
var aggregator map[string]aggregationFn = map[string]aggregationFn{
|
var aggregator map[string]aggregationFn = map[string]aggregationFn{
|
||||||
@ -40,14 +41,18 @@ func (this *ExecutorImpl) Execute(rule m.AlertRule, responseQueue chan *AlertRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlice) *AlertResult {
|
func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlice) *AlertResult {
|
||||||
for _, v := range series {
|
for _, serie := range series {
|
||||||
var aggValue = aggregator[rule.Aggregator](v)
|
if aggregator[rule.Aggregator] == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if rule.CritOperator != "" && operators[rule.CritOperator](float64(rule.CritLevel), aggValue) {
|
var aggValue = aggregator[rule.Aggregator](serie)
|
||||||
|
|
||||||
|
if operators[rule.CritOperator](float64(rule.CritLevel), aggValue) {
|
||||||
return &AlertResult{State: m.AlertStateCritical, Id: rule.Id, ActualValue: aggValue}
|
return &AlertResult{State: m.AlertStateCritical, Id: rule.Id, ActualValue: aggValue}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rule.WarnOperator != "" && operators[rule.WarnOperator](float64(rule.WarnLevel), aggValue) {
|
if operators[rule.WarnOperator](float64(rule.WarnLevel), aggValue) {
|
||||||
return &AlertResult{State: m.AlertStateWarn, Id: rule.Id, ActualValue: aggValue}
|
return &AlertResult{State: m.AlertStateWarn, Id: rule.Id, ActualValue: aggValue}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user