848f804169
- FastAPI 后端 + Vue 3 前端 - Docker Compose 一键部署 - Casdoor OAuth 认证集成 - LogHive 集中式日志 - 设备批量 CSV 导入/导出 - WebSocket 实时状态推送 - 企业微信告警通知 - fping 高性能并发 Ping 检测 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
import enum
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, BigInteger, Enum
|
|
from .device import Base
|
|
|
|
|
|
class AlertTypeEnum(str, enum.Enum):
|
|
offline = "offline" # 设备离线
|
|
recovered = "recovered" # 设备恢复
|
|
system = "system" # 系统告警(如上游断网检测)
|
|
|
|
|
|
class AlertEvent(Base):
|
|
"""告警事件表"""
|
|
__tablename__ = "alert_events"
|
|
|
|
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
|
device_id = Column(Integer, nullable=False, index=True, comment="关联设备 ID")
|
|
alert_type = Column(Enum(AlertTypeEnum), nullable=False, comment="告警类型")
|
|
message = Column(String(1024), default="", comment="告警消息摘要")
|
|
|
|
# 离线起止
|
|
start_at = Column(DateTime, nullable=False, comment="离线开始时间")
|
|
end_at = Column(DateTime, nullable=True, comment="恢复时间")
|
|
duration_minutes = Column(Integer, nullable=True, comment="离线时长(分钟)")
|
|
|
|
is_resolved = Column(Boolean, default=False, comment="是否已恢复")
|
|
notification_sent = Column(Boolean, default=False, comment="是否已发送通知")
|
|
acknowledged_at = Column(DateTime, nullable=True, comment="用户确认时间")
|
|
|
|
created_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
|
|
|
def __repr__(self):
|
|
return f"<AlertEvent(id={self.id}, device={self.device_id}, type={self.alert_type})>"
|