@@ -11,7 +11,7 @@ import (
11
11
)
12
12
13
13
var (
14
- descriptionFmt = "Actual value: %1.2f for %s"
14
+ descriptionFmt = "Actual value: %1.2f for %s. "
15
15
)
16
16
17
17
type ExecutorImpl struct {
@@ -95,30 +95,46 @@ func (e *ExecutorImpl) GetRequestForAlertRule(rule *AlertRule, datasource *m.Dat
95
95
func (e * ExecutorImpl ) evaluateRule (rule * AlertRule , series tsdb.TimeSeriesSlice ) * AlertResult {
96
96
e .log .Debug ("Evaluating Alerting Rule" , "seriesCount" , len (series ), "ruleName" , rule .Name )
97
97
98
+ triggeredAlert := make ([]* TriggeredAlert , 0 )
99
+
98
100
for _ , serie := range series {
99
101
e .log .Debug ("Evaluating series" , "series" , serie .Name )
100
102
transformedValue , _ := rule .Transformer .Transform (serie )
101
103
102
104
critResult := evalCondition (rule .Critical , transformedValue )
103
105
e .log .Debug ("Alert execution Crit" , "name" , serie .Name , "transformedValue" , transformedValue , "operator" , rule .Critical .Operator , "level" , rule .Critical .Level , "result" , critResult )
104
106
if critResult {
105
- return & AlertResult {
107
+ triggeredAlert = append ( triggeredAlert , & TriggeredAlert {
106
108
State : alertstates .Critical ,
107
109
ActualValue : transformedValue ,
108
- Description : fmt . Sprintf ( descriptionFmt , transformedValue , serie .Name ) ,
109
- }
110
+ Name : serie .Name ,
111
+ })
110
112
}
111
113
112
114
warnResult := evalCondition (rule .Warning , transformedValue )
113
115
e .log .Debug ("Alert execution Warn" , "name" , serie .Name , "transformedValue" , transformedValue , "operator" , rule .Warning .Operator , "level" , rule .Warning .Level , "result" , warnResult )
114
116
if warnResult {
115
- return & AlertResult {
117
+ triggeredAlert = append ( triggeredAlert , & TriggeredAlert {
116
118
State : alertstates .Warn ,
117
- Description : fmt .Sprintf (descriptionFmt , transformedValue , serie .Name ),
118
119
ActualValue : transformedValue ,
119
- }
120
+ Name : serie .Name ,
121
+ })
122
+ }
123
+ }
124
+
125
+ executionState := alertstates .Ok
126
+ description := ""
127
+ for _ , raised := range triggeredAlert {
128
+ if raised .State == alertstates .Critical {
129
+ executionState = alertstates .Critical
120
130
}
131
+
132
+ if executionState != alertstates .Critical && raised .State == alertstates .Warn {
133
+ executionState = alertstates .Warn
134
+ }
135
+
136
+ description += fmt .Sprintf (descriptionFmt , raised .ActualValue , raised .Name )
121
137
}
122
138
123
- return & AlertResult {State : alertstates . Ok , Description : "Alert is OK!" }
139
+ return & AlertResult {State : executionState , Description : description , TriggeredAlerts : triggeredAlert }
124
140
}
0 commit comments