F1 告警静默规则 [done]: - 后端 alert_silence.go: CRUD + Toggle (onetime/daily/weekly 三模式) - 告警引擎 isSilenced 集成 (alert_engine.go) - 前端 SilenceRuleTab + SilenceDialog - 路由 /alerts/silences 已注册 F2 审计日志导出 [done]: - 重写 ExportAuditLogs: 真正的 CSV 导出 (encoding/csv + UTF-8 BOM) - 支持 module/action/username/startTime/endTime 筛选 - 导出限制 10000 条防溢出,自动记录审计日志 - JSON 格式向后兼容 (format=json) - 前端 exportLogs 传递查询参数 同时包含累积的前期工作: - 目录重构 internal/ -> controller/model/router (v0.55-v0.57) - 后端分层架构 dto/repository/service/utils - 审计模块全功能 (终端审计/操作审计/登录日志) - asciicast v2 录制格式 - SFTP 文件浏览器 - StatStrip 紧凑统计条 - 在线会话自动刷新 - LiveMonitor WebSocket 诊断修复 验证: go build ✅ | npm run build ✅ | Docker 部署 ✅ | 10 回归端点 ✅ | CSV 导出 ✅ | 静默 CRUD ✅
133 lines
3.6 KiB
Go
133 lines
3.6 KiB
Go
package controller
|
||
|
||
import (
|
||
"net/http"
|
||
"strconv"
|
||
"strings"
|
||
|
||
"ezops/model"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// ==================== 云平台(Platform / Cloud)====================
|
||
|
||
// PlatformHandler 云平台处理器
|
||
type PlatformHandler struct {
|
||
db *gorm.DB
|
||
}
|
||
|
||
func NewPlatformHandler(db *gorm.DB) *PlatformHandler {
|
||
return &PlatformHandler{db: db}
|
||
}
|
||
|
||
// platformRequest 云平台创建/更新请求
|
||
type platformRequest struct {
|
||
Name string `json:"name"`
|
||
Code string `json:"code"`
|
||
Type string `json:"type"`
|
||
Status string `json:"status"`
|
||
Website string `json:"website"`
|
||
Description string `json:"description"`
|
||
}
|
||
|
||
// ListPlatforms 获取云平台列表
|
||
func (h *PlatformHandler) ListPlatforms(c *gin.Context) {
|
||
var platforms []model.Cloud
|
||
h.db.Find(&platforms)
|
||
|
||
c.JSON(http.StatusOK, model.Response{
|
||
Code: 200,
|
||
Message: "success",
|
||
Data: model.ListResponse{
|
||
List: platforms,
|
||
Total: int64(len(platforms)),
|
||
},
|
||
})
|
||
}
|
||
|
||
// CreatePlatform 创建云平台
|
||
func (h *PlatformHandler) CreatePlatform(c *gin.Context) {
|
||
var req platformRequest
|
||
if err := c.ShouldBindJSON(&req); err != nil {
|
||
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "请求参数错误: " + err.Error()})
|
||
return
|
||
}
|
||
if strings.TrimSpace(req.Name) == "" || strings.TrimSpace(req.Code) == "" {
|
||
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "平台名称和编码不能为空"})
|
||
return
|
||
}
|
||
|
||
cloudType := strings.TrimSpace(req.Type)
|
||
if cloudType == "" {
|
||
cloudType = "public"
|
||
}
|
||
status := strings.TrimSpace(req.Status)
|
||
if status == "" {
|
||
status = "active"
|
||
}
|
||
|
||
platform := model.Cloud{
|
||
Name: strings.TrimSpace(req.Name),
|
||
Code: strings.TrimSpace(req.Code),
|
||
Type: cloudType,
|
||
Status: status,
|
||
Website: req.Website,
|
||
Description: req.Description,
|
||
}
|
||
if err := h.db.Create(&platform).Error; err != nil {
|
||
c.JSON(http.StatusInternalServerError, model.Response{Code: 500, Message: "创建失败,编码可能已存在"})
|
||
return
|
||
}
|
||
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "创建成功", Data: platform})
|
||
}
|
||
|
||
// UpdatePlatform 更新云平台
|
||
func (h *PlatformHandler) UpdatePlatform(c *gin.Context) {
|
||
id, _ := strconv.Atoi(c.Param("id"))
|
||
var req platformRequest
|
||
if err := c.ShouldBindJSON(&req); err != nil {
|
||
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "请求参数错误: " + err.Error()})
|
||
return
|
||
}
|
||
|
||
var platform model.Cloud
|
||
if err := h.db.First(&platform, id).Error; err != nil {
|
||
c.JSON(http.StatusNotFound, model.Response{Code: 404, Message: "云平台不存在"})
|
||
return
|
||
}
|
||
|
||
if strings.TrimSpace(req.Name) != "" {
|
||
platform.Name = strings.TrimSpace(req.Name)
|
||
}
|
||
if strings.TrimSpace(req.Code) != "" {
|
||
platform.Code = strings.TrimSpace(req.Code)
|
||
}
|
||
if strings.TrimSpace(req.Type) != "" {
|
||
platform.Type = strings.TrimSpace(req.Type)
|
||
}
|
||
if strings.TrimSpace(req.Status) != "" {
|
||
platform.Status = strings.TrimSpace(req.Status)
|
||
}
|
||
platform.Website = req.Website
|
||
platform.Description = req.Description
|
||
|
||
if err := h.db.Save(&platform).Error; err != nil {
|
||
c.JSON(http.StatusInternalServerError, model.Response{Code: 500, Message: "更新失败"})
|
||
return
|
||
}
|
||
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "更新成功", Data: platform})
|
||
}
|
||
|
||
// DeletePlatform 删除云平台
|
||
func (h *PlatformHandler) DeletePlatform(c *gin.Context) {
|
||
id, _ := strconv.Atoi(c.Param("id"))
|
||
if err := h.db.Delete(&model.Cloud{}, id).Error; err != nil {
|
||
c.JSON(http.StatusInternalServerError, model.Response{Code: 500, Message: "删除失败"})
|
||
return
|
||
}
|
||
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "删除成功"})
|
||
}
|
||
|