notitfiers: avoid ShouldNotify duplication

This commit is contained in:
Corentin Chary
2018-03-15 10:48:29 +01:00
parent 777c1024c9
commit d4d2b6d7da
16 changed files with 7 additions and 60 deletions
+6
View File
@@ -27,15 +27,21 @@ 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 {
return false
}
// Do not notify when we become OK for the first time.
if (context.PrevAlertState == m.AlertStatePending) && (context.Rule.State == m.AlertStateOK) {
return false
}
return true
}
func (n *NotifierBase) ShouldNotify(context *alerting.EvalContext) bool {
return defaultShouldNotify(context)
}
func (n *NotifierBase) GetType() string {
return n.Type
}