alert_notifications.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. )
  7. var (
  8. ErrNotificationFrequencyNotFound = errors.New("Notification frequency not specified")
  9. ErrAlertNotificationStateNotFound = errors.New("alert notification state not found")
  10. ErrAlertNotificationStateVersionConflict = errors.New("alert notification state update version conflict")
  11. ErrAlertNotificationStateAlreadyExist = errors.New("alert notification state already exists.")
  12. )
  13. type AlertNotificationStateType string
  14. var (
  15. AlertNotificationStatePending = AlertNotificationStateType("pending")
  16. AlertNotificationStateCompleted = AlertNotificationStateType("completed")
  17. AlertNotificationStateUnknown = AlertNotificationStateType("unknown")
  18. )
  19. type AlertNotification struct {
  20. Id int64 `json:"id"`
  21. OrgId int64 `json:"-"`
  22. Name string `json:"name"`
  23. Type string `json:"type"`
  24. SendReminder bool `json:"sendReminder"`
  25. Frequency time.Duration `json:"frequency"`
  26. IsDefault bool `json:"isDefault"`
  27. Settings *simplejson.Json `json:"settings"`
  28. Created time.Time `json:"created"`
  29. Updated time.Time `json:"updated"`
  30. }
  31. type CreateAlertNotificationCommand struct {
  32. Name string `json:"name" binding:"Required"`
  33. Type string `json:"type" binding:"Required"`
  34. SendReminder bool `json:"sendReminder"`
  35. Frequency string `json:"frequency"`
  36. IsDefault bool `json:"isDefault"`
  37. Settings *simplejson.Json `json:"settings"`
  38. OrgId int64 `json:"-"`
  39. Result *AlertNotification
  40. }
  41. type UpdateAlertNotificationCommand struct {
  42. Id int64 `json:"id" binding:"Required"`
  43. Name string `json:"name" binding:"Required"`
  44. Type string `json:"type" binding:"Required"`
  45. SendReminder bool `json:"sendReminder"`
  46. Frequency string `json:"frequency"`
  47. IsDefault bool `json:"isDefault"`
  48. Settings *simplejson.Json `json:"settings" binding:"Required"`
  49. OrgId int64 `json:"-"`
  50. Result *AlertNotification
  51. }
  52. type DeleteAlertNotificationCommand struct {
  53. Id int64
  54. OrgId int64
  55. }
  56. type GetAlertNotificationsQuery struct {
  57. Name string
  58. Id int64
  59. OrgId int64
  60. Result *AlertNotification
  61. }
  62. type GetAlertNotificationsToSendQuery struct {
  63. Ids []int64
  64. OrgId int64
  65. Result []*AlertNotification
  66. }
  67. type GetAllAlertNotificationsQuery struct {
  68. OrgId int64
  69. Result []*AlertNotification
  70. }
  71. type AlertNotificationState struct {
  72. Id int64
  73. OrgId int64
  74. AlertId int64
  75. NotifierId int64
  76. State AlertNotificationStateType
  77. Version int64
  78. UpdatedAt int64
  79. AlertRuleStateUpdatedVersion int64
  80. }
  81. type SetAlertNotificationStateToPendingCommand struct {
  82. Id int64
  83. AlertRuleStateUpdatedVersion int64
  84. Version int64
  85. ResultVersion int64
  86. }
  87. type SetAlertNotificationStateToCompleteCommand struct {
  88. Id int64
  89. Version int64
  90. }
  91. type GetOrCreateNotificationStateQuery struct {
  92. OrgId int64
  93. AlertId int64
  94. NotifierId int64
  95. Result *AlertNotificationState
  96. }