alerts_state.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package models
  2. import (
  3. "time"
  4. )
  5. type AlertState struct {
  6. Id int64 `json:"-"`
  7. OrgId int64 `json:"-"`
  8. AlertId int64 `json:"alertId"`
  9. NewState string `json:"newState"`
  10. Created time.Time `json:"created"`
  11. Info string `json:"info"`
  12. }
  13. var (
  14. VALID_STATES = []string{
  15. AlertStateOk,
  16. AlertStateWarn,
  17. AlertStateCritical,
  18. AlertStateAcknowledged,
  19. AlertStateMaintenance,
  20. }
  21. AlertStateOk = "OK"
  22. AlertStateWarn = "WARN"
  23. AlertStateCritical = "CRITICAL"
  24. AlertStateAcknowledged = "ACKNOWLEDGED"
  25. AlertStateMaintenance = "MAINTENANCE"
  26. )
  27. func (this *UpdateAlertStateCommand) IsValidState() bool {
  28. for _, v := range VALID_STATES {
  29. if this.NewState == v {
  30. return true
  31. }
  32. }
  33. return false
  34. }
  35. // Commands
  36. type UpdateAlertStateCommand struct {
  37. AlertId int64 `json:"alertId" binding:"Required"`
  38. NewState string `json:"newState" binding:"Required"`
  39. Info string `json:"info"`
  40. Result *AlertRule
  41. }
  42. // Queries
  43. type GetAlertsStateQuery struct {
  44. OrgId int64 `json:"orgId" binding:"Required"`
  45. AlertId int64 `json:"alertId" binding:"Required"`
  46. Result *[]AlertState
  47. }