tech(alerting): add logging about failed notifications

This commit is contained in:
bergquist
2016-06-16 08:16:16 +02:00
parent 9a8416416d
commit b9b65cf2d4
4 changed files with 55 additions and 27 deletions
+19 -7
View File
@@ -20,6 +20,7 @@ type Engine struct {
handler AlertingHandler
ruleReader RuleReader
log log.Logger
notifier Notifier
}
func NewEngine() *Engine {
@@ -31,6 +32,7 @@ func NewEngine() *Engine {
handler: NewHandler(),
ruleReader: NewRuleReader(),
log: log.New("alerting.engine"),
notifier: NewNotifier(),
}
return e
@@ -129,13 +131,23 @@ func (e *Engine) resultHandler() {
}
func (e *Engine) saveState(result *AlertResult) {
cmd := &m.UpdateAlertStateCommand{
AlertId: result.AlertJob.Rule.Id,
NewState: result.State,
Info: result.Description,
}
query := &m.GetAlertByIdQuery{Id: result.AlertJob.Rule.Id}
bus.Dispatch(query)
if err := bus.Dispatch(cmd); err != nil {
e.log.Error("Failed to save state", "error", err)
if query.Result.ShouldUpdateState(result.State) {
cmd := &m.UpdateAlertStateCommand{
AlertId: result.AlertJob.Rule.Id,
NewState: result.State,
Info: result.Description,
}
if err := bus.Dispatch(cmd); err != nil {
e.log.Error("Failed to save state", "error", err)
}
e.log.Debug("will notify! about", "new state", result.State)
e.notifier.Notify(result)
} else {
e.log.Debug("state remains the same!")
}
}