alert.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Alert model for system notifications.
  3. """
  4. from datetime import datetime
  5. from sqlalchemy import DateTime, JSON, String, Text
  6. from sqlalchemy.orm import Mapped, mapped_column
  7. from app.core.database import Base
  8. class Alert(Base):
  9. """System alerts and notifications."""
  10. __tablename__ = "alerts"
  11. id: Mapped[int] = mapped_column(primary_key=True)
  12. timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), index=True)
  13. # Alert type
  14. alert_type: Mapped[str] = mapped_column(
  15. String(50), index=True, nullable=False
  16. ) # security, host_metrics, device_offline, etc.
  17. # Severity
  18. severity: Mapped[str] = mapped_column(
  19. String(20), nullable=False, index=True
  20. ) # info, warning, error, critical
  21. # Content
  22. title: Mapped[str] = mapped_column(String(255), nullable=False)
  23. message: Mapped[str] = mapped_column(Text, nullable=False)
  24. alert_metadata: Mapped[dict | None] = mapped_column(JSON)
  25. # State
  26. acknowledged: Mapped[bool] = mapped_column(default=False, index=True)
  27. acknowledged_at: Mapped[datetime | None] = mapped_column()
  28. acknowledged_by: Mapped[int | None] = mapped_column() # user_id
  29. dismissed: Mapped[bool] = mapped_column(default=False, index=True)
  30. dismissed_at: Mapped[datetime | None] = mapped_column()
  31. # Delivery tracking
  32. sent_dashboard: Mapped[bool] = mapped_column(default=False)
  33. sent_telegram: Mapped[bool] = mapped_column(default=False)
  34. sent_email: Mapped[bool] = mapped_column(default=False)