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:
1 parent
e57718998a
commit
77c234b060
314 files changed
+10050
-4065
No files matched your search
@@ -0,0 +1,217 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AgentReport Agent 上报的原始指标数据 // Logan.Li
|
||||
type AgentReport struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:255;index;not null" json:"hostname"`
|
||||
CPUUsage float64 `gorm:"type:decimal(6,2)" json:"cpu_usage"`
|
||||
CPUIOwait float64 `gorm:"type:decimal(6,2)" json:"cpu_iowait"`
|
||||
CPUCores int `json:"cpu_cores"`
|
||||
Load1 float64 `gorm:"type:decimal(8,2)" json:"load1"`
|
||||
Load5 float64 `gorm:"type:decimal(8,2)" json:"load5"`
|
||||
Load15 float64 `gorm:"type:decimal(8,2)" json:"load15"`
|
||||
MemTotal float64 `gorm:"type:decimal(10,2)" json:"mem_total"`
|
||||
MemUsed float64 `gorm:"type:decimal(10,2)" json:"mem_used"`
|
||||
MemUsage float64 `gorm:"type:decimal(6,2)" json:"mem_usage"`
|
||||
MemAvailable float64 `gorm:"type:decimal(10,2)" json:"mem_available"`
|
||||
MemSwapUsed float64 `gorm:"type:decimal(10,2)" json:"mem_swap_used"`
|
||||
DiskInfo string `gorm:"type:text" json:"disk_info"`
|
||||
PortInfo string `gorm:"type:text" json:"port_info"`
|
||||
NetInfo string `gorm:"type:text" json:"net_info"`
|
||||
DiskIOInfo string `gorm:"type:text" json:"disk_io_info"`
|
||||
// ──── v2.0 新增字段 ────
|
||||
SwapInfo string `gorm:"type:text" json:"swap_info"` // Swap JSON
|
||||
ProcessTopInfo string `gorm:"type:text" json:"process_top_info"` // 进程 TOP JSON
|
||||
FDInfo string `gorm:"type:text" json:"fd_info"` // FD 句柄 JSON
|
||||
CSInfo string `gorm:"type:text" json:"cs_info"` // 上下文切换 JSON
|
||||
HeartbeatInfo string `gorm:"type:text" json:"heartbeat_info"` // Agent 心跳 JSON
|
||||
// ──────────────────────────
|
||||
ReportTime time.Time `json:"report_time"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AgentReport) TableName() string {
|
||||
return "monitor_agent_reports"
|
||||
}
|
||||
|
||||
// AgentLatestResponse Agent 最新状态(含服务器元信息)
|
||||
type AgentLatestResponse struct {
|
||||
ServerID uint `json:"server_id"`
|
||||
Hostname string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
CPUCores int `json:"cpu_cores"`
|
||||
MemUsage float64 `json:"mem_usage"`
|
||||
MemTotal float64 `json:"mem_total"`
|
||||
MemUsed float64 `json:"mem_used"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
DiskTotal int64 `json:"disk_total"`
|
||||
DiskInfo string `json:"disk_info"`
|
||||
PortInfo string `json:"port_info"`
|
||||
NetInfo string `json:"net_info"`
|
||||
DiskIOInfo string `json:"disk_io_info"`
|
||||
// ──── v2.0 新增 ────
|
||||
SwapInfo string `json:"swap_info"`
|
||||
ProcessTopInfo string `json:"process_top_info"`
|
||||
FDInfo string `json:"fd_info"`
|
||||
CSInfo string `json:"cs_info"`
|
||||
HeartbeatInfo string `json:"heartbeat_info"`
|
||||
// ─────────────────
|
||||
ReportTime string `json:"report_time"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
AgentStatus string `json:"agent_status"`
|
||||
OS string `json:"os"`
|
||||
Kernel string `json:"kernel"`
|
||||
Uptime int64 `json:"uptime"`
|
||||
Region string `json:"region"`
|
||||
HasAuth bool `json:"has_auth"`
|
||||
}
|
||||
|
||||
// AgentReportRequest Agent 上报请求体
|
||||
type AgentReportRequest struct {
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
IP string `json:"ip"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
CPU CPUMetric `json:"cpu"`
|
||||
Memory MemMetric `json:"memory"`
|
||||
Swap *SwapMetric `json:"swap,omitempty"`
|
||||
Disks []DiskMetric `json:"disks"`
|
||||
Ports []PortMetric `json:"ports"`
|
||||
Network NetworkStatModel `json:"network"`
|
||||
DiskIO DiskIOStatModel `json:"disk_io"`
|
||||
System *SystemStatModel `json:"system,omitempty"`
|
||||
// ──── v2.0 新增 ────
|
||||
ProcessTop []ProcessMetric `json:"process_top,omitempty"`
|
||||
FD *FDMetric `json:"fd,omitempty"`
|
||||
ContextSwitches *CSMetric `json:"context_switches,omitempty"`
|
||||
Heartbeat HeartbeatMetric `json:"heartbeat"`
|
||||
ProbeResults []HealthProbeResult `json:"probe_results,omitempty"` // v2.1 健康探针结果
|
||||
}
|
||||
|
||||
// ──── v2.0 新增上报类型 ────
|
||||
|
||||
type SwapMetric struct {
|
||||
TotalGB float64 `json:"total_gb"`
|
||||
UsedGB float64 `json:"used_gb"`
|
||||
UsagePercent float64 `json:"usage_percent"`
|
||||
}
|
||||
|
||||
type ProcessMetric struct {
|
||||
PID int `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
Cmdline string `json:"cmdline"`
|
||||
User string `json:"user"`
|
||||
CPUPct float64 `json:"cpu_pct"`
|
||||
MemPct float64 `json:"mem_pct"`
|
||||
MemoryMB float64 `json:"memory_mb"`
|
||||
FDCount int `json:"fd_count"`
|
||||
Threads int `json:"threads"`
|
||||
}
|
||||
|
||||
type FDMetric struct {
|
||||
Allocated int `json:"allocated"`
|
||||
Max int64 `json:"max"`
|
||||
UsagePct float64 `json:"usage_pct"`
|
||||
}
|
||||
|
||||
type CSMetric struct {
|
||||
CTXPerSec float64 `json:"ctx_per_sec"`
|
||||
IRQPerSec float64 `json:"irq_per_sec"`
|
||||
}
|
||||
|
||||
type HeartbeatMetric struct {
|
||||
Version string `json:"version"`
|
||||
UptimeSec int64 `json:"uptime_sec"`
|
||||
LastErr string `json:"last_err,omitempty"`
|
||||
SelfCPU float64 `json:"self_cpu_pct"`
|
||||
SelfRSSMB float64 `json:"self_rss_mb"`
|
||||
ReportSeq uint64 `json:"report_seq"`
|
||||
}
|
||||
|
||||
// ──── 已有类型 ────
|
||||
|
||||
type SystemStatModel struct {
|
||||
OSVersion string `json:"os_version"`
|
||||
Kernel string `json:"kernel"`
|
||||
Uptime int64 `json:"uptime"`
|
||||
}
|
||||
|
||||
type CPUMetric struct {
|
||||
UsagePercent float64 `json:"usage_percent"`
|
||||
IOWait float64 `json:"iowait"`
|
||||
CoreCount int `json:"core_count"`
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
Load15 float64 `json:"load15"`
|
||||
}
|
||||
|
||||
type MemMetric struct {
|
||||
TotalGB float64 `json:"total_gb"`
|
||||
UsedGB float64 `json:"used_gb"`
|
||||
CachedGB float64 `json:"cached_gb"`
|
||||
AvailableGB float64 `json:"available_gb"`
|
||||
SwapUsedGB float64 `json:"swap_used_gb"`
|
||||
UsagePercent float64 `json:"usage_percent"`
|
||||
}
|
||||
|
||||
type DiskMetric struct {
|
||||
Mount string `json:"mount"`
|
||||
Device string `json:"device"`
|
||||
TotalGB float64 `json:"total_gb"`
|
||||
UsedGB float64 `json:"used_gb"`
|
||||
UsagePercent float64 `json:"usage_percent"`
|
||||
InodeUsagePct float64 `json:"inode_usage_pct"`
|
||||
}
|
||||
|
||||
type PortMetric struct {
|
||||
Port int `json:"port"`
|
||||
Protocol string `json:"protocol"`
|
||||
Process string `json:"process"`
|
||||
PID int `json:"pid"`
|
||||
}
|
||||
|
||||
type NetworkStatModel struct {
|
||||
TCPEstablished int `json:"tcp_established"`
|
||||
TCPTimeWait int `json:"tcp_time_wait"`
|
||||
TCPCloseWait int `json:"tcp_close_wait"`
|
||||
TCPTotal int `json:"tcp_total"`
|
||||
NicName string `json:"nic_name"`
|
||||
NetRxBPS float64 `json:"net_rx_bps"`
|
||||
NetTxBPS float64 `json:"net_tx_bps"`
|
||||
NetRxErrors int64 `json:"net_rx_errors"`
|
||||
NetTxErrors int64 `json:"net_tx_errors"`
|
||||
}
|
||||
|
||||
type DiskIOStatModel struct {
|
||||
ReadBPS float64 `json:"read_bps"`
|
||||
WriteBPS float64 `json:"write_bps"`
|
||||
ReadIOPS float64 `json:"read_iops"`
|
||||
WriteIOPS float64 `json:"write_iops"`
|
||||
Util float64 `json:"util"`
|
||||
}
|
||||
|
||||
// AgentPortPolicy 主机端口监控策略 // Logan.Li
|
||||
type AgentPortPolicy struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:255;uniqueIndex;not null" json:"hostname"`
|
||||
PortFilterMode string `gorm:"size:20;default:whitelist;not null" json:"port_filter_mode"` // whitelist / blacklist
|
||||
PortWhitelist string `gorm:"type:text" json:"port_whitelist"` // JSON 数组,如 [80,443,3306,6379]
|
||||
}
|
||||
|
||||
func (AgentPortPolicy) TableName() string {
|
||||
return "monitor_agent_port_policy"
|
||||
}
|
||||
|
||||
// AgentPortPolicyDTO 前端交互用的端口策略格式(含已解析的数组)
|
||||
type AgentPortPolicyDTO struct {
|
||||
Hostname string `json:"hostname"`
|
||||
PortFilterMode string `json:"port_filter_mode"`
|
||||
PortWhitelist []int `json:"port_whitelist"`
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user