告警中心 - 新增统一告警(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>
228 lines
6.0 KiB
Go
228 lines
6.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"ezops/dto"
|
|
"ezops/model"
|
|
"ezops/service"
|
|
"ezops/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ━━━ Credential Handler (v2 thin) ━━━━━━━━━━━━━━━━━━━━━━━
|
|
|
|
type CredentialHandlerV2 struct {
|
|
svc *service.CredentialService
|
|
}
|
|
|
|
func NewCredentialHandlerV2(svc *service.CredentialService) *CredentialHandlerV2 {
|
|
return &CredentialHandlerV2{svc: svc}
|
|
}
|
|
|
|
func (h *CredentialHandlerV2) ListCredentials(c *gin.Context) {
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
keyword := c.Query("keyword")
|
|
secretType := c.Query("secret_type")
|
|
|
|
list, total, err := h.svc.List(keyword, secretType, page, pageSize)
|
|
if err != nil {
|
|
utils.InternalError(c, "查询失败")
|
|
return
|
|
}
|
|
utils.ListResponse(c, list, total)
|
|
}
|
|
|
|
func (h *CredentialHandlerV2) GetCredential(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
crd, err := h.svc.GetByID(uint(id))
|
|
if err != nil {
|
|
utils.NotFound(c, "凭据不存在")
|
|
return
|
|
}
|
|
utils.OK(c, crd)
|
|
}
|
|
|
|
func (h *CredentialHandlerV2) CreateCredential(c *gin.Context) {
|
|
var req dto.CreateCredentialRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
crd, err := h.svc.Create(&req)
|
|
if err != nil {
|
|
utils.InternalError(c, "创建失败: "+err.Error())
|
|
return
|
|
}
|
|
utils.OK(c, crd)
|
|
}
|
|
|
|
func (h *CredentialHandlerV2) UpdateCredential(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
var req dto.UpdateCredentialRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
if err := h.svc.Update(uint(id), &req); err != nil {
|
|
utils.InternalError(c, "更新失败: "+err.Error())
|
|
return
|
|
}
|
|
crd, _ := h.svc.GetByID(uint(id))
|
|
utils.OK(c, crd)
|
|
}
|
|
|
|
func (h *CredentialHandlerV2) DeleteCredential(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
if err := h.svc.Delete(uint(id)); err != nil {
|
|
utils.InternalError(c, "删除失败")
|
|
return
|
|
}
|
|
utils.OK(c, gin.H{"id": id})
|
|
}
|
|
|
|
// ━━━ Alert Contact Handler (v2 thin) ━━━━━━━━━━━━━━━━━━━━
|
|
|
|
type AlertContactHandlerV2 struct {
|
|
svc *service.AlertContactService
|
|
}
|
|
|
|
func NewAlertContactHandlerV2(svc *service.AlertContactService) *AlertContactHandlerV2 {
|
|
return &AlertContactHandlerV2{svc: svc}
|
|
}
|
|
|
|
func (h *AlertContactHandlerV2) ListContacts(c *gin.Context) {
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
keyword := c.Query("keyword")
|
|
|
|
list, total, err := h.svc.List(keyword, page, pageSize)
|
|
if err != nil {
|
|
utils.InternalError(c, "查询失败: "+err.Error())
|
|
return
|
|
}
|
|
utils.ListResponse(c, list, total)
|
|
}
|
|
|
|
func (h *AlertContactHandlerV2) GetContact(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
contact, err := h.svc.GetByID(uint(id))
|
|
if err != nil {
|
|
utils.NotFound(c, "联系人不存在")
|
|
return
|
|
}
|
|
utils.OK(c, contact)
|
|
}
|
|
|
|
func (h *AlertContactHandlerV2) CreateContact(c *gin.Context) {
|
|
var req dto.CreateAlertContactRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
contact, err := h.svc.Create(&req)
|
|
if err != nil {
|
|
utils.InternalError(c, "创建失败: "+err.Error())
|
|
return
|
|
}
|
|
utils.OK(c, contact)
|
|
}
|
|
|
|
func (h *AlertContactHandlerV2) UpdateContact(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
var req dto.UpdateAlertContactRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
if err := h.svc.Update(uint(id), &req); err != nil {
|
|
utils.InternalError(c, "更新失败")
|
|
return
|
|
}
|
|
contact, _ := h.svc.GetByID(uint(id))
|
|
utils.OK(c, contact)
|
|
}
|
|
|
|
func (h *AlertContactHandlerV2) DeleteContact(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
if err := h.svc.Delete(uint(id)); err != nil {
|
|
utils.InternalError(c, "删除失败")
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "删除成功"})
|
|
}
|
|
|
|
// ━━━ Alert Contact Group Handler (v2 thin) ━━━━━━━━━━━━━━
|
|
|
|
type AlertContactGroupHandlerV2 struct {
|
|
svc *service.AlertContactGroupService
|
|
}
|
|
|
|
func NewAlertContactGroupHandlerV2(svc *service.AlertContactGroupService) *AlertContactGroupHandlerV2 {
|
|
return &AlertContactGroupHandlerV2{svc: svc}
|
|
}
|
|
|
|
func (h *AlertContactGroupHandlerV2) ListGroups(c *gin.Context) {
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
keyword := c.Query("keyword")
|
|
|
|
list, total, err := h.svc.List(keyword, page, pageSize)
|
|
if err != nil {
|
|
utils.InternalError(c, "查询失败")
|
|
return
|
|
}
|
|
utils.ListResponse(c, list, total)
|
|
}
|
|
|
|
func (h *AlertContactGroupHandlerV2) GetGroup(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
g, err := h.svc.GetByID(uint(id))
|
|
if err != nil {
|
|
utils.NotFound(c, "联系组不存在")
|
|
return
|
|
}
|
|
utils.OK(c, g)
|
|
}
|
|
|
|
func (h *AlertContactGroupHandlerV2) CreateGroup(c *gin.Context) {
|
|
var req dto.CreateAlertContactGroupRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
g, err := h.svc.Create(&req)
|
|
if err != nil {
|
|
utils.InternalError(c, "创建失败")
|
|
return
|
|
}
|
|
utils.OK(c, g)
|
|
}
|
|
|
|
func (h *AlertContactGroupHandlerV2) UpdateGroup(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
var req dto.UpdateAlertContactGroupRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
utils.BadRequest(c, "请求参数错误: "+err.Error())
|
|
return
|
|
}
|
|
if err := h.svc.Update(uint(id), &req); err != nil {
|
|
utils.InternalError(c, "更新失败")
|
|
return
|
|
}
|
|
g, _ := h.svc.GetByID(uint(id))
|
|
utils.OK(c, g)
|
|
}
|
|
|
|
func (h *AlertContactGroupHandlerV2) DeleteGroup(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
if err := h.svc.Delete(uint(id)); err != nil {
|
|
utils.InternalError(c, "删除失败")
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "删除成功"})
|
|
}
|