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

+44 -8
View File
@@ -4,19 +4,22 @@ import (
"ezops/model"
"net/http"
"strconv"
"sync"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// SNMPHandler SNMP 设备管理 handler // Logan.Li
// SNMPHandler SNMP 设备管理 + 采集 handler // Logan.Li
type SNMPHandler struct {
db *gorm.DB
db *gorm.DB
stopCh chan struct{}
wg sync.WaitGroup
}
// NewSNMPHandler 创建 SNMP handler
func NewSNMPHandler(db *gorm.DB) *SNMPHandler {
return &SNMPHandler{db: db}
return &SNMPHandler{db: db, stopCh: make(chan struct{})}
}
// ========== SNMP Device CRUD ==========
@@ -46,11 +49,42 @@ func (h *SNMPHandler) ListDevices(c *gin.Context) {
// CreateDevice 创建 SNMP 设备
// POST /api/v1/snmp/devices
func (h *SNMPHandler) CreateDevice(c *gin.Context) {
var device model.SNMPDevice
if err := c.ShouldBindJSON(&device); err != nil {
var req struct {
Name string `json:"name" binding:"required"`
IP string `json:"ip" binding:"required"`
Port int `json:"port"`
SnmpVersion string `json:"snmp_version"`
Version string `json:"version"`
Community string `json:"community"`
TemplateID uint `json:"template_id"`
DeviceType string `json:"device_type"`
Vendor string `json:"vendor"`
Description string `json:"description"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: err.Error()})
return
}
ver := req.SnmpVersion
if ver == "" {
ver = req.Version
}
if ver == "" {
ver = "v2c"
}
device := model.SNMPDevice{
Name: req.Name, IP: req.IP, Port: req.Port,
Version: model.SNMPVersion(ver), Community: req.Community,
TemplateID: req.TemplateID, DeviceType: req.DeviceType,
Vendor: req.Vendor, Description: req.Description,
Status: model.SNMPDeviceOffline,
}
if device.Port == 0 {
device.Port = 161
}
if device.Community == "" {
device.Community = "public"
}
if err := h.db.Create(&device).Error; err != nil {
c.JSON(http.StatusInternalServerError, model.Response{Code: 500, Message: err.Error()})
return
@@ -100,15 +134,17 @@ func (h *SNMPHandler) BatchDeleteDevices(c *gin.Context) {
// ========== SNMP Template CRUD ==========
// ListTemplates 列出 OID 模板
// ListTemplates 列出 OID 模板(含 OID 条目)// Logan.Li
// GET /api/v1/snmp/templates
func (h *SNMPHandler) ListTemplates(c *gin.Context) {
var templates []model.SNMPTemplate
h.db.Order("name ASC").Find(&templates)
h.db.Preload("OIDs", func(db *gorm.DB) *gorm.DB {
return db.Order("sort_order ASC")
}).Order("name ASC").Find(&templates)
if templates == nil {
templates = []model.SNMPTemplate{}
}
c.JSON(http.StatusOK, model.Response{Code: 200, Data: templates})
c.JSON(http.StatusOK, model.Response{Code: 200, Data: gin.H{"list": templates, "total": len(templates)}})
}
// CreateTemplate 创建 OID 模板