interfaces.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package alerting
  2. import (
  3. "context"
  4. "time"
  5. "github.com/grafana/grafana/pkg/models"
  6. )
  7. type EvalHandler interface {
  8. Eval(evalContext *EvalContext)
  9. }
  10. type Scheduler interface {
  11. Tick(time time.Time, execQueue chan *Job)
  12. Update(rules []*Rule)
  13. }
  14. type Notifier interface {
  15. Notify(evalContext *EvalContext) error
  16. GetType() string
  17. NeedsImage() bool
  18. // ShouldNotify checks this evaluation should send an alert notification
  19. ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.AlertNotificationState) bool
  20. GetNotifierId() int64
  21. GetIsDefault() bool
  22. GetSendReminder() bool
  23. GetFrequency() time.Duration
  24. }
  25. type notifierState struct {
  26. notifier Notifier
  27. state *models.AlertNotificationState
  28. }
  29. type notifierStateSlice []*notifierState
  30. func (notifiers notifierStateSlice) ShouldUploadImage() bool {
  31. for _, ns := range notifiers {
  32. if ns.notifier.NeedsImage() {
  33. return true
  34. }
  35. }
  36. return false
  37. }
  38. type ConditionResult struct {
  39. Firing bool
  40. NoDataFound bool
  41. Operator string
  42. EvalMatches []*EvalMatch
  43. }
  44. type Condition interface {
  45. Eval(result *EvalContext) (*ConditionResult, error)
  46. }