alert.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package models
  2. import (
  3. "time"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. )
  6. type Alert struct {
  7. Id int64
  8. OrgId int64
  9. DashboardId int64
  10. PanelId int64
  11. Name string
  12. Description string
  13. State string
  14. Handler int64
  15. Enabled bool
  16. Frequency int64
  17. Created time.Time
  18. Updated time.Time
  19. Settings *simplejson.Json
  20. }
  21. func (alert *Alert) ValidToSave() bool {
  22. return alert.DashboardId != 0 && alert.OrgId != 0 && alert.PanelId != 0
  23. }
  24. func (this *Alert) ContainsUpdates(other *Alert) bool {
  25. result := false
  26. result = result || this.Name != other.Name
  27. result = result || this.Description != other.Description
  28. if this.Settings != nil && other.Settings != nil {
  29. json1, err1 := this.Settings.Encode()
  30. json2, err2 := other.Settings.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 AlertChange 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 []*Alert
  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 []*Alert
  78. }
  79. type GetAllAlertsQuery struct {
  80. Result []*Alert
  81. }
  82. type GetAlertByIdQuery struct {
  83. Id int64
  84. Result *Alert
  85. }
  86. type GetAlertChangesQuery struct {
  87. OrgId int64
  88. Limit int64
  89. SinceId int64
  90. Result []*AlertChange
  91. }