interfaces.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. GetNotifierUid() string
  21. GetIsDefault() bool
  22. GetSendReminder() bool
  23. GetDisableResolveMessage() bool
  24. GetFrequency() time.Duration
  25. }
  26. type notifierState struct {
  27. notifier Notifier
  28. state *models.AlertNotificationState
  29. }
  30. type notifierStateSlice []*notifierState
  31. func (notifiers notifierStateSlice) ShouldUploadImage() bool {
  32. for _, ns := range notifiers {
  33. if ns.notifier.NeedsImage() {
  34. return true
  35. }
  36. }
  37. return false
  38. }
  39. type ConditionResult struct {
  40. Firing bool
  41. NoDataFound bool
  42. Operator string
  43. EvalMatches []*EvalMatch
  44. }
  45. type Condition interface {
  46. Eval(result *EvalContext) (*ConditionResult, error)
  47. }