base.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package notifiers
  2. import (
  3. "github.com/grafana/grafana/pkg/components/simplejson"
  4. m "github.com/grafana/grafana/pkg/models"
  5. "github.com/grafana/grafana/pkg/services/alerting"
  6. )
  7. type NotifierBase struct {
  8. Name string
  9. Type string
  10. Id int64
  11. IsDeault bool
  12. UploadImage bool
  13. }
  14. func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model *simplejson.Json) NotifierBase {
  15. uploadImage := model.Get("uploadImage").MustBool(false)
  16. return NotifierBase{
  17. Id: id,
  18. Name: name,
  19. IsDeault: isDefault,
  20. Type: notifierType,
  21. UploadImage: uploadImage,
  22. }
  23. }
  24. func defaultShouldNotify(context *alerting.EvalContext) bool {
  25. if context.PrevAlertState == context.Rule.State {
  26. return false
  27. }
  28. if (context.PrevAlertState == m.AlertStatePending) && (context.Rule.State == m.AlertStateOK) {
  29. return false
  30. }
  31. return true
  32. }
  33. func (n *NotifierBase) GetType() string {
  34. return n.Type
  35. }
  36. func (n *NotifierBase) NeedsImage() bool {
  37. return n.UploadImage
  38. }
  39. func (n *NotifierBase) GetNotifierId() int64 {
  40. return n.Id
  41. }
  42. func (n *NotifierBase) GetIsDefault() bool {
  43. return n.IsDeault
  44. }