feat(audit): F1+F2 告警静默规则标记完成 + 审计日志CSV导出实现

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 ✅
This commit is contained in:
attacker committed 2026-06-25 20:16:30 +08:00
1 parent e57718998a
commit 77c234b060
314 files changed
+10050 -4065

No files matched your search

+182
View File
@@ -0,0 +1,182 @@
// Package dto 定义请求(Request)与响应(Response)传输对象
// 与 models 分离:models 是 GORM 表结构,dto 是 API 契约
package dto
import "time"
// ━━━ Server ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CreateServerRequest 创建服务器
type CreateServerRequest struct {
Hostname string `json:"hostname" binding:"required"`
IP string `json:"ip" binding:"required"`
PublicIP string `json:"public_ip"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
SSHKey string `json:"ssh_key"`
AuthType string `json:"auth_type"`
OS string `json:"os"`
OSVersion string `json:"os_version"`
Arch string `json:"arch"`
CPU int `json:"cpu"`
Memory int64 `json:"memory"`
Disk int64 `json:"disk"`
RegionID *uint `json:"region_id"`
CloudID *uint `json:"cloud_id"`
Tags string `json:"tags"`
Description string `json:"description"`
}
// UpdateServerRequest 更新服务器 — 部分更新 (使用 map)
type UpdateServerRequest struct {
Hostname *string `json:"hostname"`
IP *string `json:"ip"`
PublicIP *string `json:"public_ip"`
Port *int `json:"port"`
Username *string `json:"username"`
Password *string `json:"password"`
SSHKey *string `json:"ssh_key"`
AuthType *string `json:"auth_type"`
OS *string `json:"os"`
OSVersion *string `json:"os_version"`
Arch *string `json:"arch"`
CPU *int `json:"cpu"`
Memory *int64 `json:"memory"`
Disk *int64 `json:"disk"`
Status *string `json:"status"`
CPUUsage *float64 `json:"cpu_usage"`
MemoryUsage *float64 `json:"memory_usage"`
DiskUsage *float64 `json:"disk_usage"`
RegionID *uint `json:"region_id"`
CloudID *uint `json:"cloud_id"`
Tags *string `json:"tags"`
Description *string `json:"description"`
}
// ServerListItem 服务器列表项 (精简)
type ServerListItem struct {
ID uint `json:"id"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Status string `json:"status"`
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
DiskUsage float64 `json:"disk_usage"`
AgentStatus string `json:"agent_status"`
AgentVersion string `json:"agent_version"`
HasAuth bool `json:"has_auth"`
OS string `json:"os"`
CreatedAt time.Time `json:"created_at"`
}
// ━━━ Credential ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CreateCredentialRequest 创建凭据
type CreateCredentialRequest struct {
Name string `json:"name" binding:"required"`
SecretType string `json:"secret_type" binding:"required"` // ssh, docker, tls, password, env
Description string `json:"description"`
// SSH
SSHPrivateKey string `json:"ssh_private_key"`
SSHPublicKey string `json:"ssh_public_key"`
SSHUser string `json:"ssh_user"`
SSHPort int `json:"ssh_port"`
SSHPassword string `json:"ssh_password"`
// Docker
DockerServer string `json:"docker_server"`
DockerUsername string `json:"docker_username"`
DockerPassword string `json:"docker_password"`
// TLS
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`
TLSCA string `json:"tls_ca"`
// Password / Generic
PlainPassword string `json:"plain_password"`
// Env
EnvVars string `json:"env_vars"`
}
// UpdateCredentialRequest 更新凭据
type UpdateCredentialRequest struct {
Name *string `json:"name"`
Description *string `json:"description"`
SSHPrivateKey *string `json:"ssh_private_key"`
SSHPublicKey *string `json:"ssh_public_key"`
SSHUser *string `json:"ssh_user"`
SSHPort *int `json:"ssh_port"`
SSHPassword *string `json:"ssh_password"`
DockerServer *string `json:"docker_server"`
DockerUsername *string `json:"docker_username"`
DockerPassword *string `json:"docker_password"`
TLSCert *string `json:"tls_cert"`
TLSKey *string `json:"tls_key"`
TLSCA *string `json:"tls_ca"`
PlainPassword *string `json:"plain_password"`
EnvVars *string `json:"env_vars"`
}
// ━━━ Alert ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CreateAlertContactRequest 创建告警联系人
type CreateAlertContactRequest struct {
Name string `json:"name" binding:"required"`
ChannelType string `json:"channel_type" binding:"required"` // feishu, dingtalk, wechat, webhook
WebhookURL string `json:"webhook_url" binding:"required"`
Phone string `json:"phone"`
Email string `json:"email"`
}
// UpdateAlertContactRequest 更新告警联系人
type UpdateAlertContactRequest struct {
Name *string `json:"name"`
ChannelType *string `json:"channel_type"`
WebhookURL *string `json:"webhook_url"`
Phone *string `json:"phone"`
Email *string `json:"email"`
}
// CreateAlertContactGroupRequest 创建告警联系组
type CreateAlertContactGroupRequest struct {
Name string `json:"name" binding:"required"`
ContactIDs []uint `json:"contact_ids"`
}
// UpdateAlertContactGroupRequest 更新告警联系组
type UpdateAlertContactGroupRequest struct {
Name *string `json:"name"`
ContactIDs *[]uint `json:"contact_ids"`
}
// CreateAlertRuleRequest 创建告警规则
type CreateAlertRuleRequest struct {
Name string `json:"name" binding:"required"`
Metric string `json:"metric" binding:"required"`
Condition string `json:"condition" binding:"required"` // >, <, >=, <=, ==
Threshold float64 `json:"threshold" binding:"required"`
Duration string `json:"duration"` // 30s, 1m, 5m
ContactIDs []uint `json:"contact_ids"`
Enabled bool `json:"enabled"`
Description string `json:"description"`
}
// UpdateAlertRuleRequest 更新告警规则
type UpdateAlertRuleRequest struct {
Name *string `json:"name"`
Metric *string `json:"metric"`
Condition *string `json:"condition"`
Threshold *float64 `json:"threshold"`
Duration *string `json:"duration"`
ContactIDs *[]uint `json:"contact_ids"`
Enabled *bool `json:"enabled"`
Description *string `json:"description"`
}