feat: persist probe quality and notification outbox
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, BigInteger, Enum
|
||||
from sqlalchemy import BigInteger, Boolean, Column, DateTime, Enum, Integer, String
|
||||
from .device import Base
|
||||
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class AlertTypeEnum(str, enum.Enum):
|
||||
offline = "offline" # 设备离线
|
||||
degraded = "degraded" # 设备丢包故障
|
||||
recovered = "recovered" # 设备恢复
|
||||
system = "system" # 系统告警(如上游断网检测)
|
||||
|
||||
@@ -14,7 +18,7 @@ class AlertEvent(Base):
|
||||
"""告警事件表"""
|
||||
__tablename__ = "alert_events"
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||||
id = Column(PRIMARY_KEY_TYPE, 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="告警消息摘要")
|
||||
@@ -26,6 +30,14 @@ class AlertEvent(Base):
|
||||
|
||||
is_resolved = Column(Boolean, default=False, comment="是否已恢复")
|
||||
notification_sent = Column(Boolean, default=False, comment="是否已发送通知")
|
||||
notification_attempts = Column(Integer, default=0, comment="通知尝试次数")
|
||||
last_notification_error = Column(
|
||||
String(512),
|
||||
nullable=True,
|
||||
comment="最近一次通知失败原因",
|
||||
)
|
||||
previous_status = Column(String(16), nullable=True, comment="状态变更前状态")
|
||||
current_status = Column(String(16), nullable=True, comment="状态变更后状态")
|
||||
acknowledged_at = Column(DateTime, nullable=True, comment="用户确认时间")
|
||||
|
||||
created_at = Column(DateTime, default=datetime.now, comment="创建时间")
|
||||
|
||||
Reference in New Issue
Block a user