interfaces.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Notifier is responsible for sending alert notifications.
  15. type Notifier interface {
  16. Notify(evalContext *EvalContext) error
  17. GetType() string
  18. NeedsImage() bool
  19. // ShouldNotify checks this evaluation should send an alert notification
  20. ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.AlertNotificationState) bool
  21. GetNotifierUID() string
  22. GetIsDefault() bool
  23. GetSendReminder() bool
  24. GetDisableResolveMessage() bool
  25. GetFrequency() time.Duration
  26. }
  27. type notifierState struct {
  28. notifier Notifier
  29. state *models.AlertNotificationState
  30. }
  31. type notifierStateSlice []*notifierState
  32. func (notifiers notifierStateSlice) ShouldUploadImage() bool {
  33. for _, ns := range notifiers {
  34. if ns.notifier.NeedsImage() {
  35. return true
  36. }
  37. }
  38. return false
  39. }
  40. // ConditionResult is the result of a condition evaluation.
  41. type ConditionResult struct {
  42. Firing bool
  43. NoDataFound bool
  44. Operator string
  45. EvalMatches []*EvalMatch
  46. }
  47. // Condition is responsible for evaluating an alert condition.
  48. type Condition interface {
  49. Eval(result *EvalContext) (*ConditionResult, error)
  50. }