package models import "time" // AlertRule 日志告警规则:对选定数据源周期执行 LogQL 计数,超过阈值即通知。 // 参照运维侧 app-alert.py 的两类模式: // // critical(出现即报,threshold=1)/ surge(突增才报,自定义阈值),统一收敛为「N 条 / 窗口 > 阈值」。 type AlertRule struct { ID uint `json:"id"` Name string `json:"name"` SourceID uint `json:"sourceId"` // LogSource ChannelIDs []uint `json:"channelIds"` // NotifyChannel 列表(告警扇出到多个群) Query string `json:"query"` // 完整 LogQL({app="x"} |= "FATAL") WindowMin int `json:"windowMin"` // 统计窗口(分钟) Threshold int `json:"threshold"` // 窗口内条数 > 阈值触发 Enabled bool `json:"enabled"` CooldownMin int `json:"cooldownMin"` // 同规则告警冷却(分钟,默认 60) LastFiredAt time.Time `json:"lastFiredAt"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } func (r *AlertRule) Sanitized() map[string]interface{} { return map[string]interface{}{ "id": r.ID, "name": r.Name, "sourceId": r.SourceID, "channelIds": r.ChannelIDs, "query": r.Query, "windowMin": r.WindowMin, "threshold": r.Threshold, "enabled": r.Enabled, "cooldownMin": r.CooldownMin, "lastFiredAt": r.LastFiredAt, "createdAt": r.CreatedAt, "updatedAt": r.UpdatedAt, } } // AlertDelivery 告警发送历史(飞书 webhook 投递记录) type AlertDelivery struct { ID uint `json:"id"` RuleID uint `json:"ruleId"` RuleName string `json:"ruleName"` Count int `json:"count"` // 窗口内命中条数 Status string `json:"status"` // sent | failed | cooldown-skipped Reason string `json:"reason"` CreatedAt time.Time `json:"createdAt"` }