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

+125
View File
@@ -0,0 +1,125 @@
package model
import (
"time"
)
// CronJob 定时任务模型
type CronJob struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Description string `gorm:"size:500" json:"description"`
CronExpr string `gorm:"size:64;not null" json:"cron_expr"`
Type string `gorm:"size:32;not null" json:"type"` // shell, python, command
Content string `gorm:"type:text" json:"content"`
ScriptID *uint `json:"script_id"`
TargetType string `gorm:"size:32;default:server" json:"target_type"` // server, group, tag
Targets string `gorm:"type:text" json:"targets"` // JSON
Timeout int `gorm:"default:300" json:"timeout"`
Enabled bool `gorm:"default:true" json:"enabled"`
LastRunAt *time.Time `json:"last_run_at"`
LastStatus string `gorm:"size:32" json:"last_status"`
RunCount int `gorm:"default:0" json:"run_count"`
SuccessCount int `gorm:"default:0" json:"success_count"`
FailCount int `gorm:"default:0" json:"fail_count"`
NotifyOn string `gorm:"size:32;default:failure" json:"notify_on"` // always, failure, success
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联
Script *Script `json:"script,omitempty"`
}
// TableName 表名
func (CronJob) TableName() string {
return "ops_cron_jobs"
}
// Script 脚本库模型
type Script struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
Description string `gorm:"size:500" json:"description"`
Type string `gorm:"size:32;default:shell" json:"type"` // shell, python
Content string `gorm:"type:text;not null" json:"content"`
Params string `gorm:"type:text" json:"params"` // JSON
Timeout int `gorm:"default:300" json:"timeout"`
Version int `gorm:"default:1" json:"version"`
RunCount int `gorm:"default:0" json:"run_count"`
CreatedBy uint `json:"created_by"`
UpdatedBy uint `json:"updated_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名
func (Script) TableName() string {
return "ops_scripts"
}
// TaskExecution 任务执行记录(cron / script,不含 Ansible;Ansible 走 AnsibleJob)
type TaskExecution struct {
ID uint `gorm:"primarykey" json:"id"`
TaskType string `gorm:"size:32;not null" json:"task_type"` // cron, script
TaskID uint `json:"task_id"`
TaskName string `gorm:"size:128" json:"task_name"`
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
TargetType string `gorm:"size:32" json:"target_type"`
Targets string `gorm:"type:text" json:"targets"`
Output string `gorm:"type:longtext" json:"output"`
Error string `gorm:"type:text" json:"error"`
Duration int `json:"duration"`
StartedAt *time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at"`
CreatedBy uint `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名
func (TaskExecution) TableName() string {
return "ops_task_executions"
}
// CreateCronJobRequest 创建定时任务请求
type CreateCronJobRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
CronExpr string `json:"cron_expr" binding:"required"`
Type string `json:"type" binding:"required,oneof=shell python command"`
Content string `json:"content"`
ScriptID *uint `json:"script_id"`
TargetType string `json:"target_type" binding:"omitempty,oneof=server group tag"`
Targets []uint `json:"targets"`
Timeout int `json:"timeout"`
NotifyOn string `json:"notify_on" binding:"omitempty,oneof=always failure success"`
}
// CreateScriptRequest 创建脚本请求
type CreateScriptRequest struct {
Name string `json:"name" binding:"required"`
Code string `json:"code" binding:"required"`
Description string `json:"description"`
Type string `json:"type" binding:"omitempty,oneof=shell python"`
Content string `json:"content" binding:"required"`
Params string `json:"params"`
Timeout int `json:"timeout"`
}
// ExecuteScriptRequest 执行脚本请求
type ExecuteScriptRequest struct {
TargetType string `json:"target_type" binding:"required,oneof=server group tag"`
Targets []uint `json:"targets" binding:"required"`
Params map[string]string `json:"params"`
}
// AutomationStats 自动化统计
type AutomationStats struct {
CronJobCount int64 `json:"cron_job_count"`
ScriptCount int64 `json:"script_count"`
PlaybookCount int64 `json:"playbook_count"`
TodayExecutions int64 `json:"today_executions"`
SuccessRate float64 `json:"success_rate"`
}