alert_notifications.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. ErrAlertNotificationFailedGenerateUniqueUid = errors.New("Failed to generate unique alert notification uid")
  13. )
  14. type AlertNotificationStateType string
  15. var (
  16. AlertNotificationStatePending = AlertNotificationStateType("pending")
  17. AlertNotificationStateCompleted = AlertNotificationStateType("completed")
  18. AlertNotificationStateUnknown = AlertNotificationStateType("unknown")
  19. )
  20. type AlertNotification struct {
  21. Id int64 `json:"id"`
  22. Uid string `json:"-"`
  23. OrgId int64 `json:"-"`
  24. Name string `json:"name"`
  25. Type string `json:"type"`
  26. SendReminder bool `json:"sendReminder"`
  27. DisableResolveMessage bool `json:"disableResolveMessage"`
  28. Frequency time.Duration `json:"frequency"`
  29. IsDefault bool `json:"isDefault"`
  30. Settings *simplejson.Json `json:"settings"`
  31. Created time.Time `json:"created"`
  32. Updated time.Time `json:"updated"`
  33. }
  34. type CreateAlertNotificationCommand struct {
  35. Uid string `json:"-"`
  36. Name string `json:"name" binding:"Required"`
  37. Type string `json:"type" binding:"Required"`
  38. SendReminder bool `json:"sendReminder"`
  39. DisableResolveMessage bool `json:"disableResolveMessage"`
  40. Frequency string `json:"frequency"`
  41. IsDefault bool `json:"isDefault"`
  42. Settings *simplejson.Json `json:"settings"`
  43. OrgId int64 `json:"-"`
  44. Result *AlertNotification
  45. }
  46. type UpdateAlertNotificationCommand struct {
  47. Id int64 `json:"id" binding:"Required"`
  48. Name string `json:"name" binding:"Required"`
  49. Type string `json:"type" binding:"Required"`
  50. SendReminder bool `json:"sendReminder"`
  51. DisableResolveMessage bool `json:"disableResolveMessage"`
  52. Frequency string `json:"frequency"`
  53. IsDefault bool `json:"isDefault"`
  54. Settings *simplejson.Json `json:"settings" binding:"Required"`
  55. OrgId int64 `json:"-"`
  56. Result *AlertNotification
  57. }
  58. type UpdateAlertNotificationWithUidCommand struct {
  59. Uid string `json:"-"`
  60. Name string `json:"name" binding:"Required"`
  61. Type string `json:"type" binding:"Required"`
  62. SendReminder bool `json:"sendReminder"`
  63. DisableResolveMessage bool `json:"disableResolveMessage"`
  64. Frequency string `json:"frequency"`
  65. IsDefault bool `json:"isDefault"`
  66. Settings *simplejson.Json `json:"settings" binding:"Required"`
  67. OrgId int64
  68. Result *AlertNotification
  69. }
  70. type DeleteAlertNotificationCommand struct {
  71. Id int64
  72. OrgId int64
  73. }
  74. type DeleteAlertNotificationWithUidCommand struct {
  75. Uid string
  76. OrgId int64
  77. }
  78. type GetAlertNotificationsQuery struct {
  79. Name string
  80. Id int64
  81. OrgId int64
  82. Result *AlertNotification
  83. }
  84. type GetAlertNotificationsWithUidQuery struct {
  85. Uid string
  86. OrgId int64
  87. Result *AlertNotification
  88. }
  89. type GetAlertNotificationsWithUidToSendQuery struct {
  90. Uids []string
  91. OrgId int64
  92. Result []*AlertNotification
  93. }
  94. type GetAllAlertNotificationsQuery struct {
  95. OrgId int64
  96. Result []*AlertNotification
  97. }
  98. type AlertNotificationState struct {
  99. Id int64
  100. OrgId int64
  101. AlertId int64
  102. NotifierId int64
  103. State AlertNotificationStateType
  104. Version int64
  105. UpdatedAt int64
  106. AlertRuleStateUpdatedVersion int64
  107. }
  108. type SetAlertNotificationStateToPendingCommand struct {
  109. Id int64
  110. AlertRuleStateUpdatedVersion int64
  111. Version int64
  112. ResultVersion int64
  113. }
  114. type SetAlertNotificationStateToCompleteCommand struct {
  115. Id int64
  116. Version int64
  117. }
  118. type GetOrCreateNotificationStateQuery struct {
  119. OrgId int64
  120. AlertId int64
  121. NotifierId int64
  122. Result *AlertNotificationState
  123. }