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

+105
View File
@@ -0,0 +1,105 @@
package model
import (
"time"
)
// CloudBilling 云账单模型 - 每日成本记录
type CloudBilling struct {
ID uint `gorm:"primarykey" json:"id"`
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"`
AccountName string `gorm:"size:128" json:"account_name"`
Provider string `gorm:"size:64;index" json:"provider"` // aliyun, tencent, aws, huawei, azure
BillingDate string `gorm:"size:10;index;not null" json:"billing_date"` // YYYY-MM-DD
Cost float64 `gorm:"type:decimal(12,2);default:0" json:"cost"` // 费用(元)
Currency string `gorm:"size:8;default:CNY" json:"currency"` // CNY, USD
Service string `gorm:"size:128" json:"service"` // ECS, RDS, OSS, CDN 等
Region string `gorm:"size:64" json:"region"`
Tags string `gorm:"type:text" json:"tags"` // JSON
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (CloudBilling) TableName() string {
return "asset_cloud_billings"
}
// BillingAlertRule 账单预警规则
type BillingAlertRule struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Provider string `gorm:"size:64" json:"provider"` // 空=所有云厂商
CloudAccountID *uint `gorm:"index" json:"cloud_account_id"` // 空=所有账号
Metric string `gorm:"size:32;default:daily" json:"metric"` // daily, monthly
Threshold float64 `gorm:"type:decimal(12,2)" json:"threshold"` // 阈值(元)
Operator string `gorm:"size:8;default:>" json:"operator"` // >, >=, <, <=
Enabled bool `gorm:"default:true" json:"enabled"`
LastTriggered *time.Time `json:"last_triggered"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (BillingAlertRule) TableName() string {
return "monitor_billing_alert_rules"
}
// BillingStats 账单统计
type BillingStats struct {
TodayCost float64 `json:"today_cost"`
MonthCost float64 `json:"month_cost"`
YearCost float64 `json:"year_cost"`
YesterdayCost float64 `json:"yesterday_cost"`
MonthTrend []DailyCost `json:"month_trend"`
ProviderDist []ProviderCost `json:"provider_dist"`
Alerts []BillingAlert `json:"alerts"`
}
// DailyCost 每日成本
type DailyCost struct {
Date string `json:"date"`
Cost float64 `json:"cost"`
}
// ProviderCost 厂商成本分布
type ProviderCost struct {
Provider string `json:"provider"`
Cost float64 `json:"cost"`
Percent float64 `json:"percent"`
}
// BillingAlert 账单预警
type BillingAlert struct {
RuleID uint `json:"rule_id"`
RuleName string `json:"rule_name"`
Provider string `json:"provider"`
Current float64 `json:"current"`
Threshold float64 `json:"threshold"`
Metric string `json:"metric"`
Operator string `json:"operator"`
}
// CreateBillingRequest 创建账单记录请求
type CreateBillingRequest struct {
CloudAccountID *uint `json:"cloud_account_id"`
AccountName string `json:"account_name"`
Provider string `json:"provider" binding:"required"`
BillingDate string `json:"billing_date" binding:"required"`
Cost float64 `json:"cost" binding:"required"`
Currency string `json:"currency"`
Service string `json:"service"`
Region string `json:"region"`
Description string `json:"description"`
}
// CreateBillingAlertRequest 创建预警规则请求
type CreateBillingAlertRequest struct {
Name string `json:"name" binding:"required"`
Provider string `json:"provider"`
CloudAccountID *uint `json:"cloud_account_id"`
Metric string `json:"metric"`
Threshold float64 `json:"threshold" binding:"required"`
Operator string `json:"operator"`
Enabled bool `json:"enabled"`
}