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,202 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// KubernetesCluster K8s集群模型
|
||||
type KubernetesCluster 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"`
|
||||
Version string `gorm:"size:32" json:"version"`
|
||||
Status string `gorm:"size:32;default:healthy" json:"status"` // healthy, warning, error
|
||||
ConfigType int `gorm:"default:1" json:"config_type"` // 0=token, 1=kubeconfig
|
||||
APIServer string `gorm:"size:255" json:"api_server"`
|
||||
APIEndpoint string `gorm:"size:255" json:"api_endpoint"`
|
||||
Token string `gorm:"type:text" json:"-"`
|
||||
KubeConfig string `gorm:"type:text" json:"-"`
|
||||
NodeCount int `gorm:"default:0" json:"node_count"`
|
||||
PodCount int `gorm:"default:0" json:"pod_count"`
|
||||
ServiceCount int `gorm:"default:0" json:"service_count"`
|
||||
DeploymentCount int `gorm:"default:0" json:"deployment_count"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Labels string `gorm:"type:text" json:"labels"` // JSON
|
||||
LastSyncAt *time.Time `json:"last_sync_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesCluster) TableName() string {
|
||||
return "kubernetes_clusters"
|
||||
}
|
||||
|
||||
// KubernetesNode K8s节点模型
|
||||
type KubernetesNode struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
Role string `gorm:"size:32" json:"role"` // master, worker
|
||||
Status string `gorm:"size:32" json:"status"`
|
||||
OS string `gorm:"size:64" json:"os"`
|
||||
KubeletVer string `gorm:"size:32" json:"kubelet_version"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
PodCount int `json:"pod_count"`
|
||||
MaxPods int `json:"max_pods"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Cluster *KubernetesCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesNode) TableName() string {
|
||||
return "kubernetes_nodes"
|
||||
}
|
||||
|
||||
// KubernetesPod K8s Pod模型
|
||||
type KubernetesPod struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Status string `gorm:"size:32" json:"status"` // Running, Pending, Succeeded, Failed
|
||||
NodeName string `gorm:"size:128" json:"node_name"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
RestartCount int `json:"restart_count"`
|
||||
Image string `gorm:"size:255" json:"image"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Cluster *KubernetesCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesPod) TableName() string {
|
||||
return "kubernetes_pods"
|
||||
}
|
||||
|
||||
// KubernetesDeployment K8s Deployment模型
|
||||
type KubernetesDeployment struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Replicas int `json:"replicas"`
|
||||
AvailableReplicas int `json:"available_replicas"`
|
||||
ReadyReplicas int `json:"ready_replicas"`
|
||||
Image string `gorm:"size:255" json:"image"`
|
||||
Strategy string `gorm:"size:32" json:"strategy"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Cluster *KubernetesCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesDeployment) TableName() string {
|
||||
return "kubernetes_deployments"
|
||||
}
|
||||
|
||||
// KubernetesService K8s Service模型
|
||||
type KubernetesService struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Type string `gorm:"size:32" json:"type"` // ClusterIP, NodePort, LoadBalancer
|
||||
ClusterIP string `gorm:"size:64" json:"cluster_ip"`
|
||||
ExternalIP string `gorm:"size:255" json:"external_ip"`
|
||||
Ports string `gorm:"type:text" json:"ports"` // JSON
|
||||
Selector string `gorm:"type:text" json:"selector"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Cluster *KubernetesCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesService) TableName() string {
|
||||
return "kubernetes_services"
|
||||
}
|
||||
|
||||
// KubernetesIngress K8s Ingress模型
|
||||
type KubernetesIngress struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Hosts string `gorm:"type:text" json:"hosts"` // JSON
|
||||
Backend string `gorm:"size:255" json:"backend"`
|
||||
TLS bool `json:"tls"`
|
||||
TLSHosts string `gorm:"type:text" json:"tls_hosts"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Cluster *KubernetesCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesIngress) TableName() string {
|
||||
return "kubernetes_ingresses"
|
||||
}
|
||||
|
||||
// CreateKubernetesClusterRequest 创建K8s集群请求
|
||||
type CreateKubernetesClusterRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Version string `json:"version"`
|
||||
ConfigType int `json:"config_type"` // 0=token, 1=kubeconfig
|
||||
APIServer string `json:"api_server"`
|
||||
APIEndpoint string `json:"api_endpoint"`
|
||||
Token string `json:"token"`
|
||||
KubeConfig string `json:"kube_config"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// KubernetesClusterStats K8s集群统计
|
||||
type KubernetesClusterStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Healthy int64 `json:"healthy"`
|
||||
Warning int64 `json:"warning"`
|
||||
Error int64 `json:"error"`
|
||||
TotalNodes int64 `json:"total_nodes"`
|
||||
TotalPods int64 `json:"total_pods"`
|
||||
TotalServices int64 `json:"total_services"`
|
||||
}
|
||||
|
||||
// TopologyLayout 拓扑布局(保存节点位置 + 自定义节点 + 自定义连线) // Logan.Li
|
||||
type TopologyLayout struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"uniqueIndex;not null" json:"cluster_id"`
|
||||
LayoutData string `gorm:"type:text" json:"layout_data"` // JSON: {positions, customNodes, customEdges}
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (TopologyLayout) TableName() string {
|
||||
return "kubernetes_topology_layouts"
|
||||
}
|
||||
Reference in new issue
Block a user