alerts.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package models
  2. import (
  3. "time"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. )
  6. type AlertRuleModel struct {
  7. Id int64
  8. OrgId int64
  9. DashboardId int64
  10. PanelId int64
  11. Name string
  12. Description string
  13. State string
  14. Created time.Time
  15. Updated time.Time
  16. Expression *simplejson.Json
  17. }
  18. func (this AlertRuleModel) TableName() string {
  19. return "alert_rule"
  20. }
  21. func (alertRule *AlertRuleModel) ValidToSave() bool {
  22. return alertRule.DashboardId != 0
  23. }
  24. func (this *AlertRuleModel) ContainsUpdates(other *AlertRuleModel) bool {
  25. result := false
  26. result = result || this.Name != other.Name
  27. result = result || this.Description != other.Description
  28. if this.Expression != nil && other.Expression != nil {
  29. json1, err1 := this.Expression.Encode()
  30. json2, err2 := other.Expression.Encode()
  31. if err1 != nil || err2 != nil {
  32. return false
  33. }
  34. result = result || string(json1) != string(json2)
  35. }
  36. //don't compare .State! That would be insane.
  37. return result
  38. }
  39. type AlertingClusterInfo struct {
  40. ServerId string
  41. ClusterSize int
  42. UptimePosition int
  43. }
  44. type HeartBeat struct {
  45. Id int64
  46. ServerId string
  47. Updated time.Time
  48. Created time.Time
  49. }
  50. type HeartBeatCommand struct {
  51. ServerId string
  52. Result AlertingClusterInfo
  53. }
  54. type AlertRuleChange struct {
  55. Id int64 `json:"id"`
  56. OrgId int64 `json:"-"`
  57. AlertId int64 `json:"alertId"`
  58. Type string `json:"type"`
  59. Created time.Time `json:"created"`
  60. }
  61. // Commands
  62. type SaveAlertsCommand struct {
  63. DashboardId int64
  64. UserId int64
  65. OrgId int64
  66. Alerts []*AlertRuleModel
  67. }
  68. type DeleteAlertCommand struct {
  69. AlertId int64
  70. }
  71. //Queries
  72. type GetAlertsQuery struct {
  73. OrgId int64
  74. State []string
  75. DashboardId int64
  76. PanelId int64
  77. Result []*AlertRuleModel
  78. }
  79. type GetAllAlertsQuery struct {
  80. Result []*AlertRuleModel
  81. }
  82. type GetAlertByIdQuery struct {
  83. Id int64
  84. Result *AlertRuleModel
  85. }
  86. type GetAlertChangesQuery struct {
  87. OrgId int64
  88. Limit int64
  89. SinceId int64
  90. Result []*AlertRuleChange
  91. }