ops_alert_models.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package service
  2. import "time"
  3. // Ops alert rule/event models.
  4. //
  5. // NOTE: These are admin-facing DTOs and intentionally keep JSON naming aligned
  6. // with the existing ops dashboard frontend (backup style).
  7. const (
  8. OpsAlertStatusFiring = "firing"
  9. OpsAlertStatusResolved = "resolved"
  10. OpsAlertStatusManualResolved = "manual_resolved"
  11. )
  12. type OpsAlertRule struct {
  13. ID int64 `json:"id"`
  14. Name string `json:"name"`
  15. Description string `json:"description"`
  16. Enabled bool `json:"enabled"`
  17. Severity string `json:"severity"`
  18. MetricType string `json:"metric_type"`
  19. Operator string `json:"operator"`
  20. Threshold float64 `json:"threshold"`
  21. WindowMinutes int `json:"window_minutes"`
  22. SustainedMinutes int `json:"sustained_minutes"`
  23. CooldownMinutes int `json:"cooldown_minutes"`
  24. NotifyEmail bool `json:"notify_email"`
  25. Filters map[string]any `json:"filters,omitempty"`
  26. LastTriggeredAt *time.Time `json:"last_triggered_at,omitempty"`
  27. CreatedAt time.Time `json:"created_at"`
  28. UpdatedAt time.Time `json:"updated_at"`
  29. }
  30. type OpsAlertEvent struct {
  31. ID int64 `json:"id"`
  32. RuleID int64 `json:"rule_id"`
  33. Severity string `json:"severity"`
  34. Status string `json:"status"`
  35. Title string `json:"title"`
  36. Description string `json:"description"`
  37. MetricValue *float64 `json:"metric_value,omitempty"`
  38. ThresholdValue *float64 `json:"threshold_value,omitempty"`
  39. Dimensions map[string]any `json:"dimensions,omitempty"`
  40. FiredAt time.Time `json:"fired_at"`
  41. ResolvedAt *time.Time `json:"resolved_at,omitempty"`
  42. EmailSent bool `json:"email_sent"`
  43. CreatedAt time.Time `json:"created_at"`
  44. }
  45. type OpsAlertSilence struct {
  46. ID int64 `json:"id"`
  47. RuleID int64 `json:"rule_id"`
  48. Platform string `json:"platform"`
  49. GroupID *int64 `json:"group_id,omitempty"`
  50. Region *string `json:"region,omitempty"`
  51. Until time.Time `json:"until"`
  52. Reason string `json:"reason"`
  53. CreatedBy *int64 `json:"created_by,omitempty"`
  54. CreatedAt time.Time `json:"created_at"`
  55. }
  56. type OpsAlertEventFilter struct {
  57. Limit int
  58. // Cursor pagination (descending by fired_at, then id).
  59. BeforeFiredAt *time.Time
  60. BeforeID *int64
  61. // Optional filters.
  62. Status string
  63. Severity string
  64. EmailSent *bool
  65. StartTime *time.Time
  66. EndTime *time.Time
  67. // Dimensions filters (best-effort).
  68. Platform string
  69. GroupID *int64
  70. }