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:
1 parent
092d0e4b9e
commit
471353e3d7
190 files changed
+16640
-3484
No files matched your search
+56
-1
@@ -690,9 +690,64 @@ func SeedData(db *gorm.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 种子工具配置(kubectl/maven/node/ansible/git/docker)// Logan.Li
|
||||
// 7. 默认审计保留策略(180 天) // Logan.Li
|
||||
var auditSettingsCount int64
|
||||
db.Model(&model.AuditSettings{}).Count(&auditSettingsCount)
|
||||
if auditSettingsCount == 0 {
|
||||
if err := db.Create(&model.AuditSettings{RetentionDays: 180, RecordAll: true}).Error; err != nil {
|
||||
zap.L().Warn("failed to seed audit settings", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
// 8. 补全自动化运维角色权限(已有库升级时确保 auto:* 已分配) // Logan.Li
|
||||
ensureAutoOpsRolePermissions(db)
|
||||
|
||||
// 9. 种子工具配置(kubectl/maven/node/ansible/git/docker)// Logan.Li
|
||||
ti := toolinstaller.New(db)
|
||||
ti.SeedTools()
|
||||
|
||||
// 10. SNMP OID 模板(H3C/华为网络设备)// Logan.Li
|
||||
SeedSNMPTemplates(db)
|
||||
|
||||
// 11. 站点/中间件/SNMP 默认告警规则(含 HTTPS 证书 < 30 天预警)// Logan.Li
|
||||
SeedMonitorAlertRules(db)
|
||||
}
|
||||
|
||||
// SeedMonitorAlertRules 初始化监控告警默认规则(幂等)// Logan.Li
|
||||
func SeedMonitorAlertRules(db *gorm.DB) {
|
||||
defaults := []model.MonitorAlertRule{
|
||||
{Category: model.MonitorAlertSite, Name: "拨测失败", Metric: "probe_fail", Operator: "==", Threshold: 1, Severity: "critical", Enabled: true, Description: "拨测连续失败"},
|
||||
{Category: model.MonitorAlertSite, Name: "响应延迟过高", Metric: "response_time", Operator: ">", Threshold: 500, Severity: "warning", Enabled: true, Description: "延迟 > 500ms"},
|
||||
{Category: model.MonitorAlertSite, Name: "可用率过低", Metric: "availability", Operator: "<", Threshold: 99, Severity: "warning", Enabled: true, Description: "1h 可用率 < 99%"},
|
||||
{Category: model.MonitorAlertSite, Name: "SSL 证书即将过期", Metric: "ssl_expiry_days", Operator: "<", Threshold: 30, Severity: "warning", Enabled: true, Description: "SSL 拨测证书剩余 < 30 天"},
|
||||
}
|
||||
for _, r := range defaults {
|
||||
var exist model.MonitorAlertRule
|
||||
db.Where("name = ? AND category = ?", r.Name, r.Category).First(&exist)
|
||||
if exist.ID == 0 {
|
||||
if err := db.Create(&r).Error; err != nil {
|
||||
zap.L().Warn("seed monitor alert rule failed", zap.String("name", r.Name), zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ensureAutoOpsRolePermissions 为运维类角色补充 auto:script / auto:cron 权限 // Logan.Li
|
||||
func ensureAutoOpsRolePermissions(db *gorm.DB) {
|
||||
autoCodes := []string{"auto:cron", "auto:script", "auto:ansible"}
|
||||
var perms []model.Permission
|
||||
db.Where("code IN ?", autoCodes).Find(&perms)
|
||||
if len(perms) == 0 {
|
||||
return
|
||||
}
|
||||
roleCodes := []string{"resource_admin", "release_admin", "k8s_admin", "super_admin"}
|
||||
for _, rc := range roleCodes {
|
||||
var role model.Role
|
||||
if err := db.Where("code = ?", rc).First(&role).Error; err != nil {
|
||||
continue
|
||||
}
|
||||
db.Model(&role).Association("Permissions").Append(perms)
|
||||
}
|
||||
}
|
||||
|
||||
// dedupeUint 去重 uint 切片
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
snmppkg "ezops/pkg/snmp"
|
||||
"ezops/model"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SeedSNMPTemplates 种子 H3C/华为等内置 OID 模板 // Logan.Li
|
||||
func SeedSNMPTemplates(db *gorm.DB) {
|
||||
for _, bt := range snmppkg.BuiltinTemplates() {
|
||||
var exist model.SNMPTemplate
|
||||
db.Where("name = ? AND is_system = ?", bt.Name, true).First(&exist)
|
||||
if exist.ID > 0 {
|
||||
continue
|
||||
}
|
||||
tpl := model.SNMPTemplate{
|
||||
Name: bt.Name, Description: bt.Description,
|
||||
DeviceType: bt.DeviceType, Vendor: bt.Vendor,
|
||||
IsDefault: bt.Vendor == "H3C" && bt.DeviceType == "switch",
|
||||
IsSystem: true, Status: 1,
|
||||
}
|
||||
if err := db.Create(&tpl).Error; err != nil {
|
||||
zap.L().Warn("seed snmp template failed", zap.String("name", bt.Name), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
for _, o := range bt.OIDs {
|
||||
oid := model.SNMPTemplateOID{
|
||||
TemplateID: tpl.ID, Name: o.Name, OID: o.OID,
|
||||
Description: o.Description, DataType: o.DataType,
|
||||
Unit: o.Unit, SortOrder: o.SortOrder,
|
||||
}
|
||||
if o.IsTable {
|
||||
oid.Conversion = "table"
|
||||
}
|
||||
db.Create(&oid)
|
||||
}
|
||||
zap.L().Info("seeded snmp template", zap.String("name", bt.Name), zap.Int("oids", len(bt.OIDs)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user