alert_notifications.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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:"uid"`
  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. Uid string `json:"uid"`
  49. Name string `json:"name" binding:"Required"`
  50. Type string `json:"type" binding:"Required"`
  51. SendReminder bool `json:"sendReminder"`
  52. DisableResolveMessage bool `json:"disableResolveMessage"`
  53. Frequency string `json:"frequency"`
  54. IsDefault bool `json:"isDefault"`
  55. Settings *simplejson.Json `json:"settings" binding:"Required"`
  56. OrgId int64 `json:"-"`
  57. Result *AlertNotification
  58. }
  59. type UpdateAlertNotificationWithUidCommand struct {
  60. Uid string `json:"-"`
  61. NewUid string `json:"uid"`
  62. Name string `json:"name" binding:"Required"`
  63. Type string `json:"type" binding:"Required"`
  64. SendReminder bool `json:"sendReminder"`
  65. DisableResolveMessage bool `json:"disableResolveMessage"`
  66. Frequency string `json:"frequency"`
  67. IsDefault bool `json:"isDefault"`
  68. Settings *simplejson.Json `json:"settings" binding:"Required"`
  69. OrgId int64
  70. Result *AlertNotification
  71. }
  72. type DeleteAlertNotificationCommand struct {
  73. Id int64
  74. OrgId int64
  75. }
  76. type DeleteAlertNotificationWithUidCommand struct {
  77. Uid string
  78. OrgId int64
  79. }
  80. type GetAlertNotificationsQuery struct {
  81. Name string
  82. Id int64
  83. OrgId int64
  84. Result *AlertNotification
  85. }
  86. type GetAlertNotificationsWithUidQuery struct {
  87. Uid string
  88. OrgId int64
  89. Result *AlertNotification
  90. }
  91. type GetAlertNotificationsWithUidToSendQuery struct {
  92. Uids []string
  93. OrgId int64
  94. Result []*AlertNotification
  95. }
  96. type GetAllAlertNotificationsQuery struct {
  97. OrgId int64
  98. Result []*AlertNotification
  99. }
  100. type AlertNotificationState struct {
  101. Id int64
  102. OrgId int64
  103. AlertId int64
  104. NotifierId int64
  105. State AlertNotificationStateType
  106. Version int64
  107. UpdatedAt int64
  108. AlertRuleStateUpdatedVersion int64
  109. }
  110. type SetAlertNotificationStateToPendingCommand struct {
  111. Id int64
  112. AlertRuleStateUpdatedVersion int64
  113. Version int64
  114. ResultVersion int64
  115. }
  116. type SetAlertNotificationStateToCompleteCommand struct {
  117. Id int64
  118. Version int64
  119. }
  120. type GetOrCreateNotificationStateQuery struct {
  121. OrgId int64
  122. AlertId int64
  123. NotifierId int64
  124. Result *AlertNotificationState
  125. }