alert_notifications.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. )
  18. type AlertNotification struct {
  19. Id int64 `json:"id"`
  20. OrgId int64 `json:"-"`
  21. Name string `json:"name"`
  22. Type string `json:"type"`
  23. SendReminder bool `json:"sendReminder"`
  24. Frequency time.Duration `json:"frequency"`
  25. IsDefault bool `json:"isDefault"`
  26. Settings *simplejson.Json `json:"settings"`
  27. Created time.Time `json:"created"`
  28. Updated time.Time `json:"updated"`
  29. }
  30. type CreateAlertNotificationCommand struct {
  31. Name string `json:"name" binding:"Required"`
  32. Type string `json:"type" binding:"Required"`
  33. SendReminder bool `json:"sendReminder"`
  34. Frequency string `json:"frequency"`
  35. IsDefault bool `json:"isDefault"`
  36. Settings *simplejson.Json `json:"settings"`
  37. OrgId int64 `json:"-"`
  38. Result *AlertNotification
  39. }
  40. type UpdateAlertNotificationCommand struct {
  41. Id int64 `json:"id" binding:"Required"`
  42. Name string `json:"name" binding:"Required"`
  43. Type string `json:"type" binding:"Required"`
  44. SendReminder bool `json:"sendReminder"`
  45. Frequency string `json:"frequency"`
  46. IsDefault bool `json:"isDefault"`
  47. Settings *simplejson.Json `json:"settings" binding:"Required"`
  48. OrgId int64 `json:"-"`
  49. Result *AlertNotification
  50. }
  51. type DeleteAlertNotificationCommand struct {
  52. Id int64
  53. OrgId int64
  54. }
  55. type GetAlertNotificationsQuery struct {
  56. Name string
  57. Id int64
  58. OrgId int64
  59. Result *AlertNotification
  60. }
  61. type GetAlertNotificationsToSendQuery struct {
  62. Ids []int64
  63. OrgId int64
  64. Result []*AlertNotification
  65. }
  66. type GetAllAlertNotificationsQuery struct {
  67. OrgId int64
  68. Result []*AlertNotification
  69. }
  70. type AlertNotificationState struct {
  71. Id int64
  72. OrgId int64
  73. AlertId int64
  74. NotifierId int64
  75. SentAt int64
  76. State AlertNotificationStateType
  77. Version int64
  78. }
  79. type SetAlertNotificationStateToPendingCommand struct {
  80. State *AlertNotificationState
  81. }
  82. type SetAlertNotificationStateToCompleteCommand struct {
  83. State *AlertNotificationState
  84. }
  85. type GetNotificationStateQuery struct {
  86. OrgId int64
  87. AlertId int64
  88. NotifierId int64
  89. Result *AlertNotificationState
  90. }
  91. type InsertAlertNotificationCommand struct {
  92. OrgId int64
  93. AlertId int64
  94. NotifierId int64
  95. SentAt int64
  96. State AlertNotificationStateType
  97. }