result_handler.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package alerting
  2. import "github.com/grafana/grafana/pkg/log"
  3. type ResultHandler interface {
  4. Handle(result *AlertResultContext)
  5. }
  6. type ResultHandlerImpl struct {
  7. notifier Notifier
  8. log log.Logger
  9. }
  10. func NewResultHandler() *ResultHandlerImpl {
  11. return &ResultHandlerImpl{
  12. log: log.New("alerting.responseHandler"),
  13. //notifier: NewNotifier(),
  14. }
  15. }
  16. func (handler *ResultHandlerImpl) Handle(result *AlertResultContext) {
  17. // if handler.shouldUpdateState(result) {
  18. // cmd := &m.UpdateAlertStateCommand{
  19. // AlertId: result.Rule.Id,
  20. // State: result.Rule.Severity,
  21. // Info: result.Description,
  22. // OrgId: result.Rule.OrgId,
  23. // TriggeredAlerts: simplejson.NewFromAny(result.Details),
  24. // }
  25. //
  26. // if err := bus.Dispatch(cmd); err != nil {
  27. // handler.log.Error("Failed to save state", "error", err)
  28. // }
  29. //
  30. // handler.log.Debug("will notify about new state", "new state", result.State)
  31. // handler.notifier.Notify(result)
  32. // }
  33. }
  34. func (handler *ResultHandlerImpl) shouldUpdateState(result *AlertResultContext) bool {
  35. // query := &m.GetLastAlertStateQuery{
  36. // AlertId: result.AlertJob.Rule.Id,
  37. // OrgId: result.AlertJob.Rule.OrgId,
  38. // }
  39. //
  40. // if err := bus.Dispatch(query); err != nil {
  41. // log.Error2("Failed to read last alert state", "error", err)
  42. // return false
  43. // }
  44. //
  45. // if query.Result == nil {
  46. // return true
  47. // }
  48. //
  49. // lastExecution := query.Result.Created
  50. // asdf := result.StartTime.Add(time.Minute * -15)
  51. // olderThen15Min := lastExecution.Before(asdf)
  52. // changedState := query.Result.State != result.State
  53. //
  54. // return changedState || olderThen15Min
  55. return false
  56. }