| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- """
- Alert model for system notifications.
- """
- from datetime import datetime
- from sqlalchemy import DateTime, JSON, String, Text
- from sqlalchemy.orm import Mapped, mapped_column
- from app.core.database import Base
- class Alert(Base):
- """System alerts and notifications."""
- __tablename__ = "alerts"
- id: Mapped[int] = mapped_column(primary_key=True)
- timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), index=True)
- # Alert type
- alert_type: Mapped[str] = mapped_column(
- String(50), index=True, nullable=False
- ) # security, host_metrics, device_offline, etc.
- # Severity
- severity: Mapped[str] = mapped_column(
- String(20), nullable=False, index=True
- ) # info, warning, error, critical
- # Content
- title: Mapped[str] = mapped_column(String(255), nullable=False)
- message: Mapped[str] = mapped_column(Text, nullable=False)
- alert_metadata: Mapped[dict | None] = mapped_column(JSON)
- # State
- acknowledged: Mapped[bool] = mapped_column(default=False, index=True)
- acknowledged_at: Mapped[datetime | None] = mapped_column()
- acknowledged_by: Mapped[int | None] = mapped_column() # user_id
- dismissed: Mapped[bool] = mapped_column(default=False, index=True)
- dismissed_at: Mapped[datetime | None] = mapped_column()
- # Delivery tracking
- sent_dashboard: Mapped[bool] = mapped_column(default=False)
- sent_telegram: Mapped[bool] = mapped_column(default=False)
- sent_email: Mapped[bool] = mapped_column(default=False)
|