Feature for repeated alerting in grafana
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user