alerts.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 (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.Name != other.Name
  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 HeartBeat struct {
  48. Id int64
  49. ServerId string
  50. Updated time.Time
  51. Created time.Time
  52. }
  53. type HeartBeatCommand struct {
  54. ServerId string
  55. Result AlertingClusterInfo
  56. }
  57. type AlertRuleChange struct {
  58. Id int64 `json:"id"`
  59. OrgId int64 `json:"-"`
  60. AlertId int64 `json:"alertId"`
  61. Type string `json:"type"`
  62. Created time.Time `json:"created"`
  63. }
  64. // Commands
  65. type SaveAlertsCommand struct {
  66. DashboardId int64
  67. UserId int64
  68. OrgId int64
  69. Alerts []*AlertRule
  70. }
  71. type DeleteAlertCommand struct {
  72. AlertId int64
  73. }
  74. //Queries
  75. type GetAlertsQuery struct {
  76. OrgId int64
  77. State []string
  78. DashboardId int64
  79. PanelId int64
  80. Result []*AlertRule
  81. }
  82. type GetAllAlertsQuery struct {
  83. Result []*AlertRule
  84. }
  85. type GetAlertsForExecutionQuery struct {
  86. Timestamp int64
  87. Result []*AlertRule
  88. }
  89. type GetAlertByIdQuery struct {
  90. Id int64
  91. Result *AlertRule
  92. }
  93. type GetAlertChangesQuery struct {
  94. OrgId int64
  95. Limit int64
  96. SinceId int64
  97. Result []*AlertRuleChange
  98. }