update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
+112
-111
@@ -56,41 +56,41 @@ const (
|
||||
|
||||
// AlertRule 告警规则(增强版)
|
||||
type AlertRule struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:规则名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(500);comment:规则描述" json:"description,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:规则名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(500);comment:规则描述" json:"description,omitempty"`
|
||||
// ====== 原 V1 兼容字段 ======
|
||||
Type string `gorm:"type:varchar(32);comment:规则类型: metric/log/event" json:"type,omitempty"`
|
||||
Source string `gorm:"type:varchar(64);comment:数据源: prometheus/zabbix/custom/loki/elasticsearch" json:"source,omitempty"`
|
||||
Expression string `gorm:"type:text;comment:PromQL/Zabbix/LogQL/Lucene表达式" json:"expression,omitempty"`
|
||||
DatasourceID uint `gorm:"index;comment:日志/指标数据源ID" json:"datasource_id,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);default:'warning';comment:告警级别" json:"severity"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
Type string `gorm:"type:varchar(32);comment:规则类型: metric/log/event" json:"type,omitempty"`
|
||||
Source string `gorm:"type:varchar(64);comment:数据源: prometheus/zabbix/custom/loki/elasticsearch" json:"source,omitempty"`
|
||||
Expression string `gorm:"type:text;comment:PromQL/Zabbix/LogQL/Lucene表达式" json:"expression,omitempty"`
|
||||
DatasourceID uint `gorm:"index;comment:日志/指标数据源ID" json:"datasource_id,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);default:'warning';comment:告警级别" json:"severity"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
// ====== V2 增强字段 ======
|
||||
Status AlertRuleStatus `gorm:"type:varchar(16);default:'enabled';comment:规则状态" json:"status,omitempty"`
|
||||
TargetType string `gorm:"type:varchar(32);comment:目标类型" json:"target_type,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID(0表示全部)" json:"target_id,omitempty"`
|
||||
TargetTags string `gorm:"type:varchar(256);comment:目标标签筛选" json:"target_tags,omitempty"`
|
||||
Conditions string `gorm:"type:text;comment:触发条件JSON数组" json:"conditions,omitempty"`
|
||||
AggWindow int `gorm:"default:300;comment:聚合窗口(秒)" json:"agg_window,omitempty"`
|
||||
AggFunction string `gorm:"type:varchar(16);default:'avg';comment:聚合函数" json:"agg_function,omitempty"`
|
||||
RecoverCount int `gorm:"default:1;comment:恢复次数" json:"recover_count,omitempty"`
|
||||
RecoverWindow int `gorm:"default:300;comment:恢复检查窗口(秒)" json:"recover_window,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:评估间隔(秒)" json:"interval,omitempty"`
|
||||
CheckTimes int `gorm:"default:1;comment:连续触发次数" json:"check_times,omitempty"`
|
||||
NotifyMode string `gorm:"type:varchar(16);default:'every';comment:通知模式: every/once/upgrade" json:"notify_mode,omitempty"`
|
||||
ChannelIDs string `gorm:"type:varchar(256);comment:通知渠道ID列表JSON" json:"channel_ids,omitempty"`
|
||||
NotifyChannels string `gorm:"type:text;comment:通知渠道JSON(兼容V1)" json:"notify_channels,omitempty"`
|
||||
TemplateID uint `gorm:"comment:通知模板ID" json:"template_id,omitempty"`
|
||||
UpgradeID uint `gorm:"comment:升级策略ID" json:"upgrade_id,omitempty"`
|
||||
SilenceID uint `gorm:"comment:静默规则ID" json:"silence_id,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
Status AlertRuleStatus `gorm:"type:varchar(16);default:'enabled';comment:规则状态" json:"status,omitempty"`
|
||||
TargetType string `gorm:"type:varchar(32);comment:目标类型" json:"target_type,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID(0表示全部)" json:"target_id,omitempty"`
|
||||
TargetTags string `gorm:"type:varchar(256);comment:目标标签筛选" json:"target_tags,omitempty"`
|
||||
Conditions string `gorm:"type:text;comment:触发条件JSON数组" json:"conditions,omitempty"`
|
||||
AggWindow int `gorm:"default:300;comment:聚合窗口(秒)" json:"agg_window,omitempty"`
|
||||
AggFunction string `gorm:"type:varchar(16);default:'avg';comment:聚合函数" json:"agg_function,omitempty"`
|
||||
RecoverCount int `gorm:"default:1;comment:恢复次数" json:"recover_count,omitempty"`
|
||||
RecoverWindow int `gorm:"default:300;comment:恢复检查窗口(秒)" json:"recover_window,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:评估间隔(秒)" json:"interval,omitempty"`
|
||||
CheckTimes int `gorm:"default:1;comment:连续触发次数" json:"check_times,omitempty"`
|
||||
NotifyMode string `gorm:"type:varchar(16);default:'every';comment:通知模式: every/once/upgrade" json:"notify_mode,omitempty"`
|
||||
ChannelIDs string `gorm:"type:varchar(256);comment:通知渠道ID列表JSON" json:"channel_ids,omitempty"`
|
||||
NotifyChannels string `gorm:"type:text;comment:通知渠道JSON(兼容V1)" json:"notify_channels,omitempty"`
|
||||
TemplateID uint `gorm:"comment:通知模板ID" json:"template_id,omitempty"`
|
||||
UpgradeID uint `gorm:"comment:升级策略ID" json:"upgrade_id,omitempty"`
|
||||
SilenceID uint `gorm:"comment:静默规则ID" json:"silence_id,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertRule) TableName() string {
|
||||
@@ -112,40 +112,40 @@ const (
|
||||
|
||||
// AlertEvent 告警事件(增强版)
|
||||
type AlertEvent struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
RuleID uint `gorm:"not null;index:idx_rule_time;comment:规则ID" json:"rule_id"`
|
||||
RuleName string `gorm:"type:varchar(128);comment:规则名称" json:"rule_name,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);comment:告警级别" json:"severity,omitempty"`
|
||||
Status string `gorm:"type:varchar(32);default:'firing';comment:事件状态" json:"status"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
RuleID uint `gorm:"not null;index:idx_rule_time;comment:规则ID" json:"rule_id"`
|
||||
RuleName string `gorm:"type:varchar(128);comment:规则名称" json:"rule_name,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);comment:告警级别" json:"severity,omitempty"`
|
||||
Status string `gorm:"type:varchar(32);default:'firing';comment:事件状态" json:"status"`
|
||||
// ====== 原V1兼容字段 ======
|
||||
Target string `gorm:"type:varchar(255);comment:目标标签" json:"target,omitempty"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
Value float64 `gorm:"comment:触发值" json:"value,omitempty"`
|
||||
Target string `gorm:"type:varchar(255);comment:目标标签" json:"target,omitempty"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
Value float64 `gorm:"comment:触发值" json:"value,omitempty"`
|
||||
// ====== V2增强字段 ======
|
||||
TargetID uint `gorm:"index;comment:目标ID" json:"target_id,omitempty"`
|
||||
TargetName string `gorm:"type:varchar(128);comment:目标名称" json:"target_name,omitempty"`
|
||||
TargetIP string `gorm:"type:varchar(64);comment:目标IP" json:"target_ip,omitempty"`
|
||||
Title string `gorm:"type:varchar(256);comment:告警标题" json:"title,omitempty"`
|
||||
MetricName string `gorm:"type:varchar(64);comment:指标名称" json:"metric_name,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
Operator string `gorm:"type:varchar(8);comment:运算符" json:"operator,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
StartedAt time.Time `gorm:"not null;index:idx_rule_time;comment:触发时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
LastEvalAt time.Time `gorm:"comment:最后评估时间" json:"last_eval_at,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count,omitempty"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
UpgradeLevel int `gorm:"default:0;comment:当前升级级别" json:"upgrade_level,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy *uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
AckComment string `gorm:"type:varchar(256);comment:确认备注" json:"ack_comment,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID" json:"target_id,omitempty"`
|
||||
TargetName string `gorm:"type:varchar(128);comment:目标名称" json:"target_name,omitempty"`
|
||||
TargetIP string `gorm:"type:varchar(64);comment:目标IP" json:"target_ip,omitempty"`
|
||||
Title string `gorm:"type:varchar(256);comment:告警标题" json:"title,omitempty"`
|
||||
MetricName string `gorm:"type:varchar(64);comment:指标名称" json:"metric_name,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
Operator string `gorm:"type:varchar(8);comment:运算符" json:"operator,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
StartedAt time.Time `gorm:"not null;index:idx_rule_time;comment:触发时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
LastEvalAt time.Time `gorm:"comment:最后评估时间" json:"last_eval_at,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count,omitempty"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
UpgradeLevel int `gorm:"default:0;comment:当前升级级别" json:"upgrade_level,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy *uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
AckComment string `gorm:"type:varchar(256);comment:确认备注" json:"ack_comment,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联
|
||||
Rule *AlertRule `json:"rule,omitempty" gorm:"foreignKey:RuleID"`
|
||||
@@ -160,14 +160,14 @@ func (AlertEvent) TableName() string {
|
||||
// ============================================
|
||||
|
||||
type AlertCondition struct {
|
||||
Metric string `json:"metric"`
|
||||
Operator Operator `json:"operator"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index string `json:"index,omitempty"`
|
||||
LogicOp string `json:"logic_op,omitempty"`
|
||||
AggFunc AggFunction `json:"agg_func,omitempty"`
|
||||
Window int `json:"window,omitempty"`
|
||||
Metric string `json:"metric"`
|
||||
Operator Operator `json:"operator"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index string `json:"index,omitempty"`
|
||||
LogicOp string `json:"logic_op,omitempty"`
|
||||
AggFunc AggFunction `json:"agg_func,omitempty"`
|
||||
Window int `json:"window,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertCondition) TableName() string {
|
||||
@@ -184,21 +184,21 @@ type AlertConditionGroup struct {
|
||||
// ============================================
|
||||
|
||||
type AlertNotifyTemplate struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
ChannelType string `gorm:"type:varchar(32);not null;comment:适用渠道类型: email/sms/webhook/dingtalk/wecom/feishu" json:"channel_type"`
|
||||
TitleTemplate string `gorm:"type:varchar(256);comment:标题模板" json:"title_template,omitempty"`
|
||||
BodyTemplate string `gorm:"type:text;comment:正文模板" json:"body_template,omitempty"`
|
||||
Variables string `gorm:"type:text;comment:可用变量说明JSON" json:"variables,omitempty"`
|
||||
RecoverTitleTemplate string `gorm:"type:varchar(256);comment:恢复标题模板" json:"recover_title_template,omitempty"`
|
||||
RecoverBodyTemplate string `gorm:"type:text;comment:恢复正文模板" json:"recover_body_template,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
ChannelType string `gorm:"type:varchar(32);not null;comment:适用渠道类型: email/sms/webhook/dingtalk/wecom/feishu" json:"channel_type"`
|
||||
TitleTemplate string `gorm:"type:varchar(256);comment:标题模板" json:"title_template,omitempty"`
|
||||
BodyTemplate string `gorm:"type:text;comment:正文模板" json:"body_template,omitempty"`
|
||||
Variables string `gorm:"type:text;comment:可用变量说明JSON" json:"variables,omitempty"`
|
||||
RecoverTitleTemplate string `gorm:"type:varchar(256);comment:恢复标题模板" json:"recover_title_template,omitempty"`
|
||||
RecoverBodyTemplate string `gorm:"type:text;comment:恢复正文模板" json:"recover_body_template,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertNotifyTemplate) TableName() string {
|
||||
@@ -249,12 +249,12 @@ func (AlertUpgrade) TableName() string {
|
||||
}
|
||||
|
||||
type AlertUpgradeRule struct {
|
||||
Level int `json:"level"`
|
||||
Duration int `json:"duration"`
|
||||
Severity string `json:"severity"`
|
||||
Level int `json:"level"`
|
||||
Duration int `json:"duration"`
|
||||
Severity string `json:"severity"`
|
||||
ChannelIDs []string `json:"channel_ids"`
|
||||
NotifyUsers []uint `json:"notify_users"`
|
||||
RepeatInterval int `json:"repeat_interval"`
|
||||
NotifyUsers []uint `json:"notify_users"`
|
||||
RepeatInterval int `json:"repeat_interval"`
|
||||
}
|
||||
|
||||
type AlertUpgradeRecord struct {
|
||||
@@ -321,19 +321,19 @@ type AlertSilenceCheckResult struct {
|
||||
|
||||
// NotifyChannel 通知渠道模型
|
||||
type NotifyChannel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
|
||||
Config string `gorm:"type:text" json:"config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
TestStatus string `gorm:"size:32" json:"test_status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
|
||||
Config string `gorm:"type:text" json:"config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
TestStatus string `gorm:"size:32" json:"test_status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (NotifyChannel) TableName() string {
|
||||
return "monitor_notify_channels"
|
||||
return "monitor_alert_channels"
|
||||
}
|
||||
|
||||
// MetricData 监控指标数据
|
||||
@@ -383,14 +383,14 @@ type UpdateAlertRuleRequest struct {
|
||||
|
||||
// AlertStats 告警统计
|
||||
type AlertStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Firing int64 `json:"firing"`
|
||||
Resolved int64 `json:"resolved"`
|
||||
Critical int64 `json:"critical"`
|
||||
Warning int64 `json:"warning"`
|
||||
Info int64 `json:"info"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
Total int64 `json:"total"`
|
||||
Firing int64 `json:"firing"`
|
||||
Resolved int64 `json:"resolved"`
|
||||
Critical int64 `json:"critical"`
|
||||
Warning int64 `json:"warning"`
|
||||
Info int64 `json:"info"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
}
|
||||
|
||||
// AcknowledgeAlertRequest 确认告警请求
|
||||
@@ -491,7 +491,7 @@ type FeishuWebhookConfig struct {
|
||||
|
||||
// FeishuCardMessage 飞书卡片消息
|
||||
type FeishuCardMessage struct {
|
||||
MsgType string `json:"msg_type"`
|
||||
MsgType string `json:"msg_type"`
|
||||
Content FeishuCardContent `json:"content"`
|
||||
}
|
||||
|
||||
@@ -499,6 +499,7 @@ type FeishuCardContent struct {
|
||||
Title string `json:"title"`
|
||||
Content [][]FeishuCardElement `json:"content"`
|
||||
}
|
||||
|
||||
// FeishuCardElement 飞书卡片元素
|
||||
type FeishuCardElement struct {
|
||||
Tag string `json:"tag"`
|
||||
|
||||
Reference in new issue
Block a user