- 告警规则:独立实体(alert_rules 表),按优先级命中第一条生效;支持三种主机目标(全部/按主机/按标签)、7 类阈值、事件通知开关、IP 打码、推送渠道选择;未命中规则的主机不产生告警;列表支持外置启停 - 服务监控:新增按标签选择探针,与指定探针取并集,均为空时全部探针执行 - 公网 IP 采集:范围支持全部探针/按探针/按标签,兼容历史 custom 取值 - 告警历史:新增规则归属列;评估链路(指标/证书/服务下线/探针离线/到期提醒/事件通知)全部按主机命中规则驱动 - 设置页:左侧菜单改为浅色卡片容器并优化对比度,通知渠道移至公网 IP 采集之后;主菜单宽度调整为 240px
50 lines
3.7 KiB
Go
50 lines
3.7 KiB
Go
package models
|
||
|
||
// AlertRecord 告警记录
|
||
type AlertRecord struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"` // 记录ID
|
||
AgentID string `gorm:"index" json:"agentId"` // 探针ID
|
||
AgentName string `json:"agentName"` // 探针名称
|
||
AlertType string `json:"alertType"` // 告警类型: cpu, memory, disk, network
|
||
ConfigID string `gorm:"index;default:global" json:"configId"` // 命中的告警规则 ID(global = 默认规则)
|
||
ConfigName string `json:"configName"` // 命中的告警规则名称(快照)
|
||
Message string `json:"message"` // 告警消息
|
||
Threshold float64 `json:"threshold"` // 告警阈值
|
||
ActualValue float64 `json:"actualValue"` // 告警触发时的实际值
|
||
ResolvedValue float64 `json:"resolvedValue,omitempty"` // 恢复时的实际值
|
||
Level string `json:"level"` // 告警级别: info, warning, critical
|
||
Status string `json:"status"` // 状态: firing(告警中), resolved(已恢复)
|
||
FiredAt int64 `gorm:"index" json:"firedAt"` // 触发时间(时间戳毫秒)
|
||
ResolvedAt int64 `json:"resolvedAt,omitempty"` // 恢复时间(时间戳毫秒)
|
||
NotificationStatus string `json:"notificationStatus"` // 通知状态: pending, sent, failed
|
||
NotificationSentAt int64 `json:"notificationSentAt,omitempty"` // 通知发送时间(时间戳毫秒)
|
||
NotificationError string `gorm:"type:text" json:"notificationError,omitempty"` // 通知发送失败原因
|
||
CreatedAt int64 `json:"createdAt"` // 创建时间(时间戳毫秒)
|
||
UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
|
||
}
|
||
|
||
func (AlertRecord) TableName() string {
|
||
return "alert_records"
|
||
}
|
||
|
||
// AlertState 告警状态(持久化到数据库,用于判断是否持续超过阈值)
|
||
type AlertState struct {
|
||
ID string `gorm:"primaryKey" json:"id"` // 状态ID(格式:agentId:configId:alertType)
|
||
AgentID string `gorm:"index" json:"agentId"` // 探针ID
|
||
AlertType string `gorm:"index" json:"alertType"` // 告警类型
|
||
ConfigID string `gorm:"index;default:global" json:"configId"` // 告警规则 ID(global = 默认规则)
|
||
Value float64 `json:"value"` // 当前值
|
||
Threshold float64 `json:"threshold"` // 阈值
|
||
StartTime int64 `json:"startTime"` // 开始超过阈值的时间
|
||
Duration int `json:"duration"` // 需要持续的时间(秒)
|
||
LastCheckTime int64 `json:"lastCheckTime"` // 上次检查时间
|
||
IsFiring bool `json:"isFiring"` // 是否正在告警
|
||
LastRecordID int64 `json:"lastRecordId"` // 最后一条告警记录ID
|
||
CreatedAt int64 `json:"createdAt"` // 创建时间(时间戳毫秒)
|
||
UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` // 更新时间(时间戳毫秒)
|
||
}
|
||
|
||
func (AlertState) TableName() string {
|
||
return "alert_states"
|
||
}
|