feat: 监控告警体系统一重构 + 自动化任务调度引擎 + 监控大屏拆分

告警中心
- 新增统一告警(alert_unified)、监控告警规则(monitor_alert_rule)、指标目录(alert_metric_catalog)
- 通知策略与消息分发(alert_notify_policy/dispatch/message)、静默规则
- 告警引擎按阈值/SNMP 拆分(alert_engine_monitor/snmp)

监控采集
- SNMP 常量/模板与历史指标(snmp templates/constants、snmp_metrics_history、snmp_collect)
- 中间件监控 Redis 采集与种子(middleware_monitor_redis/seed)
- 站点探测 pkg(siteprobe) + 站点视图(site_view)

自动化任务
- cron 调度器(cronscheduler)、脚本运行器(scriptrunner)、系统任务(systask)及运行记录(cron_job_run、system_task)

审计与凭证
- 审计设置(audit_setting) + 历史清理(auditcleaner)

前端
- 监控页面(host/middleware/site/snmp)拆分为子模块并大屏化
- 告警中心多 Tab(规则/指标目录/通知策略/静默)、任务管理组件重构、Agent CLI Markdown 渲染
- 移除旧脚本卡片/详情/日志组件,统一为 ScriptTable/ScriptCodeEditor/TerminalOutput

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
LoganandClaude committed 2026-07-01 23:44:45 +08:00
1 parent 092d0e4b9e
commit 471353e3d7
190 files changed
+16640 -3484

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package model
import "time"
// AlertNotifyCategory 告警通知策略分类(与监控中心四 Tab 对齐)// Logan.Li
type AlertNotifyCategory string
const (
AlertNotifyHost AlertNotifyCategory = "host"
AlertNotifyMiddleware AlertNotifyCategory = "middleware"
AlertNotifySite AlertNotifyCategory = "site"
AlertNotifySNMP AlertNotifyCategory = "snmp"
)
// AllAlertNotifyCategories 全部告警集合 // Logan.Li
var AllAlertNotifyCategories = []AlertNotifyCategory{
AlertNotifyHost, AlertNotifyMiddleware, AlertNotifySite, AlertNotifySNMP,
}
// AlertNotifyPolicy 告警集合级通知策略 — 绑定联系组/联系人 // Logan.Li
type AlertNotifyPolicy struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Category AlertNotifyCategory `gorm:"type:varchar(16);not null;uniqueIndex" json:"category"`
Label string `gorm:"type:varchar(64)" json:"label"`
Enabled bool `gorm:"default:false" json:"enabled"`
ContactGroupIDs string `gorm:"type:text;comment:联系组ID列表JSON" json:"contact_group_ids,omitempty"`
ContactIDs string `gorm:"type:text;comment:额外联系人ID列表JSON" json:"contact_ids,omitempty"`
NotifyMode string `gorm:"type:varchar(16);default:every;comment:every/once" json:"notify_mode"`
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (AlertNotifyPolicy) TableName() string { return "monitor_alert_notify_policies" }
+15
View File
@@ -0,0 +1,15 @@
package model
import "time"
// AlertNotifySettings 告警消息模版(全局单行配置) // Logan.Li
type AlertNotifySettings struct {
ID uint `gorm:"primaryKey" json:"id"`
TitleTemplate string `gorm:"type:varchar(256);comment:标题模版" json:"title_template"`
FooterTemplate string `gorm:"type:varchar(256);comment:卡片底部模版" json:"footer_template"`
PlatformName string `gorm:"type:varchar(64);default:AIOps 智能运维平台;comment:平台署名" json:"platform_name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (AlertNotifySettings) TableName() string { return "monitor_alert_notify_settings" }
+29
View File
@@ -0,0 +1,29 @@
package model
import "time"
// AuditSettings 审计策略配置(单行) // Logan.Li
type AuditSettings struct {
ID uint `gorm:"primarykey" json:"id"`
RetentionDays int `gorm:"default:180;not null" json:"retention_days"`
RecordAll bool `gorm:"default:true" json:"record_all"`
LastCleanupAt *time.Time `json:"last_cleanup_at,omitempty"`
LastCleanupSummary string `gorm:"size:500" json:"last_cleanup_summary,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (AuditSettings) TableName() string { return "sys_audit_settings" }
// AllowedAuditRetentionDays 允许的日志保留天数 // Logan.Li
var AllowedAuditRetentionDays = []int{7, 15, 30, 90, 180, 365}
// IsValidRetentionDays 校验保留天数 // Logan.Li
func IsValidRetentionDays(days int) bool {
for _, d := range AllowedAuditRetentionDays {
if d == days {
return true
}
}
return false
}
+3 -3
View File
@@ -88,7 +88,7 @@ type CreateCronJobRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
CronExpr string `json:"cron_expr" binding:"required"`
Type string `json:"type" binding:"required,oneof=shell python command"`
Type string `json:"type" binding:"required,oneof=shell python powershell command bash"`
Content string `json:"content"`
ScriptID *uint `json:"script_id"`
TargetType string `json:"target_type" binding:"omitempty,oneof=server group tag"`
@@ -100,9 +100,9 @@ type CreateCronJobRequest struct {
// CreateScriptRequest 创建脚本请求
type CreateScriptRequest struct {
Name string `json:"name" binding:"required"`
Code string `json:"code" binding:"required"`
Code string `json:"code"` // 为空时由 handler 自动生成 // Logan.Li
Description string `json:"description"`
Type string `json:"type" binding:"omitempty,oneof=shell python"`
Type string `json:"type" binding:"omitempty,oneof=shell python powershell command bash"`
Content string `json:"content" binding:"required"`
Params string `json:"params"`
Timeout int `json:"timeout"`
+18 -7
View File
@@ -58,13 +58,24 @@ type StatusRequest struct {
// DashboardStats 仪表盘统计
type DashboardStats struct {
ServerStats ServerStats `json:"server_stats"`
K8sStats KubernetesClusterStats `json:"kubernetes_stats"`
AlertStats AlertStats `json:"alert_stats"`
PipelineStats PipelineStats `json:"pipeline_stats"`
CostStats CostStats `json:"cost_stats"`
TopResourceUsage TopResourceUsage `json:"top_resource_usage"`
ExpiringCerts []DomainCert `json:"expiring_certs"`
ServerStats ServerStats `json:"server_stats"`
K8sStats KubernetesClusterStats `json:"kubernetes_stats"`
AlertStats AlertStats `json:"alert_stats"`
PipelineStats PipelineStats `json:"pipeline_stats"`
AutomationStats AutomationStats `json:"automation_stats"`
OpsStats OpsOverviewStats `json:"ops_stats"`
CostStats CostStats `json:"cost_stats"`
TopResourceUsage TopResourceUsage `json:"top_resource_usage"`
ExpiringCerts []DomainCert `json:"expiring_certs"`
}
// OpsOverviewStats 运维概览统计(仪表盘快捷入口)// Logan.Li
type OpsOverviewStats struct {
DomainCount int64 `json:"domain_count"`
SiteTaskCount int64 `json:"site_task_count"`
MiddlewareCount int64 `json:"middleware_count"`
SnmpDeviceCount int64 `json:"snmp_device_count"`
MonitorTargetCount int64 `json:"monitor_target_count"`
}
// CostStats 成本统计
+9 -7
View File
@@ -179,13 +179,15 @@ type CreateKubernetesClusterRequest struct {
// KubernetesClusterStats K8s集群统计
type KubernetesClusterStats struct {
Total int64 `json:"total"`
Healthy int64 `json:"healthy"`
Warning int64 `json:"warning"`
Error int64 `json:"error"`
TotalNodes int64 `json:"total_nodes"`
TotalPods int64 `json:"total_pods"`
TotalServices int64 `json:"total_services"`
Total int64 `json:"total"`
Healthy int64 `json:"healthy"`
Warning int64 `json:"warning"`
Error int64 `json:"error"`
TotalNodes int64 `json:"total_nodes"`
TotalPods int64 `json:"total_pods"`
TotalServices int64 `json:"total_services"`
TotalIngresses int64 `json:"total_ingresses"`
TotalDeployments int64 `json:"total_deployments"`
}
// TopologyLayout 拓扑布局(保存节点位置 + 自定义节点 + 自定义连线) // Logan.Li
+1 -1
View File
@@ -6,7 +6,7 @@ import "time"
// 支持 OpenAI 兼容接口(OpenAI / DeepSeek / 智谱GLM / 通义千问 / Moonshot / Kimi / 小米MiMo / Anthropic(需代理) / Ollama / 自定义)
type LLMConfig struct {
ID uint `gorm:"primarykey" json:"id"`
Provider string `gorm:"size:50;not null;default:openai" json:"provider"` // openai/deepseek/glm/qwen/moonshot/kimi/mimo/anthropic/ollama/custom
Provider string `gorm:"size:50;not null;default:openai" json:"provider"` // deepseek/glm/glm-coding/kimi/moonshot/minimax/minimax-coding/mimo/siliconflow/openai/anthropic/ollama/vllm/custom
Model string `gorm:"size:100;not null;default:gpt-4o-mini" json:"model"` // 模型名,如 gpt-4o-mini / deepseek-v4-flash
APIKey string `gorm:"size:500" json:"api_key"` // API Key(GET 时会被脱敏)
Endpoint string `gorm:"size:500" json:"endpoint"` // 基础地址,如 https://api.openai.com/v1
+34
View File
@@ -0,0 +1,34 @@
package model
import "time"
// MonitorAlertCategory 监控告警规则分类 // Logan.Li
type MonitorAlertCategory string
const (
MonitorAlertHost MonitorAlertCategory = "host"
MonitorAlertMiddleware MonitorAlertCategory = "middleware"
MonitorAlertSNMP MonitorAlertCategory = "snmp"
MonitorAlertSite MonitorAlertCategory = "site"
)
// MonitorAlertRule 中间件/站点拨测告警规则(主机规则仍用 AgentRule)// Logan.Li
type MonitorAlertRule struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Category MonitorAlertCategory `gorm:"type:varchar(16);not null;index" json:"category"`
Name string `gorm:"type:varchar(128);not null" json:"name"`
TargetID uint `gorm:"default:0;index;comment:目标ID,0=全部" json:"target_id"`
Metric string `gorm:"type:varchar(64);not null" json:"metric"`
Operator string `gorm:"type:varchar(8);default:>" json:"operator"`
Threshold float64 `gorm:"type:decimal(12,4)" json:"threshold"`
Severity string `gorm:"type:varchar(16);default:warning" json:"severity"`
Enabled bool `gorm:"default:true" json:"enabled"`
DurationSec int `gorm:"default:0;comment:持续秒数(预留)" json:"duration_sec"`
Port int `gorm:"default:0" json:"port,omitempty"`
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
LastTriggered *time.Time `json:"last_triggered,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (MonitorAlertRule) TableName() string { return "monitor_alert_rules" }
+2 -1
View File
@@ -12,7 +12,8 @@ import (
type SiteTaskType string
const (
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS拨测
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS Web 拨测
SiteTaskTypeSSL SiteTaskType = "ssl" // SSL/TLS 证书拨测
SiteTaskTypeTCP SiteTaskType = "tcp" // TCP拨测
SiteTaskTypePing SiteTaskType = "ping" // ICMP Ping拨测
SiteTaskTypeDNS SiteTaskType = "dns" // DNS拨测
+16
View File
@@ -0,0 +1,16 @@
package model
import "time"
// SystemTaskStatus 内置系统任务运行状态(按 code 唯一) // Logan.Li
type SystemTaskStatus struct {
Code string `gorm:"primaryKey;size:64" json:"code"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastStatus string `gorm:"size:32" json:"last_status"` // success / failed / running
LastMessage string `gorm:"size:500" json:"last_message,omitempty"`
RunCount int64 `gorm:"default:0" json:"run_count"`
LastDurationMs int `json:"last_duration_ms"`
UpdatedAt time.Time `json:"updated_at"`
}
func (SystemTaskStatus) TableName() string { return "sys_system_task_status" }