alert_notifications.go 3.7 KB

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