Feature for repeated alerting in grafana

This commit is contained in:
John Baublitz
2018-06-04 13:19:13 +02:00
committed by bergquist
parent f5cf926364
commit e068be4c26
10 changed files with 55 additions and 2 deletions
+2
View File
@@ -122,6 +122,8 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
Handler: jsonAlert.Get("handler").MustInt64(),
Message: jsonAlert.Get("message").MustString(),
Frequency: frequency,
NotifyOnce: jsonAlert.Get("notifyOnce").MustBool(),
NotifyFreq: jsonAlert.Get("notifyFrequency").MustUint64(),
}
for _, condition := range jsonAlert.Get("conditions").MustArray() {
+4 -1
View File
@@ -32,7 +32,10 @@ func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model
func defaultShouldNotify(context *alerting.EvalContext) bool {
// Only notify on state change.
if context.PrevAlertState == context.Rule.State {
if context.PrevAlertState == context.Rule.State && context.Rule.NotifyOnce {
return false
}
if !context.Rule.NotifyOnce && context.Rule.NotifyEval != 0 {
return false
}
// Do not notify when we become OK for the first time.
+1
View File
@@ -88,6 +88,7 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
}
}
bus.Dispatch(&m.IncAlertEvalCommand{AlertId: evalContext.Rule.Id})
handler.notifier.SendIfNeeded(evalContext)
return nil
+6
View File
@@ -23,6 +23,9 @@ type Rule struct {
State m.AlertStateType
Conditions []Condition
Notifications []int64
NotifyOnce bool
NotifyFreq uint64
NotifyEval uint64
}
type ValidationError struct {
@@ -97,6 +100,9 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
model.Name = ruleDef.Name
model.Message = ruleDef.Message
model.Frequency = ruleDef.Frequency
model.NotifyOnce = ruleDef.NotifyOnce
model.NotifyFreq = ruleDef.NotifyFreq
model.NotifyEval = ruleDef.NotifyEval
model.State = ruleDef.State
model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data"))
model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting"))