alert.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. Created time.Time
  17. Updated time.Time
  18. Settings *simplejson.Json
  19. }
  20. func (alert *Alert) ValidToSave() bool {
  21. return alert.DashboardId != 0 && alert.OrgId != 0 && alert.PanelId != 0
  22. }
  23. func (this *Alert) ContainsUpdates(other *Alert) bool {
  24. result := false
  25. result = result || this.Name != other.Name
  26. result = result || this.Description != other.Description
  27. if this.Settings != nil && other.Settings != nil {
  28. json1, err1 := this.Settings.Encode()
  29. json2, err2 := other.Settings.Encode()
  30. if err1 != nil || err2 != nil {
  31. return false
  32. }
  33. result = result || string(json1) != string(json2)
  34. }
  35. //don't compare .State! That would be insane.
  36. return result
  37. }
  38. type AlertingClusterInfo struct {
  39. ServerId string
  40. ClusterSize int
  41. UptimePosition int
  42. }
  43. type HeartBeat struct {
  44. Id int64
  45. ServerId string
  46. Updated time.Time
  47. Created time.Time
  48. }
  49. type HeartBeatCommand struct {
  50. ServerId string
  51. Result AlertingClusterInfo
  52. }
  53. type AlertChange struct {
  54. Id int64 `json:"id"`
  55. OrgId int64 `json:"-"`
  56. AlertId int64 `json:"alertId"`
  57. Type string `json:"type"`
  58. Created time.Time `json:"created"`
  59. }
  60. // Commands
  61. type SaveAlertsCommand struct {
  62. DashboardId int64
  63. UserId int64
  64. OrgId int64
  65. Alerts []*Alert
  66. }
  67. type DeleteAlertCommand struct {
  68. AlertId int64
  69. }
  70. //Queries
  71. type GetAlertsQuery struct {
  72. OrgId int64
  73. State []string
  74. DashboardId int64
  75. PanelId int64
  76. Result []*Alert
  77. }
  78. type GetAllAlertsQuery struct {
  79. Result []*Alert
  80. }
  81. type GetAlertByIdQuery struct {
  82. Id int64
  83. Result *Alert
  84. }
  85. type GetAlertChangesQuery struct {
  86. OrgId int64
  87. Limit int64
  88. SinceId int64
  89. Result []*AlertChange
  90. }