alerts.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Title string `json:"title"`
  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 (this *AlertRule) Equals(other AlertRule) bool {
  27. result := false
  28. result = result || this.Aggregator != other.Aggregator
  29. result = result || this.CritLevel != other.CritLevel
  30. result = result || this.WarnLevel != other.WarnLevel
  31. result = result || this.WarnOperator != other.WarnOperator
  32. result = result || this.CritOperator != other.CritOperator
  33. result = result || this.Query != other.Query
  34. result = result || this.QueryRefId != other.QueryRefId
  35. result = result || this.Frequency != other.Frequency
  36. result = result || this.Title != other.Title
  37. result = result || this.Description != other.Description
  38. result = result || this.QueryRange != other.QueryRange
  39. //don't compare .State! That would be insane.
  40. return result
  41. }
  42. type AlertingClusterInfo struct {
  43. ServerId string
  44. ClusterSize int
  45. UptimePosition int
  46. }
  47. type HeartBeatCommand struct {
  48. ServerId string
  49. Result AlertingClusterInfo
  50. }
  51. type AlertRuleChange struct {
  52. Id int64 `json:"id"`
  53. OrgId int64 `json:"-"`
  54. AlertId int64 `json:"alertId"`
  55. Type string `json:"type"`
  56. Created time.Time `json:"created"`
  57. }
  58. // Commands
  59. type SaveAlertsCommand struct {
  60. DashboardId int64
  61. UserId int64
  62. OrgId int64
  63. Alerts []AlertRule
  64. }
  65. type DeleteAlertCommand struct {
  66. AlertId int64
  67. }
  68. //Queries
  69. type GetAlertsQuery struct {
  70. OrgId int64
  71. State []string
  72. DashboardId int64
  73. PanelId int64
  74. Result []AlertRule
  75. }
  76. type GetAlertsForExecutionQuery struct {
  77. Timestamp int64
  78. Result []AlertRule
  79. }
  80. type GetAlertByIdQuery struct {
  81. Id int64
  82. Result AlertRule
  83. }
  84. type GetAlertChangesQuery struct {
  85. OrgId int64
  86. Limit int64
  87. SinceId int64
  88. Result []AlertRuleChange
  89. }
  90. type AlertJob struct {
  91. Offset int64
  92. Delay bool
  93. Running bool
  94. Rule AlertRule
  95. }
  96. type AlertResult struct {
  97. Id int64
  98. State string
  99. ActualValue float64
  100. Duration float64
  101. Description string
  102. Rule AlertRule
  103. }