alerts.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package models
  2. import (
  3. "time"
  4. )
  5. type AlertRule struct {
  6. Id int64 `json:"id"`
  7. OrgId int64 `json:"-"`
  8. DatasourceId int64 `json:"datasourceId"`
  9. DashboardId int64 `json:"dashboardId"`
  10. PanelId int64 `json:"panelId"`
  11. Query string `json:"query"`
  12. QueryRefId string `json:"queryRefId"`
  13. WarnLevel float64 `json:"warnLevel"`
  14. CritLevel float64 `json:"critLevel"`
  15. WarnOperator string `json:"warnOperator"`
  16. CritOperator string `json:"critOperator"`
  17. Frequency int64 `json:"frequency"`
  18. Name string `json:"name"`
  19. Description string `json:"description"`
  20. QueryRange int `json:"queryRange"`
  21. Aggregator string `json:"aggregator"`
  22. State string `json:"state"`
  23. Created time.Time `json:"created"`
  24. Updated time.Time `json:"updated"`
  25. }
  26. func (alertRule *AlertRule) ValidToSave() bool {
  27. return alertRule.Query != "" && alertRule.Frequency != 0 && alertRule.QueryRange != 0 && alertRule.Name != ""
  28. }
  29. func (this *AlertRule) Equals(other *AlertRule) bool {
  30. result := false
  31. result = result || this.Aggregator != other.Aggregator
  32. result = result || this.CritLevel != other.CritLevel
  33. result = result || this.WarnLevel != other.WarnLevel
  34. result = result || this.WarnOperator != other.WarnOperator
  35. result = result || this.CritOperator != other.CritOperator
  36. result = result || this.Query != other.Query
  37. result = result || this.QueryRefId != other.QueryRefId
  38. result = result || this.Frequency != other.Frequency
  39. result = result || this.Name != other.Name
  40. result = result || this.Description != other.Description
  41. result = result || this.QueryRange != other.QueryRange
  42. //don't compare .State! That would be insane.
  43. return result
  44. }
  45. type AlertingClusterInfo struct {
  46. ServerId string
  47. ClusterSize int
  48. UptimePosition int
  49. }
  50. type HeartBeat struct {
  51. Id int64
  52. ServerId string
  53. Updated time.Time
  54. Created time.Time
  55. }
  56. type HeartBeatCommand struct {
  57. ServerId string
  58. Result AlertingClusterInfo
  59. }
  60. type AlertRuleChange struct {
  61. Id int64 `json:"id"`
  62. OrgId int64 `json:"-"`
  63. AlertId int64 `json:"alertId"`
  64. Type string `json:"type"`
  65. Created time.Time `json:"created"`
  66. }
  67. // Commands
  68. type SaveAlertsCommand struct {
  69. DashboardId int64
  70. UserId int64
  71. OrgId int64
  72. Alerts []*AlertRule
  73. }
  74. type DeleteAlertCommand struct {
  75. AlertId int64
  76. }
  77. //Queries
  78. type GetAlertsQuery struct {
  79. OrgId int64
  80. State []string
  81. DashboardId int64
  82. PanelId int64
  83. Result []*AlertRule
  84. }
  85. type GetAllAlertsQuery struct {
  86. Result []*AlertRule
  87. }
  88. type GetAlertsForExecutionQuery struct {
  89. Timestamp int64
  90. Result []*AlertRule
  91. }
  92. type GetAlertByIdQuery struct {
  93. Id int64
  94. Result *AlertRule
  95. }
  96. type GetAlertChangesQuery struct {
  97. OrgId int64
  98. Limit int64
  99. SinceId int64
  100. Result []*AlertRuleChange
  101. }