update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
+60
-61
@@ -6,33 +6,33 @@ import (
|
||||
|
||||
// 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"`
|
||||
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
|
||||
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"`
|
||||
ReportTime time.Time `json:"report_time"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AgentReport) TableName() string {
|
||||
@@ -41,20 +41,20 @@ func (AgentReport) TableName() string {
|
||||
|
||||
// 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"`
|
||||
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"`
|
||||
@@ -74,23 +74,23 @@ type AgentLatestResponse struct {
|
||||
|
||||
// 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"`
|
||||
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"`
|
||||
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 健康探针结果
|
||||
}
|
||||
|
||||
@@ -198,14 +198,14 @@ type DiskIOStatModel struct {
|
||||
|
||||
// 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]
|
||||
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"
|
||||
return "monitor_agent_port_policies"
|
||||
}
|
||||
|
||||
// AgentPortPolicyDTO 前端交互用的端口策略格式(含已解析的数组)
|
||||
@@ -214,4 +214,3 @@ type AgentPortPolicyDTO struct {
|
||||
PortFilterMode string `json:"port_filter_mode"`
|
||||
PortWhitelist []int `json:"port_whitelist"`
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// agent_cli.go - Agent CLI 会话与消息持久化模型 // Logan.Li
|
||||
// 记录 AI 运维 Agent 的每次任务(关联主机 + 用户)及其 ReAct 推理过程
|
||||
// (思考/工具调用/输出/结果),供前端历史回放与审计。
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// AgentCLISession Agent CLI 任务会话 // Logan.Li
|
||||
type AgentCLISession struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
UserID uint `gorm:"index" json:"user_id"` // 发起用户
|
||||
Mode string `gorm:"size:16;default:host;index" json:"mode"` // host | kubernetes
|
||||
ServerID uint `gorm:"index" json:"server_id"` // 主机模式目标主机
|
||||
ServerName string `gorm:"size:128" json:"server_name"` // 主机名快照
|
||||
ServerHost string `gorm:"size:64" json:"server_host"` // 主机 IP 快照
|
||||
ClusterID uint `gorm:"index" json:"cluster_id"` // K8s 模式集群 ID
|
||||
ClusterName string `gorm:"size:128" json:"cluster_name"` // 集群名快照
|
||||
Namespace string `gorm:"size:128" json:"namespace"` // K8s 命名空间
|
||||
PodName string `gorm:"size:128" json:"pod_name"` // 可选目标 Pod
|
||||
Container string `gorm:"size:128" json:"container"` // 可选目标容器
|
||||
Title string `gorm:"size:255" json:"title"` // 任务标题(query 截断)
|
||||
Status string `gorm:"size:32;default:running" json:"status"` // running/done/aborted/error
|
||||
Provider string `gorm:"size:50" json:"provider"` // LLM 提供商
|
||||
Model string `gorm:"size:100" json:"model"` // 模型名
|
||||
Rounds int `json:"rounds"` // ReAct 轮次
|
||||
TotalTokens int `json:"total_tokens"` // token 消耗
|
||||
Duration int64 `json:"duration"` // 耗时(毫秒)
|
||||
Error string `gorm:"type:text" json:"error,omitempty"` // 错误信息
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名 // Logan.Li
|
||||
func (AgentCLISession) TableName() string { return "agent_cli_sessions" }
|
||||
|
||||
// AgentCLIMessage Agent CLI 任务消息(ReAct 推理过程的每一步) // Logan.Li
|
||||
type AgentCLIMessage struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
SessionID uint `gorm:"index;not null" json:"session_id"`
|
||||
Round int `json:"round"` // ReAct 轮次
|
||||
Type string `gorm:"size:32" json:"type"` // thought/tool_call/tool_result/done/error/session
|
||||
Role string `gorm:"size:32" json:"role"` // user/assistant/tool
|
||||
Content string `gorm:"type:text" json:"content"` // 思考文本/最终答案
|
||||
ToolName string `gorm:"size:64" json:"tool_name"` // 工具名
|
||||
ToolArgs string `gorm:"type:text" json:"tool_args"` // 工具参数 JSON
|
||||
ToolOutput string `gorm:"type:text" json:"tool_output"` // 工具输出
|
||||
Risk string `gorm:"size:32" json:"risk"` // 风险等级
|
||||
Success bool `json:"success"`
|
||||
Duration string `gorm:"size:32" json:"duration"` // 工具耗时
|
||||
Tokens int `json:"tokens"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 表名 // Logan.Li
|
||||
func (AgentCLIMessage) TableName() string { return "agent_cli_messages" }
|
||||
+37
-38
@@ -2,25 +2,24 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// AgentTask Agent 远程任务 // Logan.Li
|
||||
type AgentTask struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TaskID string `gorm:"size:36;uniqueIndex;not null" json:"task_id"` // UUID
|
||||
Hostname string `gorm:"size:255;index;not null" json:"hostname"` // 目标主机
|
||||
Type string `gorm:"size:32;not null" json:"type"` // command / script / file
|
||||
Command string `gorm:"type:text" json:"command"` // 命令或脚本内容
|
||||
Timeout int `gorm:"default:60" json:"timeout"` // 超时秒数
|
||||
Status string `gorm:"size:20;default:pending;index" json:"status"` // pending/running/success/failed/timeout
|
||||
Result string `gorm:"type:text" json:"result"` // 执行输出
|
||||
ExitCode int `gorm:"default:-1" json:"exit_code"` // 退出码
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"` // 创建人
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
PickedAt *time.Time `json:"picked_at"` // Agent 拉取时间
|
||||
FinishedAt *time.Time `json:"finished_at"` // 完成时间
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TaskID string `gorm:"size:36;uniqueIndex;not null" json:"task_id"` // UUID
|
||||
Hostname string `gorm:"size:255;index;not null" json:"hostname"` // 目标主机
|
||||
Type string `gorm:"size:32;not null" json:"type"` // command / script / file
|
||||
Command string `gorm:"type:text" json:"command"` // 命令或脚本内容
|
||||
Timeout int `gorm:"default:60" json:"timeout"` // 超时秒数
|
||||
Status string `gorm:"size:20;default:pending;index" json:"status"` // pending/running/success/failed/timeout
|
||||
Result string `gorm:"type:text" json:"result"` // 执行输出
|
||||
ExitCode int `gorm:"default:-1" json:"exit_code"` // 退出码
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"` // 创建人
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
PickedAt *time.Time `json:"picked_at"` // Agent 拉取时间
|
||||
FinishedAt *time.Time `json:"finished_at"` // 完成时间
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AgentTask) TableName() string {
|
||||
@@ -29,17 +28,17 @@ func (AgentTask) TableName() string {
|
||||
|
||||
// AgentRule 告警规则(基于 Agent 数据) // Logan.Li
|
||||
type AgentRule struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Hostname string `gorm:"size:255" json:"hostname"` // 空表示全部主机
|
||||
Metric string `gorm:"size:32;not null" json:"metric"` // cpu/mem/disk/offline/port_down/tcp_time_wait/tcp_close_wait/service_process/fd
|
||||
Operator string `gorm:"size:10;default:>" json:"operator"` // > >= < <= ==
|
||||
Threshold float64 `gorm:"type:decimal(10,2)" json:"threshold"`
|
||||
Port int `json:"port"` // port_down 专用
|
||||
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"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Hostname string `gorm:"size:255" json:"hostname"` // 空表示全部主机
|
||||
Metric string `gorm:"size:32;not null" json:"metric"` // cpu/mem/disk/offline/port_down/tcp_time_wait/tcp_close_wait/service_process/fd
|
||||
Operator string `gorm:"size:10;default:>" json:"operator"` // > >= < <= ==
|
||||
Threshold float64 `gorm:"type:decimal(10,2)" json:"threshold"`
|
||||
Port int `json:"port"` // port_down 专用
|
||||
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 (AgentRule) TableName() string {
|
||||
@@ -48,18 +47,18 @@ func (AgentRule) TableName() string {
|
||||
|
||||
// AgentAlert Agent 告警事件 // Logan.Li
|
||||
type AgentAlert struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RuleName string `gorm:"size:255" json:"rule_name"`
|
||||
Hostname string `gorm:"size:255;index" json:"hostname"`
|
||||
Metric string `gorm:"size:32" json:"metric"`
|
||||
Severity string `gorm:"size:20;default:warning" json:"severity"` // critical/warning/info
|
||||
Message string `gorm:"type:text" json:"message"`
|
||||
Value float64 `gorm:"type:decimal(10,2)" json:"value"`
|
||||
Threshold float64 `gorm:"type:decimal(10,2)" json:"threshold"`
|
||||
Resolved bool `gorm:"default:false;index" json:"resolved"`
|
||||
ResolvedAt *time.Time `json:"resolved_at"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RuleName string `gorm:"size:255" json:"rule_name"`
|
||||
Hostname string `gorm:"size:255;index" json:"hostname"`
|
||||
Metric string `gorm:"size:32" json:"metric"`
|
||||
Severity string `gorm:"size:20;default:warning" json:"severity"` // critical/warning/info
|
||||
Message string `gorm:"type:text" json:"message"`
|
||||
Value float64 `gorm:"type:decimal(10,2)" json:"value"`
|
||||
Threshold float64 `gorm:"type:decimal(10,2)" json:"threshold"`
|
||||
Resolved bool `gorm:"default:false;index" json:"resolved"`
|
||||
ResolvedAt *time.Time `json:"resolved_at"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AgentAlert) TableName() string {
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
// ai_runtime.go - AI 运行、工具能力和执行审计统一模型 // Logan.Li
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// AIRun 统一记录 Agent CLI、告警分析、智能助手、MCP/技能调用发起的 AI 任务。 // Logan.Li
|
||||
type AIRun struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RunID string `gorm:"size:64;uniqueIndex;not null" json:"run_id"` // 对外 trace/run 标识 // Logan.Li
|
||||
ParentRunID string `gorm:"size:64;index" json:"parent_run_id"` // 子任务关联 // Logan.Li
|
||||
UserID uint `gorm:"index" json:"user_id"` // 发起用户 // Logan.Li
|
||||
Feature string `gorm:"size:64;index;not null" json:"feature"` // agent_cli/alert_analysis/assistant/mcp // Logan.Li
|
||||
Mode string `gorm:"size:32;index" json:"mode"` // host/kubernetes/aiops/general // Logan.Li
|
||||
Title string `gorm:"size:255" json:"title"` // 任务标题 // Logan.Li
|
||||
Status string `gorm:"size:32;index;default:running" json:"status"` // running/done/error/aborted // Logan.Li
|
||||
SubjectType string `gorm:"size:64;index" json:"subject_type"` // host/k8s_cluster/namespace/pod/aiops_module/mcp_server/skill // Logan.Li
|
||||
SubjectID string `gorm:"size:128;index" json:"subject_id"` // 资源 ID 或稳定键 // Logan.Li
|
||||
SubjectName string `gorm:"size:255" json:"subject_name"` // 资源快照名称 // Logan.Li
|
||||
SubjectScope string `gorm:"size:255;index" json:"subject_scope"` // prod/ns/app 等范围键 // Logan.Li
|
||||
Provider string `gorm:"size:50" json:"provider"` // LLM 提供商 // Logan.Li
|
||||
Model string `gorm:"size:100" json:"model"` // 模型名 // Logan.Li
|
||||
SafetyMode string `gorm:"size:32" json:"safety_mode"` // strict/balanced/permissive // Logan.Li
|
||||
ContextPackID string `gorm:"size:64;index" json:"context_pack_id"` // 上下文包引用 // Logan.Li
|
||||
PromptTokens int `json:"prompt_tokens"` // 输入 token // Logan.Li
|
||||
CompletionTokens int `json:"completion_tokens"` // 输出 token // Logan.Li
|
||||
TotalTokens int `json:"total_tokens"` // 总 token // Logan.Li
|
||||
Rounds int `json:"rounds"` // Agent 轮次 // Logan.Li
|
||||
Duration int64 `json:"duration"` // 毫秒 // Logan.Li
|
||||
Error string `gorm:"type:text" json:"error,omitempty"` // 错误摘要 // Logan.Li
|
||||
StartedAt time.Time `gorm:"index" json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AIRun) TableName() string { return "ai_runs" }
|
||||
|
||||
// AIRunMessage 统一 AI 对话消息,负责回放,不承载工具审计明细。 // Logan.Li
|
||||
type AIRunMessage struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RunID string `gorm:"size:64;index;not null" json:"run_id"`
|
||||
Round int `gorm:"index" json:"round"`
|
||||
Seq int `gorm:"index" json:"seq"`
|
||||
Role string `gorm:"size:32;index" json:"role"` // system/user/assistant/tool // Logan.Li
|
||||
Type string `gorm:"size:32;index" json:"type"` // message/thought/tool_call/tool_result/done/error/status // Logan.Li
|
||||
Content string `gorm:"type:text" json:"content"` // 脱敏内容 // Logan.Li
|
||||
ToolName string `gorm:"size:128;index" json:"tool_name"` // 可选工具名 // Logan.Li
|
||||
ToolCallID string `gorm:"size:128;index" json:"tool_call_id"` // LLM 工具调用 ID // Logan.Li
|
||||
SpanID string `gorm:"size:64;index" json:"span_id"` // 关联 span // Logan.Li
|
||||
Tokens int `json:"tokens"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
}
|
||||
|
||||
func (AIRunMessage) TableName() string { return "ai_run_messages" }
|
||||
|
||||
// AIRunSpan 统一 AI trace span,记录 LLM、工具、guardrail、确认、审批等事件。 // Logan.Li
|
||||
type AIRunSpan struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RunID string `gorm:"size:64;index;not null" json:"run_id"`
|
||||
SpanID string `gorm:"size:64;uniqueIndex;not null" json:"span_id"`
|
||||
ParentSpanID string `gorm:"size:64;index" json:"parent_span_id"`
|
||||
Kind string `gorm:"size:32;index;not null" json:"kind"` // llm/tool/guardrail/confirm/approval/context // Logan.Li
|
||||
Name string `gorm:"size:128;index" json:"name"` // 工具名或步骤名 // Logan.Li
|
||||
CapabilityID uint `gorm:"index" json:"capability_id"` // 能力注册表 ID // Logan.Li
|
||||
ToolSource string `gorm:"size:32;index" json:"tool_source"` // builtin/mcp/skill/shell/kubernetes/aiops // Logan.Li
|
||||
Input string `gorm:"type:text" json:"input"` // 脱敏输入 // Logan.Li
|
||||
Output string `gorm:"type:text" json:"output"` // 脱敏输出摘要 // Logan.Li
|
||||
OutputSize int `json:"output_size"` // 脱敏后输出长度 // Logan.Li
|
||||
Risk string `gorm:"size:32;index" json:"risk"` // safe/low/medium/high/critical // Logan.Li
|
||||
Decision string `gorm:"size:32;index" json:"decision"` // auto/approved/rejected/denied/escalated // Logan.Li
|
||||
Status string `gorm:"size:32;index" json:"status"` // running/success/error/skipped // Logan.Li
|
||||
Error string `gorm:"type:text" json:"error"` // 错误摘要 // Logan.Li
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
Duration int64 `json:"duration"` // 毫秒 // Logan.Li
|
||||
StartedAt time.Time `gorm:"index" json:"started_at"`
|
||||
EndedAt *time.Time `json:"ended_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (AIRunSpan) TableName() string { return "ai_run_spans" }
|
||||
|
||||
// AICapability 注册 AIOps 内置工具、MCP 工具、Skill、Shell/K8s 工具的统一能力目录。 // Logan.Li
|
||||
type AICapability struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;uniqueIndex;not null" json:"name"` // 稳定工具名 // Logan.Li
|
||||
DisplayName string `gorm:"size:128" json:"display_name"`
|
||||
Source string `gorm:"size:32;index;not null" json:"source"` // builtin/mcp/skill/shell/kubernetes/aiops // Logan.Li
|
||||
Category string `gorm:"size:64;index" json:"category"` // asset/k8s/monitor/alert/change/security // Logan.Li
|
||||
RiskLevel string `gorm:"size:32;index;default:safe" json:"risk_level"`
|
||||
Schema string `gorm:"type:text" json:"schema"` // JSON Schema // Logan.Li
|
||||
Config string `gorm:"type:text" json:"config"` // MCP server/skill 配置快照 // Logan.Li
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Enabled bool `gorm:"default:true;index" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AICapability) TableName() string { return "ai_capabilities" }
|
||||
|
||||
// AICapabilityPolicy 描述工具能力在用户、角色、资源范围上的准入和审批策略。 // Logan.Li
|
||||
type AICapabilityPolicy struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
CapabilityID uint `gorm:"index" json:"capability_id"`
|
||||
SubjectType string `gorm:"size:32;index" json:"subject_type"` // user/role/all // Logan.Li
|
||||
SubjectID string `gorm:"size:64;index" json:"subject_id"`
|
||||
ResourceType string `gorm:"size:64;index" json:"resource_type"` // host/k8s_cluster/namespace/pod/aiops_module/mcp_server/skill // Logan.Li
|
||||
ResourcePattern string `gorm:"size:255" json:"resource_pattern"` // 正则或通配符 // Logan.Li
|
||||
Effect string `gorm:"size:16;index;default:allow" json:"effect"` // allow/deny // Logan.Li
|
||||
RequireConfirm bool `gorm:"default:false" json:"require_confirm"`
|
||||
RequireApproval bool `gorm:"default:false" json:"require_approval"`
|
||||
MaxRisk string `gorm:"size:32;default:high" json:"max_risk"`
|
||||
Enabled bool `gorm:"default:true;index" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AICapabilityPolicy) TableName() string { return "ai_capability_policies" }
|
||||
|
||||
// OpsSession 统一人机执行会话,覆盖 SSH/RDP/Pod/kubectl/Agent CLI。 // Logan.Li
|
||||
type OpsSession struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
SessionID string `gorm:"size:64;uniqueIndex;not null" json:"session_id"`
|
||||
RunID string `gorm:"size:64;index" json:"run_id"` // AI 发起时关联 ai_runs // Logan.Li
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
SessionType string `gorm:"size:32;index;not null" json:"session_type"` // ssh/rdp/pod_exec/kubectl/agent_cli // Logan.Li
|
||||
ActorType string `gorm:"size:32;index;default:user" json:"actor_type"` // user/ai/system // Logan.Li
|
||||
TargetType string `gorm:"size:64;index" json:"target_type"` // host/k8s_cluster/pod // Logan.Li
|
||||
TargetID string `gorm:"size:128;index" json:"target_id"`
|
||||
TargetName string `gorm:"size:255" json:"target_name"`
|
||||
ClientIP string `gorm:"size:64" json:"client_ip"`
|
||||
Status string `gorm:"size:32;index" json:"status"` // active/closed/failed // Logan.Li
|
||||
RecordRef string `gorm:"size:255" json:"record_ref"` // 录制对象存储或分片引用 // Logan.Li
|
||||
RecordSize int `json:"record_size"`
|
||||
Duration int64 `json:"duration"` // 秒 // Logan.Li
|
||||
Error string `gorm:"type:text" json:"error,omitempty"`
|
||||
StartedAt time.Time `gorm:"index" json:"started_at"`
|
||||
EndedAt *time.Time `json:"ended_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (OpsSession) TableName() string { return "ai_ops_sessions" }
|
||||
|
||||
// OpsCommand 统一命令/动作审计,覆盖人执行和 AI 工具执行。 // Logan.Li
|
||||
type OpsCommand struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CommandID string `gorm:"size:64;uniqueIndex;not null" json:"command_id"`
|
||||
SessionID string `gorm:"size:64;index" json:"session_id"`
|
||||
RunID string `gorm:"size:64;index" json:"run_id"`
|
||||
SpanID string `gorm:"size:64;index" json:"span_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
ActorType string `gorm:"size:32;index;default:user" json:"actor_type"` // user/ai/system // Logan.Li
|
||||
TargetType string `gorm:"size:64;index" json:"target_type"`
|
||||
TargetID string `gorm:"size:128;index" json:"target_id"`
|
||||
CommandType string `gorm:"size:32;index" json:"command_type"` // shell/k8s_action/mcp/skill/api // Logan.Li
|
||||
Command string `gorm:"type:text" json:"command"` // 脱敏命令或动作参数 // Logan.Li
|
||||
Risk string `gorm:"size:32;index" json:"risk"`
|
||||
Decision string `gorm:"size:32;index" json:"decision"`
|
||||
Status string `gorm:"size:32;index" json:"status"`
|
||||
ExitCode int `gorm:"default:-1" json:"exit_code"`
|
||||
OutputRef string `gorm:"size:255" json:"output_ref"` // 大输出引用 // Logan.Li
|
||||
OutputSize int `json:"output_size"`
|
||||
Duration int64 `json:"duration"` // 毫秒 // Logan.Li
|
||||
Error string `gorm:"type:text" json:"error"`
|
||||
ExecutedAt time.Time `gorm:"index" json:"executed_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (OpsCommand) TableName() string { return "ai_ops_commands" }
|
||||
+112
-111
@@ -56,41 +56,41 @@ const (
|
||||
|
||||
// AlertRule 告警规则(增强版)
|
||||
type AlertRule struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:规则名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(500);comment:规则描述" json:"description,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:规则名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(500);comment:规则描述" json:"description,omitempty"`
|
||||
// ====== 原 V1 兼容字段 ======
|
||||
Type string `gorm:"type:varchar(32);comment:规则类型: metric/log/event" json:"type,omitempty"`
|
||||
Source string `gorm:"type:varchar(64);comment:数据源: prometheus/zabbix/custom/loki/elasticsearch" json:"source,omitempty"`
|
||||
Expression string `gorm:"type:text;comment:PromQL/Zabbix/LogQL/Lucene表达式" json:"expression,omitempty"`
|
||||
DatasourceID uint `gorm:"index;comment:日志/指标数据源ID" json:"datasource_id,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);default:'warning';comment:告警级别" json:"severity"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
Type string `gorm:"type:varchar(32);comment:规则类型: metric/log/event" json:"type,omitempty"`
|
||||
Source string `gorm:"type:varchar(64);comment:数据源: prometheus/zabbix/custom/loki/elasticsearch" json:"source,omitempty"`
|
||||
Expression string `gorm:"type:text;comment:PromQL/Zabbix/LogQL/Lucene表达式" json:"expression,omitempty"`
|
||||
DatasourceID uint `gorm:"index;comment:日志/指标数据源ID" json:"datasource_id,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);default:'warning';comment:告警级别" json:"severity"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
// ====== V2 增强字段 ======
|
||||
Status AlertRuleStatus `gorm:"type:varchar(16);default:'enabled';comment:规则状态" json:"status,omitempty"`
|
||||
TargetType string `gorm:"type:varchar(32);comment:目标类型" json:"target_type,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID(0表示全部)" json:"target_id,omitempty"`
|
||||
TargetTags string `gorm:"type:varchar(256);comment:目标标签筛选" json:"target_tags,omitempty"`
|
||||
Conditions string `gorm:"type:text;comment:触发条件JSON数组" json:"conditions,omitempty"`
|
||||
AggWindow int `gorm:"default:300;comment:聚合窗口(秒)" json:"agg_window,omitempty"`
|
||||
AggFunction string `gorm:"type:varchar(16);default:'avg';comment:聚合函数" json:"agg_function,omitempty"`
|
||||
RecoverCount int `gorm:"default:1;comment:恢复次数" json:"recover_count,omitempty"`
|
||||
RecoverWindow int `gorm:"default:300;comment:恢复检查窗口(秒)" json:"recover_window,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:评估间隔(秒)" json:"interval,omitempty"`
|
||||
CheckTimes int `gorm:"default:1;comment:连续触发次数" json:"check_times,omitempty"`
|
||||
NotifyMode string `gorm:"type:varchar(16);default:'every';comment:通知模式: every/once/upgrade" json:"notify_mode,omitempty"`
|
||||
ChannelIDs string `gorm:"type:varchar(256);comment:通知渠道ID列表JSON" json:"channel_ids,omitempty"`
|
||||
NotifyChannels string `gorm:"type:text;comment:通知渠道JSON(兼容V1)" json:"notify_channels,omitempty"`
|
||||
TemplateID uint `gorm:"comment:通知模板ID" json:"template_id,omitempty"`
|
||||
UpgradeID uint `gorm:"comment:升级策略ID" json:"upgrade_id,omitempty"`
|
||||
SilenceID uint `gorm:"comment:静默规则ID" json:"silence_id,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
Status AlertRuleStatus `gorm:"type:varchar(16);default:'enabled';comment:规则状态" json:"status,omitempty"`
|
||||
TargetType string `gorm:"type:varchar(32);comment:目标类型" json:"target_type,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID(0表示全部)" json:"target_id,omitempty"`
|
||||
TargetTags string `gorm:"type:varchar(256);comment:目标标签筛选" json:"target_tags,omitempty"`
|
||||
Conditions string `gorm:"type:text;comment:触发条件JSON数组" json:"conditions,omitempty"`
|
||||
AggWindow int `gorm:"default:300;comment:聚合窗口(秒)" json:"agg_window,omitempty"`
|
||||
AggFunction string `gorm:"type:varchar(16);default:'avg';comment:聚合函数" json:"agg_function,omitempty"`
|
||||
RecoverCount int `gorm:"default:1;comment:恢复次数" json:"recover_count,omitempty"`
|
||||
RecoverWindow int `gorm:"default:300;comment:恢复检查窗口(秒)" json:"recover_window,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:评估间隔(秒)" json:"interval,omitempty"`
|
||||
CheckTimes int `gorm:"default:1;comment:连续触发次数" json:"check_times,omitempty"`
|
||||
NotifyMode string `gorm:"type:varchar(16);default:'every';comment:通知模式: every/once/upgrade" json:"notify_mode,omitempty"`
|
||||
ChannelIDs string `gorm:"type:varchar(256);comment:通知渠道ID列表JSON" json:"channel_ids,omitempty"`
|
||||
NotifyChannels string `gorm:"type:text;comment:通知渠道JSON(兼容V1)" json:"notify_channels,omitempty"`
|
||||
TemplateID uint `gorm:"comment:通知模板ID" json:"template_id,omitempty"`
|
||||
UpgradeID uint `gorm:"comment:升级策略ID" json:"upgrade_id,omitempty"`
|
||||
SilenceID uint `gorm:"comment:静默规则ID" json:"silence_id,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertRule) TableName() string {
|
||||
@@ -112,40 +112,40 @@ const (
|
||||
|
||||
// AlertEvent 告警事件(增强版)
|
||||
type AlertEvent struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
RuleID uint `gorm:"not null;index:idx_rule_time;comment:规则ID" json:"rule_id"`
|
||||
RuleName string `gorm:"type:varchar(128);comment:规则名称" json:"rule_name,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);comment:告警级别" json:"severity,omitempty"`
|
||||
Status string `gorm:"type:varchar(32);default:'firing';comment:事件状态" json:"status"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
RuleID uint `gorm:"not null;index:idx_rule_time;comment:规则ID" json:"rule_id"`
|
||||
RuleName string `gorm:"type:varchar(128);comment:规则名称" json:"rule_name,omitempty"`
|
||||
Severity string `gorm:"type:varchar(32);comment:告警级别" json:"severity,omitempty"`
|
||||
Status string `gorm:"type:varchar(32);default:'firing';comment:事件状态" json:"status"`
|
||||
// ====== 原V1兼容字段 ======
|
||||
Target string `gorm:"type:varchar(255);comment:目标标签" json:"target,omitempty"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
Value float64 `gorm:"comment:触发值" json:"value,omitempty"`
|
||||
Target string `gorm:"type:varchar(255);comment:目标标签" json:"target,omitempty"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
Value float64 `gorm:"comment:触发值" json:"value,omitempty"`
|
||||
// ====== V2增强字段 ======
|
||||
TargetID uint `gorm:"index;comment:目标ID" json:"target_id,omitempty"`
|
||||
TargetName string `gorm:"type:varchar(128);comment:目标名称" json:"target_name,omitempty"`
|
||||
TargetIP string `gorm:"type:varchar(64);comment:目标IP" json:"target_ip,omitempty"`
|
||||
Title string `gorm:"type:varchar(256);comment:告警标题" json:"title,omitempty"`
|
||||
MetricName string `gorm:"type:varchar(64);comment:指标名称" json:"metric_name,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
Operator string `gorm:"type:varchar(8);comment:运算符" json:"operator,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
StartedAt time.Time `gorm:"not null;index:idx_rule_time;comment:触发时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
LastEvalAt time.Time `gorm:"comment:最后评估时间" json:"last_eval_at,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count,omitempty"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
UpgradeLevel int `gorm:"default:0;comment:当前升级级别" json:"upgrade_level,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy *uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
AckComment string `gorm:"type:varchar(256);comment:确认备注" json:"ack_comment,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
TargetID uint `gorm:"index;comment:目标ID" json:"target_id,omitempty"`
|
||||
TargetName string `gorm:"type:varchar(128);comment:目标名称" json:"target_name,omitempty"`
|
||||
TargetIP string `gorm:"type:varchar(64);comment:目标IP" json:"target_ip,omitempty"`
|
||||
Title string `gorm:"type:varchar(256);comment:告警标题" json:"title,omitempty"`
|
||||
MetricName string `gorm:"type:varchar(64);comment:指标名称" json:"metric_name,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
Operator string `gorm:"type:varchar(8);comment:运算符" json:"operator,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
Labels string `gorm:"type:text;comment:标签JSON" json:"labels,omitempty"`
|
||||
Annotations string `gorm:"type:text;comment:注释JSON" json:"annotations,omitempty"`
|
||||
StartedAt time.Time `gorm:"not null;index:idx_rule_time;comment:触发时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
LastEvalAt time.Time `gorm:"comment:最后评估时间" json:"last_eval_at,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count,omitempty"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
UpgradeLevel int `gorm:"default:0;comment:当前升级级别" json:"upgrade_level,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy *uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
AckComment string `gorm:"type:varchar(256);comment:确认备注" json:"ack_comment,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联
|
||||
Rule *AlertRule `json:"rule,omitempty" gorm:"foreignKey:RuleID"`
|
||||
@@ -160,14 +160,14 @@ func (AlertEvent) TableName() string {
|
||||
// ============================================
|
||||
|
||||
type AlertCondition struct {
|
||||
Metric string `json:"metric"`
|
||||
Operator Operator `json:"operator"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index string `json:"index,omitempty"`
|
||||
LogicOp string `json:"logic_op,omitempty"`
|
||||
AggFunc AggFunction `json:"agg_func,omitempty"`
|
||||
Window int `json:"window,omitempty"`
|
||||
Metric string `json:"metric"`
|
||||
Operator Operator `json:"operator"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
Index string `json:"index,omitempty"`
|
||||
LogicOp string `json:"logic_op,omitempty"`
|
||||
AggFunc AggFunction `json:"agg_func,omitempty"`
|
||||
Window int `json:"window,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertCondition) TableName() string {
|
||||
@@ -184,21 +184,21 @@ type AlertConditionGroup struct {
|
||||
// ============================================
|
||||
|
||||
type AlertNotifyTemplate struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
ChannelType string `gorm:"type:varchar(32);not null;comment:适用渠道类型: email/sms/webhook/dingtalk/wecom/feishu" json:"channel_type"`
|
||||
TitleTemplate string `gorm:"type:varchar(256);comment:标题模板" json:"title_template,omitempty"`
|
||||
BodyTemplate string `gorm:"type:text;comment:正文模板" json:"body_template,omitempty"`
|
||||
Variables string `gorm:"type:text;comment:可用变量说明JSON" json:"variables,omitempty"`
|
||||
RecoverTitleTemplate string `gorm:"type:varchar(256);comment:恢复标题模板" json:"recover_title_template,omitempty"`
|
||||
RecoverBodyTemplate string `gorm:"type:text;comment:恢复正文模板" json:"recover_body_template,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
ChannelType string `gorm:"type:varchar(32);not null;comment:适用渠道类型: email/sms/webhook/dingtalk/wecom/feishu" json:"channel_type"`
|
||||
TitleTemplate string `gorm:"type:varchar(256);comment:标题模板" json:"title_template,omitempty"`
|
||||
BodyTemplate string `gorm:"type:text;comment:正文模板" json:"body_template,omitempty"`
|
||||
Variables string `gorm:"type:text;comment:可用变量说明JSON" json:"variables,omitempty"`
|
||||
RecoverTitleTemplate string `gorm:"type:varchar(256);comment:恢复标题模板" json:"recover_title_template,omitempty"`
|
||||
RecoverBodyTemplate string `gorm:"type:text;comment:恢复正文模板" json:"recover_body_template,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (AlertNotifyTemplate) TableName() string {
|
||||
@@ -249,12 +249,12 @@ func (AlertUpgrade) TableName() string {
|
||||
}
|
||||
|
||||
type AlertUpgradeRule struct {
|
||||
Level int `json:"level"`
|
||||
Duration int `json:"duration"`
|
||||
Severity string `json:"severity"`
|
||||
Level int `json:"level"`
|
||||
Duration int `json:"duration"`
|
||||
Severity string `json:"severity"`
|
||||
ChannelIDs []string `json:"channel_ids"`
|
||||
NotifyUsers []uint `json:"notify_users"`
|
||||
RepeatInterval int `json:"repeat_interval"`
|
||||
NotifyUsers []uint `json:"notify_users"`
|
||||
RepeatInterval int `json:"repeat_interval"`
|
||||
}
|
||||
|
||||
type AlertUpgradeRecord struct {
|
||||
@@ -321,19 +321,19 @@ type AlertSilenceCheckResult struct {
|
||||
|
||||
// NotifyChannel 通知渠道模型
|
||||
type NotifyChannel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
|
||||
Config string `gorm:"type:text" json:"config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
TestStatus string `gorm:"size:32" json:"test_status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
|
||||
Config string `gorm:"type:text" json:"config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
TestStatus string `gorm:"size:32" json:"test_status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (NotifyChannel) TableName() string {
|
||||
return "monitor_notify_channels"
|
||||
return "monitor_alert_channels"
|
||||
}
|
||||
|
||||
// MetricData 监控指标数据
|
||||
@@ -383,14 +383,14 @@ type UpdateAlertRuleRequest struct {
|
||||
|
||||
// AlertStats 告警统计
|
||||
type AlertStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Firing int64 `json:"firing"`
|
||||
Resolved int64 `json:"resolved"`
|
||||
Critical int64 `json:"critical"`
|
||||
Warning int64 `json:"warning"`
|
||||
Info int64 `json:"info"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
Total int64 `json:"total"`
|
||||
Firing int64 `json:"firing"`
|
||||
Resolved int64 `json:"resolved"`
|
||||
Critical int64 `json:"critical"`
|
||||
Warning int64 `json:"warning"`
|
||||
Info int64 `json:"info"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
}
|
||||
|
||||
// AcknowledgeAlertRequest 确认告警请求
|
||||
@@ -491,7 +491,7 @@ type FeishuWebhookConfig struct {
|
||||
|
||||
// FeishuCardMessage 飞书卡片消息
|
||||
type FeishuCardMessage struct {
|
||||
MsgType string `json:"msg_type"`
|
||||
MsgType string `json:"msg_type"`
|
||||
Content FeishuCardContent `json:"content"`
|
||||
}
|
||||
|
||||
@@ -499,6 +499,7 @@ type FeishuCardContent struct {
|
||||
Title string `json:"title"`
|
||||
Content [][]FeishuCardElement `json:"content"`
|
||||
}
|
||||
|
||||
// FeishuCardElement 飞书卡片元素
|
||||
type FeishuCardElement struct {
|
||||
Tag string `json:"tag"`
|
||||
|
||||
@@ -31,4 +31,4 @@ type AlertNotifyPolicy struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AlertNotifyPolicy) TableName() string { return "monitor_alert_notify_policies" }
|
||||
func (AlertNotifyPolicy) TableName() string { return "monitor_alert_notify_policies" }
|
||||
@@ -12,4 +12,4 @@ type AlertNotifySettings struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AlertNotifySettings) TableName() string { return "monitor_alert_notify_settings" }
|
||||
func (AlertNotifySettings) TableName() string { return "monitor_alert_notify_settings" }
|
||||
+40
-41
@@ -2,44 +2,43 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// ApprovalTemplate 审批模板模型
|
||||
type ApprovalTemplate 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;not null" json:"type"` // release, server_apply, app_deploy, permission_request
|
||||
FormSchema string `gorm:"type:text" json:"form_schema"` // JSON form fields config
|
||||
FlowConfig string `gorm:"type:text" json:"flow_config"` // JSON approval flow steps
|
||||
Category string `gorm:"size:32;default:resource" json:"category"` // resource, app, permission
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
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;not null" json:"type"` // release, server_apply, app_deploy, permission_request
|
||||
FormSchema string `gorm:"type:text" json:"form_schema"` // JSON form fields config
|
||||
FlowConfig string `gorm:"type:text" json:"flow_config"` // JSON approval flow steps
|
||||
Category string `gorm:"size:32;default:resource" json:"category"` // resource, app, permission
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (ApprovalTemplate) TableName() string {
|
||||
return "sys_approval_templates"
|
||||
return "approval_templates"
|
||||
}
|
||||
|
||||
// ApprovalProcess 审批流程模型
|
||||
type ApprovalProcess struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TemplateID uint `json:"template_id"`
|
||||
Title string `gorm:"size:255;not null" json:"title"`
|
||||
Applicant uint `json:"applicant"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
FormData string `gorm:"type:text" json:"form_data"` // JSON
|
||||
CurrentStep int `gorm:"default:0" json:"current_step"`
|
||||
TotalSteps int `json:"total_steps"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
RejectedAt *time.Time `json:"rejected_at"`
|
||||
RejectReason string `gorm:"size:500" json:"reject_reason"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TemplateID uint `json:"template_id"`
|
||||
Title string `gorm:"size:255;not null" json:"title"`
|
||||
Applicant uint `json:"applicant"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
FormData string `gorm:"type:text" json:"form_data"` // JSON
|
||||
CurrentStep int `gorm:"default:0" json:"current_step"`
|
||||
TotalSteps int `json:"total_steps"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
RejectedAt *time.Time `json:"rejected_at"`
|
||||
RejectReason string `gorm:"size:500" json:"reject_reason"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Template *ApprovalTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
|
||||
@@ -54,16 +53,16 @@ func (ApprovalProcess) TableName() string {
|
||||
|
||||
// ApprovalStep 审批步骤模型
|
||||
type ApprovalStep struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ProcessID uint `json:"process_id"`
|
||||
Step int `json:"step"`
|
||||
StepType string `gorm:"size:32;default:audit" json:"step_type"` // audit, execute
|
||||
Approver uint `json:"approver"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
Comment string `gorm:"size:500" json:"comment"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ProcessID uint `json:"process_id"`
|
||||
Step int `json:"step"`
|
||||
StepType string `gorm:"size:32;default:audit" json:"step_type"` // audit, execute
|
||||
Approver uint `json:"approver"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
Comment string `gorm:"size:500" json:"comment"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
ApproverUser *User `gorm:"foreignKey:Approver" json:"approver_user,omitempty"`
|
||||
@@ -94,15 +93,15 @@ type CreateApprovalProcessRequest struct {
|
||||
|
||||
// ApproveRequest 审批请求
|
||||
type ApproveRequest struct {
|
||||
Status string `json:"status"`
|
||||
Status string `json:"status"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
// ApprovalStats 审批统计
|
||||
type ApprovalStats struct {
|
||||
Pending int64 `json:"pending"`
|
||||
Approved int64 `json:"approved"`
|
||||
Rejected int64 `json:"rejected"`
|
||||
Total int64 `json:"total"`
|
||||
Pending int64 `json:"pending"`
|
||||
Approved int64 `json:"approved"`
|
||||
Rejected int64 `json:"rejected"`
|
||||
Total int64 `json:"total"`
|
||||
MyPending int64 `json:"my_pending"`
|
||||
}
|
||||
@@ -17,52 +17,52 @@ type ApprovalWorkflow struct {
|
||||
}
|
||||
|
||||
func (ApprovalWorkflow) TableName() string {
|
||||
return "sys_approval_workflows"
|
||||
return "approval_workflows"
|
||||
}
|
||||
|
||||
// ApprovalWorkflowStep 审批流程步骤
|
||||
type ApprovalWorkflowStep struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
WorkflowID uint `json:"workflow_id"`
|
||||
StepNumber int `gorm:"not null" json:"step_number"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
StepType string `gorm:"size:32;not null" json:"step_type"` // submit, audit, execute
|
||||
ApproverIDs string `gorm:"type:text" json:"approver_ids"` // JSON array of user IDs
|
||||
IsRequired bool `gorm:"default:true" json:"is_required"`
|
||||
TimeoutHours int `gorm:"default:24" json:"timeout_hours"`
|
||||
AutoApprove bool `gorm:"default:false" json:"auto_approve_on_timeout"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
WorkflowID uint `json:"workflow_id"`
|
||||
StepNumber int `gorm:"not null" json:"step_number"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
StepType string `gorm:"size:32;not null" json:"step_type"` // submit, audit, execute
|
||||
ApproverIDs string `gorm:"type:text" json:"approver_ids"` // JSON array of user IDs
|
||||
IsRequired bool `gorm:"default:true" json:"is_required"`
|
||||
TimeoutHours int `gorm:"default:24" json:"timeout_hours"`
|
||||
AutoApprove bool `gorm:"default:false" json:"auto_approve_on_timeout"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (ApprovalWorkflowStep) TableName() string {
|
||||
return "sys_approval_workflow_steps"
|
||||
return "approval_workflow_steps"
|
||||
}
|
||||
|
||||
// CreateWorkflowRequest 创建审批流程请求
|
||||
type CreateWorkflowRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Steps []CreateWorkflowStepReq `json:"steps"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Steps []CreateWorkflowStepReq `json:"steps"`
|
||||
}
|
||||
|
||||
type CreateWorkflowStepReq struct {
|
||||
StepNumber int `json:"step_number"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
StepType string `json:"step_type" binding:"required,oneof=submit audit execute"`
|
||||
ApproverIDs string `json:"approver_ids"`
|
||||
IsRequired bool `json:"is_required"`
|
||||
TimeoutHours int `json:"timeout_hours"`
|
||||
AutoApproveTimeout bool `json:"auto_approve_on_timeout"`
|
||||
StepNumber int `json:"step_number"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
StepType string `json:"step_type" binding:"required,oneof=submit audit execute"`
|
||||
ApproverIDs string `json:"approver_ids"`
|
||||
IsRequired bool `json:"is_required"`
|
||||
TimeoutHours int `json:"timeout_hours"`
|
||||
AutoApproveTimeout bool `json:"auto_approve_on_timeout"`
|
||||
}
|
||||
|
||||
// UpdateWorkflowRequest 更新审批流程请求
|
||||
type UpdateWorkflowRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
IsActive *bool `json:"is_active,omitempty"`
|
||||
IsDefault *bool `json:"is_default,omitempty"`
|
||||
Steps []CreateWorkflowStepReq `json:"steps,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
IsActive *bool `json:"is_active,omitempty"`
|
||||
IsDefault *bool `json:"is_default,omitempty"`
|
||||
Steps []CreateWorkflowStepReq `json:"steps,omitempty"`
|
||||
}
|
||||
@@ -25,7 +25,7 @@ type AuditLog struct {
|
||||
|
||||
// TableName 表名
|
||||
func (AuditLog) TableName() string {
|
||||
return "sys_audit_logs"
|
||||
return "audit_operation_logs"
|
||||
}
|
||||
|
||||
// AuditLogQuery 审计日志查询
|
||||
@@ -48,11 +48,11 @@ type AuditLogListResponse struct {
|
||||
|
||||
// AuditStats 审计统计
|
||||
type AuditStats struct {
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
MonthCount int64 `json:"month_count"`
|
||||
TopModules []ModuleStat `json:"top_modules"`
|
||||
TopUsers []UserStat `json:"top_users"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
MonthCount int64 `json:"month_count"`
|
||||
TopModules []ModuleStat `json:"top_modules"`
|
||||
TopUsers []UserStat `json:"top_users"`
|
||||
}
|
||||
|
||||
// ModuleStat 模块统计
|
||||
|
||||
@@ -20,7 +20,7 @@ type AuditSettings struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AuditSettings) TableName() string { return "sys_audit_settings" }
|
||||
func (AuditSettings) TableName() string { return "audit_settings" }
|
||||
|
||||
// AllowedAuditRetentionDays 允许的日志保留天数 // Logan.Li
|
||||
var AllowedAuditRetentionDays = []int{7, 15, 30, 90, 180, 365}
|
||||
|
||||
+63
-64
@@ -2,30 +2,29 @@ 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"`
|
||||
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"`
|
||||
@@ -38,20 +37,20 @@ func (CronJob) TableName() string {
|
||||
|
||||
// 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"`
|
||||
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 表名
|
||||
@@ -61,21 +60,21 @@ func (Script) TableName() string {
|
||||
|
||||
// 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"`
|
||||
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 表名
|
||||
@@ -85,16 +84,16 @@ func (TaskExecution) TableName() string {
|
||||
|
||||
// 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 powershell command bash"`
|
||||
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"`
|
||||
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 powershell command bash"`
|
||||
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 创建脚本请求
|
||||
@@ -117,9 +116,9 @@ type ExecuteScriptRequest struct {
|
||||
|
||||
// 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"`
|
||||
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"`
|
||||
}
|
||||
+43
-44
@@ -2,64 +2,63 @@ 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"`
|
||||
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"
|
||||
return "asset_cloud_billing_records"
|
||||
}
|
||||
|
||||
// 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"`
|
||||
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"
|
||||
return "asset_cloud_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"`
|
||||
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"`
|
||||
Date string `json:"date"`
|
||||
Cost float64 `json:"cost"`
|
||||
}
|
||||
|
||||
// ProviderCost 厂商成本分布
|
||||
@@ -82,15 +81,15 @@ type BillingAlert struct {
|
||||
|
||||
// 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"`
|
||||
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"`
|
||||
Currency string `json:"currency"`
|
||||
Service string `json:"service"`
|
||||
Region string `json:"region"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CreateBillingAlertRequest 创建预警规则请求
|
||||
|
||||
@@ -32,7 +32,7 @@ type BuildMasterConfig struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (BuildMasterConfig) TableName() string { return "deploy_build_master_config" }
|
||||
func (BuildMasterConfig) TableName() string { return "deploy_build_master_configs" }
|
||||
|
||||
// UpdateBuildMasterRequest 更新 Master 并发数 // Logan.Li
|
||||
type UpdateBuildMasterRequest struct {
|
||||
@@ -58,4 +58,4 @@ type UpdateBuildNodeRequest struct {
|
||||
MaxExecutors int `json:"max_executors"`
|
||||
WorkspacePath string `json:"workspace_path"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
}
|
||||
+88
-99
@@ -2,23 +2,22 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// Pipeline CI/CD流水线模型
|
||||
type Pipeline 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"`
|
||||
JobName string `gorm:"size:128;uniqueIndex;comment:Job名称(webhook URL标识, 如 cex-admin-server)" json:"job_name,omitempty"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;default:deploy" json:"type"` // build, deploy, test
|
||||
Source string `gorm:"size:255" json:"source"` // Git仓库地址
|
||||
Branch string `gorm:"size:64;default:main" json:"branch"`
|
||||
Dockerfile string `gorm:"size:255" json:"dockerfile"`
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Variables string `gorm:"type:text" json:"variables"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
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"`
|
||||
JobName string `gorm:"size:128;uniqueIndex;comment:Job名称(webhook URL标识, 如 cex-admin-server)" json:"job_name,omitempty"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;default:deploy" json:"type"` // build, deploy, test
|
||||
Source string `gorm:"size:255" json:"source"` // Git仓库地址
|
||||
Branch string `gorm:"size:64;default:main" json:"branch"`
|
||||
Dockerfile string `gorm:"size:255" json:"dockerfile"`
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Variables string `gorm:"type:text" json:"variables"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
|
||||
// 部署模式
|
||||
DeployMode string `gorm:"size:16;default:branch;comment:部署模式 branch/tag" json:"deploy_mode"`
|
||||
@@ -36,16 +35,12 @@ type Pipeline struct {
|
||||
DeployScript string `gorm:"type:text;comment:SSH部署后执行命令" json:"deploy_script,omitempty"`
|
||||
|
||||
// K8s 部署目标
|
||||
K8sClusterID *uint `json:"k8s_cluster_id,omitempty"` // FK → kubernetes_clusters
|
||||
K8sClusterID *uint `json:"k8s_cluster_id,omitempty"` // FK → k8s_clusters
|
||||
K8sNamespace string `gorm:"size:128;comment:K8s部署命名空间" json:"k8s_namespace,omitempty"`
|
||||
K8sDeployment string `gorm:"size:128;comment:K8s Deployment 名称" json:"k8s_deployment,omitempty"`
|
||||
K8sContainerName string `gorm:"size:128;comment:K8s更新镜像目标容器" json:"k8s_container_name,omitempty"`
|
||||
|
||||
// 仓库和镜像仓库关联(旧字段,待废弃)
|
||||
RepoID *uint `json:"repo_id"` // FK → deploy_pipeline_repos
|
||||
RegistryID *uint `json:"registry_id"` // FK → deploy_pipeline_registries
|
||||
|
||||
// 凭证关联(直接关联凭证 ID)
|
||||
// 凭证关联(直接关联统一凭证 ID)// Logan.Li
|
||||
GitCredentialID *uint `json:"git_credential_id"` // FK → iam_credentials (Git Token)
|
||||
RegistryCredentialID *uint `json:"registry_credential_id"` // FK → iam_credentials (Docker Password)
|
||||
|
||||
@@ -71,39 +66,37 @@ type Pipeline struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Repo *PipelineRepo `json:"repo,omitempty" gorm:"foreignKey:RepoID"`
|
||||
Registry *PipelineRegistry `json:"registry,omitempty" gorm:"foreignKey:RegistryID"`
|
||||
Environment *DeployEnvironment `json:"environment,omitempty" gorm:"foreignKey:EnvironmentID"`
|
||||
Environment *DeployEnvironment `json:"environment,omitempty" gorm:"foreignKey:EnvironmentID"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Pipeline) TableName() string {
|
||||
return "ops_pipelines"
|
||||
return "deploy_pipelines"
|
||||
}
|
||||
|
||||
// PipelineRun 流水线运行记录(CI 执行)
|
||||
type PipelineRun struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID uint `gorm:"not null" json:"pipeline_id"`
|
||||
BuildNumber int `json:"build_number"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
||||
Branch string `gorm:"size:64" json:"branch"`
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
ArtifactURL string `gorm:"size:500" json:"artifact_url"` // 构建产物地址
|
||||
WorkspacePath string `gorm:"size:500" json:"workspace_path"` // 工作区路径
|
||||
BuildNodeID *uint `json:"build_node_id,omitempty"` // 实际执行节点(0/nil=Master)
|
||||
BuildNodeName string `gorm:"size:64" json:"build_node_name,omitempty"`
|
||||
Duration int `json:"duration"` // 秒
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Logs string `gorm:"type:longtext" json:"logs"`
|
||||
TriggeredBy string `gorm:"size:64" json:"triggered_by"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID uint `gorm:"not null" json:"pipeline_id"`
|
||||
BuildNumber int `json:"build_number"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
||||
Branch string `gorm:"size:64" json:"branch"`
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
ArtifactURL string `gorm:"size:500" json:"artifact_url"` // 构建产物地址
|
||||
WorkspacePath string `gorm:"size:500" json:"workspace_path"` // 工作区路径
|
||||
BuildNodeID *uint `json:"build_node_id,omitempty"` // 实际执行节点(0/nil=Master)
|
||||
BuildNodeName string `gorm:"size:64" json:"build_node_name,omitempty"`
|
||||
Duration int `json:"duration"` // 秒
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Logs string `gorm:"type:longtext" json:"logs"`
|
||||
TriggeredBy string `gorm:"size:64" json:"triggered_by"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Pipeline *Pipeline `json:"pipeline,omitempty"`
|
||||
@@ -111,34 +104,34 @@ type PipelineRun struct {
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRun) TableName() string {
|
||||
return "ops_pipeline_runs"
|
||||
return "deploy_pipeline_runs"
|
||||
}
|
||||
|
||||
// AppRelease 应用发布模型(CD:从 CI 产物部署到目标环境)
|
||||
type AppRelease struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID *uint `json:"pipeline_id"` // 来源流水线
|
||||
PipelineRunID *uint `json:"pipeline_run_id"` // 来源 CI 执行记录
|
||||
AppName string `gorm:"size:128;not null" json:"app_name"`
|
||||
Version string `gorm:"size:64;not null" json:"version"`
|
||||
Environment string `gorm:"size:32;not null" json:"environment"` // dev, test, staging, prod
|
||||
DeployType string `gorm:"size:32;default:server" json:"deploy_type"` // server, kubernetes
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected, deploying, success, failed, rolled_back
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
Approver string `gorm:"size:64" json:"approver"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
DeployedAt *time.Time `json:"deployed_at"`
|
||||
RollbackAt *time.Time `json:"rollback_at"`
|
||||
Duration int `json:"duration"`
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
K8sClusterID *uint `json:"k8s_cluster_id"` // Kubernetes 部署目标集群
|
||||
K8sNamespace string `gorm:"size:128" json:"k8s_namespace"` // Kubernetes 部署目标命名空间
|
||||
Servers string `gorm:"type:text" json:"servers"` // JSON(传统服务器部署目标)
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID *uint `json:"pipeline_id"` // 来源流水线
|
||||
PipelineRunID *uint `json:"pipeline_run_id"` // 来源 CI 执行记录
|
||||
AppName string `gorm:"size:128;not null" json:"app_name"`
|
||||
Version string `gorm:"size:64;not null" json:"version"`
|
||||
Environment string `gorm:"size:32;not null" json:"environment"` // dev, test, staging, prod
|
||||
DeployType string `gorm:"size:32;default:server" json:"deploy_type"` // server, kubernetes
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected, deploying, success, failed, rolled_back
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
Approver string `gorm:"size:64" json:"approver"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
DeployedAt *time.Time `json:"deployed_at"`
|
||||
RollbackAt *time.Time `json:"rollback_at"`
|
||||
Duration int `json:"duration"`
|
||||
ImageTag string `gorm:"size:255" json:"image_tag"` // 构建产物镜像标签
|
||||
K8sClusterID *uint `json:"k8s_cluster_id"` // Kubernetes 部署目标集群
|
||||
K8sNamespace string `gorm:"size:128" json:"k8s_namespace"` // Kubernetes 部署目标命名空间
|
||||
Servers string `gorm:"type:text" json:"servers"` // JSON(传统服务器部署目标)
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
@@ -150,7 +143,7 @@ func (AppRelease) TableName() string {
|
||||
type CreatePipelineRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
JobName string `json:"job_name"` // Webhook Job名称
|
||||
JobName string `json:"job_name"` // Webhook Job名称
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type" binding:"omitempty,oneof=build deploy test"`
|
||||
Source string `json:"source"`
|
||||
@@ -160,9 +153,9 @@ type CreatePipelineRequest struct {
|
||||
Variables string `json:"variables"`
|
||||
|
||||
// 部署模式
|
||||
DeployMode string `json:"deploy_mode"` // branch / tag
|
||||
DeployTarget string `json:"deploy_target"` // ssh / k8s
|
||||
ServerIDs string `json:"server_ids"` // SSH 服务器ID JSON [1,2,3]
|
||||
DeployMode string `json:"deploy_mode"` // branch / tag
|
||||
DeployTarget string `json:"deploy_target"` // ssh / k8s
|
||||
ServerIDs string `json:"server_ids"` // SSH 服务器ID JSON [1,2,3]
|
||||
DeployRemotePath string `json:"deploy_remote_path"`
|
||||
DeployScript string `json:"deploy_script"`
|
||||
K8sClusterID *uint `json:"k8s_cluster_id"`
|
||||
@@ -170,12 +163,10 @@ type CreatePipelineRequest struct {
|
||||
K8sDeployment string `json:"k8s_deployment"`
|
||||
K8sContainerName string `json:"k8s_container_name"`
|
||||
|
||||
RepoID *uint `json:"repo_id"`
|
||||
RegistryID *uint `json:"registry_id"`
|
||||
// 凭证关联
|
||||
// 凭证关联 // Logan.Li
|
||||
GitCredentialID *uint `json:"git_credential_id"`
|
||||
RegistryCredentialID *uint `json:"registry_credential_id"`
|
||||
EnvironmentID *uint `json:"environment_id"`
|
||||
EnvironmentID *uint `json:"environment_id"`
|
||||
|
||||
// 触发配置
|
||||
TriggerMode string `json:"trigger_mode"`
|
||||
@@ -196,17 +187,17 @@ type CreatePipelineRequest struct {
|
||||
|
||||
// UpdatePipelineRequest 更新流水线请求
|
||||
type UpdatePipelineRequest struct {
|
||||
Name string `json:"name"`
|
||||
JobName string `json:"job_name"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Source string `json:"source"`
|
||||
Branch string `json:"branch"`
|
||||
Dockerfile string `json:"dockerfile"`
|
||||
Stages string `json:"stages"`
|
||||
Variables string `json:"variables"`
|
||||
DeployMode string `json:"deploy_mode"`
|
||||
DeployTarget string `json:"deploy_target"`
|
||||
Name string `json:"name"`
|
||||
JobName string `json:"job_name"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Source string `json:"source"`
|
||||
Branch string `json:"branch"`
|
||||
Dockerfile string `json:"dockerfile"`
|
||||
Stages string `json:"stages"`
|
||||
Variables string `json:"variables"`
|
||||
DeployMode string `json:"deploy_mode"`
|
||||
DeployTarget string `json:"deploy_target"`
|
||||
ServerIDs string `json:"server_ids"`
|
||||
DeployRemotePath string `json:"deploy_remote_path"`
|
||||
DeployScript string `json:"deploy_script"`
|
||||
@@ -214,12 +205,10 @@ type UpdatePipelineRequest struct {
|
||||
K8sNamespace string `json:"k8s_namespace"`
|
||||
K8sDeployment string `json:"k8s_deployment"`
|
||||
K8sContainerName string `json:"k8s_container_name"`
|
||||
RepoID *uint `json:"repo_id"`
|
||||
RegistryID *uint `json:"registry_id"`
|
||||
// 凭证关联
|
||||
// 凭证关联 // Logan.Li
|
||||
GitCredentialID *uint `json:"git_credential_id"`
|
||||
RegistryCredentialID *uint `json:"registry_credential_id"`
|
||||
EnvironmentID *uint `json:"environment_id"`
|
||||
EnvironmentID *uint `json:"environment_id"`
|
||||
// 触发配置
|
||||
TriggerMode string `json:"trigger_mode"`
|
||||
WatchBranches string `json:"watch_branches"`
|
||||
@@ -228,7 +217,7 @@ type UpdatePipelineRequest struct {
|
||||
WebhookToken string `json:"webhook_token"`
|
||||
// 缓存
|
||||
CachePaths string `json:"cache_paths"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
|
||||
// 并发控制
|
||||
MaxExecutors int `json:"max_executors"`
|
||||
@@ -240,7 +229,7 @@ type UpdatePipelineRequest struct {
|
||||
// TriggerPipelineRequest 触发流水线请求
|
||||
type TriggerPipelineRequest struct {
|
||||
Branch string `json:"branch"`
|
||||
Tag string `json:"tag"` // 发布 Tag
|
||||
Tag string `json:"tag"` // 发布 Tag
|
||||
Variables map[string]string `json:"variables"`
|
||||
}
|
||||
|
||||
@@ -263,10 +252,10 @@ type CreateAppReleaseRequest struct {
|
||||
|
||||
// PipelineStats 流水线统计
|
||||
type PipelineStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Success int64 `json:"success"`
|
||||
Failed int64 `json:"failed"`
|
||||
Running int64 `json:"running"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
SuccessRate float64 `json:"success_rate"`
|
||||
Total int64 `json:"total"`
|
||||
Success int64 `json:"success"`
|
||||
Failed int64 `json:"failed"`
|
||||
Running int64 `json:"running"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
SuccessRate float64 `json:"success_rate"`
|
||||
}
|
||||
@@ -80,10 +80,10 @@ type OpsOverviewStats struct {
|
||||
|
||||
// CostStats 成本统计
|
||||
type CostStats struct {
|
||||
TotalCost float64 `json:"total_cost"`
|
||||
MonthCost float64 `json:"month_cost"`
|
||||
CloudCosts []CloudCost `json:"cloud_costs"`
|
||||
MonthTrend []MonthTrend `json:"month_trend"`
|
||||
TotalCost float64 `json:"total_cost"`
|
||||
MonthCost float64 `json:"month_cost"`
|
||||
CloudCosts []CloudCost `json:"cloud_costs"`
|
||||
MonthTrend []MonthTrend `json:"month_trend"`
|
||||
}
|
||||
|
||||
// CloudCost 云平台成本
|
||||
@@ -115,8 +115,8 @@ type ServerResource struct {
|
||||
|
||||
// DomainCert 域名证书
|
||||
type DomainCert struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ExpireDate string `json:"expire_date"`
|
||||
DaysUntilExpiry int `json:"days_until_expiry"`
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ExpireDate string `json:"expire_date"`
|
||||
DaysUntilExpiry int `json:"days_until_expiry"`
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CustomDashboard 自定义监控仪表盘(面板配置存 JSON) // Logan.Li
|
||||
type CustomDashboard struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:仪表盘名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(512);comment:描述" json:"description"`
|
||||
Datasource string `gorm:"type:varchar(32);default:'prometheus';comment:数据源类型" json:"datasource"`
|
||||
DatasourceURL string `gorm:"type:varchar(512);comment:数据源URL(留空则用默认Prometheus)" json:"datasource_url"`
|
||||
// Panels 存储面板配置 JSON 数组: [{id,title,type,query,width,height,x,y,options}]
|
||||
Panels string `gorm:"type:longtext;comment:面板配置JSON" json:"panels"`
|
||||
// Tags 标签(JSON 数组字符串)
|
||||
Tags string `gorm:"type:varchar(512);comment:标签JSON" json:"tags,omitempty"`
|
||||
// 归属
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by"`
|
||||
IsDefault bool `gorm:"default:false;index;comment:是否默认仪表盘" json:"is_default"`
|
||||
IsFavorite bool `gorm:"default:false;comment:是否收藏" json:"is_favorite"`
|
||||
// 时间戳
|
||||
CreatedAt time.Time `gorm:"not null;index;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (CustomDashboard) TableName() string {
|
||||
return "monitor_custom_dashboards"
|
||||
}
|
||||
+10
-74
@@ -2,91 +2,27 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
// ============================================
|
||||
// PipelineRepo Git 仓库认证配置
|
||||
// ============================================
|
||||
|
||||
// RepoAuthType 仓库认证方式
|
||||
type RepoAuthType string
|
||||
|
||||
const (
|
||||
RepoAuthToken RepoAuthType = "token" // Personal Access Token
|
||||
RepoAuthSSH RepoAuthType = "ssh" // SSH Key
|
||||
RepoAuthPassword RepoAuthType = "password" // 用户名+密码
|
||||
)
|
||||
|
||||
// PipelineRepo Git 仓库认证配置表
|
||||
type PipelineRepo struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
URL string `gorm:"type:varchar(512);not null;comment:仓库 URL" json:"url"`
|
||||
AuthType RepoAuthType `gorm:"type:varchar(16);default:'token';comment:认证方式: token/ssh/password" json:"auth_type"`
|
||||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRepo) TableName() string {
|
||||
return "deploy_pipeline_repos"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// PipelineRegistry 镜像仓库认证配置
|
||||
// ============================================
|
||||
|
||||
// RegistryAuthType 镜像仓库认证方式
|
||||
type RegistryAuthType string
|
||||
|
||||
const (
|
||||
RegistryAuthToken RegistryAuthType = "token" // Access Token
|
||||
RegistryAuthPassword RegistryAuthType = "password" // 用户名+密码
|
||||
)
|
||||
|
||||
// PipelineRegistry 镜像仓库认证配置表
|
||||
type PipelineRegistry struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
RegistryURL string `gorm:"type:varchar(512);not null;comment:镜像仓库地址" json:"registry_url"`
|
||||
Namespace string `gorm:"type:varchar(128);comment:默认命名空间" json:"namespace,omitempty"`
|
||||
AuthType RegistryAuthType `gorm:"type:varchar(16);default:'password';comment:认证方式: token/password" json:"auth_type"`
|
||||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRegistry) TableName() string {
|
||||
return "deploy_pipeline_registries"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// PipelineStage 流水线阶段定义(JSON)
|
||||
// ============================================
|
||||
|
||||
// PipelineStage 一个阶段包含多个任务
|
||||
type PipelineStage struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // source/build/deploy/test/custom
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // source/build/deploy/test/custom
|
||||
Tasks []PipelineTask `json:"tasks"`
|
||||
}
|
||||
|
||||
// PipelineTask 阶段内的任务
|
||||
type PipelineTask struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // build/deploy/test/custom
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Config map[string]string `json:"config,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
ScriptType string `json:"script_type,omitempty"` // shell/python
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // build/deploy/test/custom
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Config map[string]string `json:"config,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
ScriptType string `json:"script_type,omitempty"` // shell/python
|
||||
}
|
||||
|
||||
// ============================================
|
||||
|
||||
@@ -3,8 +3,8 @@ package model
|
||||
import "time"
|
||||
|
||||
// ============================================
|
||||
// DeployTool 工具配置(懒加载/预装/禁用)
|
||||
// 按 deploy_ 前缀,与 PipelineRepo/Registry 同属发布配置域
|
||||
// DeployTool 工具配置(懒加载/预装/禁用)// Logan.Li
|
||||
// 按 deploy_ 前缀归属发布配置域。// Logan.Li
|
||||
// ============================================
|
||||
|
||||
// ToolInstallMethod 安装方式
|
||||
@@ -395,29 +395,29 @@ echo "[Node.js] Installed: $(/usr/local/bin/node --version) / npm $("$NVM_DIR/ve
|
||||
},
|
||||
// ──── Git — 版本控制(懒加载, U4 镜像瘦身)// Logan.Li ────
|
||||
{
|
||||
Name: "git",
|
||||
DisplayName: "Git",
|
||||
Description: "版本控制工具,流水线代码拉取使用(首次使用自动安装)",
|
||||
Category: "build",
|
||||
InstallMethod: ToolLazy,
|
||||
BinaryName: "git",
|
||||
InstallPath: "/usr/bin/git",
|
||||
CheckCommand: "git --version 2>/dev/null",
|
||||
Name: "git",
|
||||
DisplayName: "Git",
|
||||
Description: "版本控制工具,流水线代码拉取使用(首次使用自动安装)",
|
||||
Category: "build",
|
||||
InstallMethod: ToolLazy,
|
||||
BinaryName: "git",
|
||||
InstallPath: "/usr/bin/git",
|
||||
CheckCommand: "git --version 2>/dev/null",
|
||||
InstallScript: `apk add --no-cache git`,
|
||||
SortOrder: 6,
|
||||
SortOrder: 6,
|
||||
},
|
||||
// ──── Docker CLI — 容器构建(懒加载, U4 镜像瘦身)// Logan.Li ────
|
||||
{
|
||||
Name: "docker-cli",
|
||||
DisplayName: "Docker CLI",
|
||||
Description: "Docker 命令行工具,流水线镜像构建/推送使用(首次使用自动安装)",
|
||||
Category: "deploy",
|
||||
InstallMethod: ToolLazy,
|
||||
BinaryName: "docker",
|
||||
InstallPath: "/usr/bin/docker",
|
||||
CheckCommand: "docker --version 2>/dev/null",
|
||||
InstallScript: `apk add --no-cache docker-cli`,
|
||||
SortOrder: 7,
|
||||
Name: "docker-cli",
|
||||
DisplayName: "Docker CLI",
|
||||
Description: "Docker 命令行工具,流水线镜像构建/推送使用(首次使用自动安装)",
|
||||
Category: "deploy",
|
||||
InstallMethod: ToolLazy,
|
||||
BinaryName: "docker",
|
||||
InstallPath: "/usr/bin/docker",
|
||||
CheckCommand: "docker --version 2>/dev/null",
|
||||
InstallScript: `apk add --no-cache docker-cli`,
|
||||
SortOrder: 7,
|
||||
},
|
||||
}
|
||||
}
|
||||
+98
-99
@@ -2,61 +2,60 @@ 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"`
|
||||
IngressCount int `gorm:"default:0" json:"ingress_count"` // 路由/Ingress 数量 // Logan.Li
|
||||
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"`
|
||||
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"`
|
||||
IngressCount int `gorm:"default:0" json:"ingress_count"` // 路由/Ingress 数量 // Logan.Li
|
||||
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"
|
||||
return "k8s_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"`
|
||||
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"`
|
||||
@@ -64,25 +63,25 @@ type KubernetesNode struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesNode) TableName() string {
|
||||
return "kubernetes_nodes"
|
||||
return "k8s_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"`
|
||||
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"`
|
||||
@@ -90,23 +89,23 @@ type KubernetesPod struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesPod) TableName() string {
|
||||
return "kubernetes_pods"
|
||||
return "k8s_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"`
|
||||
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"`
|
||||
@@ -114,23 +113,23 @@ type KubernetesDeployment struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesDeployment) TableName() string {
|
||||
return "kubernetes_deployments"
|
||||
return "k8s_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"`
|
||||
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"`
|
||||
@@ -138,22 +137,22 @@ type KubernetesService struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesService) TableName() string {
|
||||
return "kubernetes_services"
|
||||
return "k8s_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"`
|
||||
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"`
|
||||
@@ -161,7 +160,7 @@ type KubernetesIngress struct {
|
||||
|
||||
// TableName 表名
|
||||
func (KubernetesIngress) TableName() string {
|
||||
return "kubernetes_ingresses"
|
||||
return "k8s_ingresses"
|
||||
}
|
||||
|
||||
// CreateKubernetesClusterRequest 创建K8s集群请求
|
||||
@@ -169,7 +168,7 @@ 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
|
||||
ConfigType int `json:"config_type"` // 0=token, 1=kubeconfig
|
||||
APIServer string `json:"api_server"`
|
||||
APIEndpoint string `json:"api_endpoint"`
|
||||
Token string `json:"token"`
|
||||
@@ -201,5 +200,5 @@ type TopologyLayout struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (TopologyLayout) TableName() string {
|
||||
return "kubernetes_topology_layouts"
|
||||
return "k8s_topology_layouts"
|
||||
}
|
||||
+16
-16
@@ -5,16 +5,16 @@ import "time"
|
||||
// LLMConfig 大语言模型配置(单行配置,类似 LDAPConfig) // Logan.Li
|
||||
// 支持 OpenAI 兼容接口(OpenAI / DeepSeek / 智谱GLM / 通义千问 / Moonshot / Kimi / 小米MiMo / Anthropic(需代理) / Ollama / 自定义)
|
||||
type LLMConfig struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Provider string `gorm:"size:50;not null;default:openai" json:"provider"` // deepseek/glm/glm-coding/kimi/moonshot/minimax/minimax-coding/mimo/siliconflow/openai/anthropic/ollama/vllm/custom
|
||||
Model string `gorm:"size:100;not null;default:gpt-4o-mini" json:"model"` // 模型名,如 gpt-4o-mini / deepseek-v4-flash
|
||||
APIKey string `gorm:"size:500" json:"api_key"` // API Key(GET 时会被脱敏)
|
||||
Endpoint string `gorm:"size:500" json:"endpoint"` // 基础地址,如 https://api.openai.com/v1
|
||||
Temperature float64 `gorm:"default:0.7" json:"temperature"` // 采样温度 0-2
|
||||
MaxTokens int `gorm:"default:2000" json:"max_tokens"` // 最大输出 token
|
||||
SystemPrompt string `gorm:"type:text" json:"system_prompt"` // 系统提示词(AIOps 运维助手角色)
|
||||
Enabled bool `gorm:"default:false" json:"enabled"` // 是否启用
|
||||
ReasoningEnabled bool `gorm:"default:false" json:"reasoning_enabled"` // 是否启用推理/Plan 模式(OpenAI o-series / DeepSeek R1 / Claude thinking 等) // Logan.Li
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Provider string `gorm:"size:50;not null;default:openai" json:"provider"` // deepseek/glm/glm-coding/kimi/moonshot/minimax/minimax-coding/mimo/siliconflow/openai/anthropic/ollama/vllm/custom
|
||||
Model string `gorm:"size:100;not null;default:gpt-4o-mini" json:"model"` // 模型名,如 gpt-4o-mini / deepseek-v4-flash
|
||||
APIKey string `gorm:"size:500" json:"api_key"` // API Key(GET 时会被脱敏)
|
||||
Endpoint string `gorm:"size:500" json:"endpoint"` // 基础地址,如 https://api.openai.com/v1
|
||||
Temperature float64 `gorm:"default:0.7" json:"temperature"` // 采样温度 0-2
|
||||
MaxTokens int `gorm:"default:2000" json:"max_tokens"` // 最大输出 token
|
||||
SystemPrompt string `gorm:"type:text" json:"system_prompt"` // 系统提示词(AIOps 运维助手角色)
|
||||
Enabled bool `gorm:"default:false" json:"enabled"` // 是否启用
|
||||
ReasoningEnabled bool `gorm:"default:false" json:"reasoning_enabled"` // 是否启用推理/Plan 模式(OpenAI o-series / DeepSeek R1 / Claude thinking 等) // Logan.Li
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func (LLMConfig) TableName() string { return "ai_llm_configs" }
|
||||
type SaveLLMConfigRequest struct {
|
||||
Provider string `json:"provider"`
|
||||
Model string `json:"model"`
|
||||
APIKey string `json:"api_key"` // 若为脱敏值(含 ****)则后端保留原值
|
||||
APIKey string `json:"api_key"` // 若为脱敏值(含 ****)则后端保留原值
|
||||
Endpoint string `json:"endpoint"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
@@ -37,7 +37,7 @@ type SaveLLMConfigRequest struct {
|
||||
|
||||
// ChatMessage 对话消息 // Logan.Li
|
||||
type ChatMessage struct {
|
||||
Role string `json:"role"` // system / user / assistant
|
||||
Role string `json:"role"` // system / user / assistant
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ type ChatResponse struct {
|
||||
// 仅持久化成功完成的对话(用户消息 + 助手回复成对写入),错误气泡为瞬时 UI 不入库
|
||||
type ChatHistory struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
UserID uint `gorm:"index;not null" json:"user_id"` // 所属用户(JWT 中间件注入)
|
||||
UserID uint `gorm:"index;not null" json:"user_id"` // 所属用户(JWT 中间件注入)
|
||||
SessionID string `gorm:"size:64;index;not null;default:''" json:"session_id"` // 对话会话 ID(前端 UUID)
|
||||
Role string `gorm:"size:16;not null" json:"role"` // user / assistant
|
||||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||||
Model string `gorm:"size:100" json:"model"` // 生成回复所用模型(仅 assistant 行有意义)
|
||||
Role string `gorm:"size:16;not null" json:"role"` // user / assistant
|
||||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||||
Model string `gorm:"size:100" json:"model"` // 生成回复所用模型(仅 assistant 行有意义)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
|
||||
@@ -78,4 +78,4 @@ type TestLogDSReq struct {
|
||||
Token string `json:"token"`
|
||||
Headers string `json:"headers"`
|
||||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||||
}
|
||||
}
|
||||
@@ -4,33 +4,33 @@ import "time"
|
||||
|
||||
// LogScopeRole 日志查询范围权限(正则匹配 ES 索引 / Loki label) // Logan.Li
|
||||
type LogScopeRole struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Engine string `gorm:"size:32;default:*;comment:引擎 loki/elasticsearch/*" json:"engine"`
|
||||
MatchField string `gorm:"size:32;not null;comment:匹配维度 index/app/namespace/job" json:"match_field"`
|
||||
Pattern string `gorm:"size:255;not null;comment:正则表达式" json:"pattern"`
|
||||
DatasourceID *uint `json:"datasource_id,omitempty"`
|
||||
Role string `gorm:"size:16;default:viewer;comment:viewer/analyst" json:"role"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Status int `gorm:"default:1;comment:0禁用1启用" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Engine string `gorm:"size:32;default:*;comment:引擎 loki/elasticsearch/*" json:"engine"`
|
||||
MatchField string `gorm:"size:32;not null;comment:匹配维度 index/app/namespace/job" json:"match_field"`
|
||||
Pattern string `gorm:"size:255;not null;comment:正则表达式" json:"pattern"`
|
||||
DatasourceID *uint `json:"datasource_id,omitempty"`
|
||||
Role string `gorm:"size:16;default:viewer;comment:viewer/analyst" json:"role"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Status int `gorm:"default:1;comment:0禁用1启用" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (LogScopeRole) TableName() string { return "monitor_log_scope_roles" }
|
||||
func (LogScopeRole) TableName() string { return "iam_log_scope_roles" }
|
||||
|
||||
// UserLogScopeRole 用户 ↔ 日志范围权限 // Logan.Li
|
||||
type UserLogScopeRole struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
UserID uint `gorm:"uniqueIndex:idx_user_log_scope;not null" json:"user_id"`
|
||||
LogScopeRoleID uint `gorm:"uniqueIndex:idx_user_log_scope;not null" json:"log_scope_role_id"`
|
||||
UserID uint `gorm:"uniqueIndex:idx_iam_user_log_scope_role;not null" json:"user_id"`
|
||||
LogScopeRoleID uint `gorm:"uniqueIndex:idx_iam_user_log_scope_role;not null" json:"log_scope_role_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
LogScopeRole *LogScopeRole `json:"log_scope_role,omitempty" gorm:"foreignKey:LogScopeRoleID"`
|
||||
LogScopeRole *LogScopeRole `json:"log_scope_role,omitempty" gorm:"foreignKey:LogScopeRoleID;references:ID"`
|
||||
}
|
||||
|
||||
func (UserLogScopeRole) TableName() string { return "monitor_user_log_scope_roles" }
|
||||
func (UserLogScopeRole) TableName() string { return "iam_user_log_scope_roles" }
|
||||
|
||||
// CreateLogScopeRoleRequest 创建日志权限策略 // Logan.Li
|
||||
type CreateLogScopeRoleRequest struct {
|
||||
@@ -64,9 +64,9 @@ type AssignLogScopeRoleRequest struct {
|
||||
|
||||
// PreviewLogScopeRequest 命中预览 // Logan.Li
|
||||
type PreviewLogScopeRequest struct {
|
||||
Engine string `json:"engine" binding:"required,oneof=loki elasticsearch"`
|
||||
DatasourceID uint `json:"datasource_id"`
|
||||
Index string `json:"index"`
|
||||
Query string `json:"query"`
|
||||
SampleValue string `json:"sample_value"`
|
||||
}
|
||||
Engine string `json:"engine" binding:"required,oneof=loki elasticsearch"`
|
||||
DatasourceID uint `json:"datasource_id"`
|
||||
Index string `json:"index"`
|
||||
Query string `json:"query"`
|
||||
SampleValue string `json:"sample_value"`
|
||||
}
|
||||
@@ -8,19 +8,19 @@ type LoginLog struct {
|
||||
UserID *uint `json:"user_id"`
|
||||
Username string `gorm:"size:64;index" json:"username"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
Location string `gorm:"size:128" json:"location"` // IP 归属地
|
||||
Browser string `gorm:"size:128" json:"browser"` // 浏览器
|
||||
OS string `gorm:"size:128" json:"os"` // 操作系统
|
||||
Location string `gorm:"size:128" json:"location"` // IP 归属地
|
||||
Browser string `gorm:"size:128" json:"browser"` // 浏览器
|
||||
OS string `gorm:"size:128" json:"os"` // 操作系统
|
||||
LoginType string `gorm:"size:32;default:password" json:"login_type"` // password / ldap
|
||||
UserAgent string `gorm:"size:500" json:"user_agent"`
|
||||
Status string `gorm:"size:32" json:"status"` // success, failed
|
||||
Status string `gorm:"size:32" json:"status"` // success, failed
|
||||
FailReason string `gorm:"size:255" json:"fail_reason"`
|
||||
LoginAt time.Time `gorm:"index" json:"login_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (LoginLog) TableName() string {
|
||||
return "sys_login_logs"
|
||||
return "audit_login_logs"
|
||||
}
|
||||
|
||||
// LoginLogQuery 登录日志查询
|
||||
|
||||
@@ -7,8 +7,8 @@ import "time"
|
||||
type MetricsAggregate struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:255;index:idx_agg;not null" json:"hostname"`
|
||||
Metric string `gorm:"size:32;index:idx_agg;not null" json:"metric"` // cpu / mem / load1 / disk / net_rx / net_tx
|
||||
Interval string `gorm:"size:8;index:idx_agg;not null" json:"interval"` // 1m / 5m / 1h / 6h / 1d
|
||||
Metric string `gorm:"size:32;index:idx_agg;not null" json:"metric"` // cpu / mem / load1 / disk / net_rx / net_tx
|
||||
Interval string `gorm:"size:8;index:idx_agg;not null" json:"interval"` // 1m / 5m / 1h / 6h / 1d
|
||||
Avg float64 `gorm:"type:decimal(10,2)" json:"avg"`
|
||||
MaxV float64 `gorm:"column:max_v;type:decimal(10,2)" json:"max"`
|
||||
MinV float64 `gorm:"column:min_v;type:decimal(10,2)" json:"min"`
|
||||
@@ -19,7 +19,7 @@ type MetricsAggregate struct {
|
||||
}
|
||||
|
||||
func (MetricsAggregate) TableName() string {
|
||||
return "monitor_metrics_aggregate"
|
||||
return "monitor_metric_aggregates"
|
||||
}
|
||||
|
||||
// AggregateReq 聚合触发请求
|
||||
|
||||
+108
-109
@@ -42,18 +42,18 @@ type MonitorTarget struct {
|
||||
OS string `gorm:"type:varchar(64);comment:操作系统" json:"os,omitempty"`
|
||||
OSVersion string `gorm:"type:varchar(64);comment:OS版本" json:"os_version,omitempty"`
|
||||
Arch string `gorm:"type:varchar(16);comment:系统架构" json:"arch,omitempty"`
|
||||
Kernel string `gorm:"type:varchar(64);comment:内核版本" json:"kernel,omitempty"`
|
||||
HostGroupID uint `gorm:"index;comment:主机组ID" json:"host_group_id,omitempty"`
|
||||
Tags string `gorm:"type:varchar(512);comment:标签JSON" json:"tags,omitempty"`
|
||||
CollectMode string `gorm:"type:varchar(16);default:'agent';comment:采集模式:agent/snmp/api" json:"collect_mode"`
|
||||
SNMPConfig string `gorm:"type:text;comment:SNMP配置JSON" json:"snmp_config,omitempty"`
|
||||
APIConfig string `gorm:"type:text;comment:API配置JSON" json:"api_config,omitempty"`
|
||||
Address string `gorm:"type:varchar(255);comment:监控地址(IP或域名)" json:"address,omitempty"`
|
||||
Protocol string `gorm:"type:varchar(32);comment:协议类型(http/https/tcp/udp/icmp/snmp)" json:"protocol,omitempty"`
|
||||
Timeout int `gorm:"default:30;comment:超时时间(秒)" json:"timeout,omitempty"`
|
||||
Config string `gorm:"type:text;comment:通用配置JSON" json:"config,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:采集间隔(秒)" json:"interval"`
|
||||
Labels string `gorm:"type:varchar(512);comment:标签JSON" json:"labels,omitempty"`
|
||||
Kernel string `gorm:"type:varchar(64);comment:内核版本" json:"kernel,omitempty"`
|
||||
HostGroupID uint `gorm:"index;comment:主机组ID" json:"host_group_id,omitempty"`
|
||||
Tags string `gorm:"type:varchar(512);comment:标签JSON" json:"tags,omitempty"`
|
||||
CollectMode string `gorm:"type:varchar(16);default:'agent';comment:采集模式:agent/snmp/api" json:"collect_mode"`
|
||||
SNMPConfig string `gorm:"type:text;comment:SNMP配置JSON" json:"snmp_config,omitempty"`
|
||||
APIConfig string `gorm:"type:text;comment:API配置JSON" json:"api_config,omitempty"`
|
||||
Address string `gorm:"type:varchar(255);comment:监控地址(IP或域名)" json:"address,omitempty"`
|
||||
Protocol string `gorm:"type:varchar(32);comment:协议类型(http/https/tcp/udp/icmp/snmp)" json:"protocol,omitempty"`
|
||||
Timeout int `gorm:"default:30;comment:超时时间(秒)" json:"timeout,omitempty"`
|
||||
Config string `gorm:"type:text;comment:通用配置JSON" json:"config,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:采集间隔(秒)" json:"interval"`
|
||||
Labels string `gorm:"type:varchar(512);comment:标签JSON" json:"labels,omitempty"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;index;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
@@ -86,36 +86,36 @@ const (
|
||||
type DataSourceType string
|
||||
|
||||
const (
|
||||
DataSourceAgent DataSourceType = "agent" // Agent采集
|
||||
DataSourceSNMP DataSourceType = "snmp" // SNMP采集
|
||||
DataSourceAPI DataSourceType = "api" // API采集
|
||||
DataSourceAgent DataSourceType = "agent" // Agent采集
|
||||
DataSourceSNMP DataSourceType = "snmp" // SNMP采集
|
||||
DataSourceAPI DataSourceType = "api" // API采集
|
||||
DataSourcePrometheus DataSourceType = "prometheus" // Prometheus
|
||||
DataSourceZabbix DataSourceType = "zabbix" // Zabbix
|
||||
DataSourceZabbix DataSourceType = "zabbix" // Zabbix
|
||||
)
|
||||
|
||||
// MonitorMetric 监控指标定义表
|
||||
// 定义系统中所有可采集的监控指标元数据
|
||||
type MonitorMetric struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;uniqueIndex:uk_metric_name;comment:指标名称" json:"name"`
|
||||
DisplayName string `gorm:"type:varchar(128);not null;comment:显示名称" json:"display_name"`
|
||||
Description string `gorm:"type:varchar(256);comment:指标描述" json:"description,omitempty"`
|
||||
MetricType MetricType `gorm:"type:varchar(16);not null;comment:指标类型: gauge/counter/summary" json:"metric_type"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
DataSource DataSourceType `gorm:"type:varchar(16);not null;comment:数据来源" json:"data_source"`
|
||||
CollectExpr string `gorm:"type:varchar(256);comment:采集表达式/OID/PromQL" json:"collect_expr,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:采集间隔(秒)" json:"interval"`
|
||||
Labels string `gorm:"type:varchar(512);comment:指标标签定义JSON" json:"labels,omitempty"`
|
||||
ValueType string `gorm:"type:varchar(16);default:'float64';comment:值类型" json:"value_type"`
|
||||
Category string `gorm:"type:varchar(64);comment:指标分类" json:"category,omitempty"`
|
||||
IsDefault bool `gorm:"default:true;comment:是否默认启用" json:"is_default"`
|
||||
IsInternal bool `gorm:"default:false;comment:是否内置指标" json:"is_internal"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
Icon string `gorm:"type:varchar(64);comment:图标" json:"icon,omitempty"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;uniqueIndex:uk_metric_name;comment:指标名称" json:"name"`
|
||||
DisplayName string `gorm:"type:varchar(128);not null;comment:显示名称" json:"display_name"`
|
||||
Description string `gorm:"type:varchar(256);comment:指标描述" json:"description,omitempty"`
|
||||
MetricType MetricType `gorm:"type:varchar(16);not null;comment:指标类型: gauge/counter/summary" json:"metric_type"`
|
||||
Unit string `gorm:"type:varchar(32);comment:单位" json:"unit,omitempty"`
|
||||
DataSource DataSourceType `gorm:"type:varchar(16);not null;comment:数据来源" json:"data_source"`
|
||||
CollectExpr string `gorm:"type:varchar(256);comment:采集表达式/OID/PromQL" json:"collect_expr,omitempty"`
|
||||
Interval int `gorm:"default:60;comment:采集间隔(秒)" json:"interval"`
|
||||
Labels string `gorm:"type:varchar(512);comment:指标标签定义JSON" json:"labels,omitempty"`
|
||||
ValueType string `gorm:"type:varchar(16);default:'float64';comment:值类型" json:"value_type"`
|
||||
Category string `gorm:"type:varchar(64);comment:指标分类" json:"category,omitempty"`
|
||||
IsDefault bool `gorm:"default:true;comment:是否默认启用" json:"is_default"`
|
||||
IsInternal bool `gorm:"default:false;comment:是否内置指标" json:"is_internal"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
Icon string `gorm:"type:varchar(64);comment:图标" json:"icon,omitempty"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
@@ -147,7 +147,7 @@ type MetricValue struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (MetricValue) TableName() string {
|
||||
return "metric_values"
|
||||
return "monitor_metric_values"
|
||||
}
|
||||
|
||||
// MetricHistory 指标历史数据(简化版,供监控查询使用)
|
||||
@@ -213,29 +213,29 @@ func (MetricTag) TableName() string {
|
||||
type DashboardType string
|
||||
|
||||
const (
|
||||
DashboardTypeSystem DashboardType = "system" // 系统内置
|
||||
DashboardTypeCustom DashboardType = "custom" // 自定义
|
||||
DashboardTypeShared DashboardType = "shared" // 共享
|
||||
DashboardTypeSystem DashboardType = "system" // 系统内置
|
||||
DashboardTypeCustom DashboardType = "custom" // 自定义
|
||||
DashboardTypeShared DashboardType = "shared" // 共享
|
||||
)
|
||||
|
||||
// MonitorDashboard 监控大屏配置表
|
||||
// 定义监控大屏的元数据配置
|
||||
type MonitorDashboard struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:大屏名称" json:"name"`
|
||||
Type DashboardType `gorm:"type:varchar(16);default:'custom';comment:大屏类型" json:"type"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
Layout string `gorm:"type:text;comment:布局配置JSON" json:"layout,omitempty"`
|
||||
Theme string `gorm:"type:varchar(32);default:'dark';comment:主题: dark/light" json:"theme"`
|
||||
RefreshRate int `gorm:"default:30;comment:自动刷新间隔(秒)" json:"refresh_rate"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认大屏" json:"is_default"`
|
||||
IsPublic bool `gorm:"default:false;comment:是否公开" json:"is_public"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:大屏名称" json:"name"`
|
||||
Type DashboardType `gorm:"type:varchar(16);default:'custom';comment:大屏类型" json:"type"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
Layout string `gorm:"type:text;comment:布局配置JSON" json:"layout,omitempty"`
|
||||
Theme string `gorm:"type:varchar(32);default:'dark';comment:主题: dark/light" json:"theme"`
|
||||
RefreshRate int `gorm:"default:30;comment:自动刷新间隔(秒)" json:"refresh_rate"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认大屏" json:"is_default"`
|
||||
IsPublic bool `gorm:"default:false;comment:是否公开" json:"is_public"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联关系
|
||||
Panels []DashboardPanel `gorm:"foreignKey:DashboardID" json:"panels,omitempty"`
|
||||
@@ -254,16 +254,16 @@ func (MonitorDashboard) TableName() string {
|
||||
type PanelType string
|
||||
|
||||
const (
|
||||
PanelTypeChart PanelType = "chart" // 图表
|
||||
PanelTypeGauge PanelType = "gauge" // 仪表盘
|
||||
PanelTypeCounter PanelType = "counter" // 计数器
|
||||
PanelTypeTable PanelType = "table" // 表格
|
||||
PanelTypeStatus PanelType = "status" // 状态
|
||||
PanelTypeTopology PanelType = "topology" // 拓扑
|
||||
PanelTypeLog PanelType = "log" // 日志
|
||||
PanelTypeAlertList PanelType = "alert_list" // 告警列表
|
||||
PanelTypeHeatmap PanelType = "heatmap" // 热力图
|
||||
PanelTypeText PanelType = "text" // 文本
|
||||
PanelTypeChart PanelType = "chart" // 图表
|
||||
PanelTypeGauge PanelType = "gauge" // 仪表盘
|
||||
PanelTypeCounter PanelType = "counter" // 计数器
|
||||
PanelTypeTable PanelType = "table" // 表格
|
||||
PanelTypeStatus PanelType = "status" // 状态
|
||||
PanelTypeTopology PanelType = "topology" // 拓扑
|
||||
PanelTypeLog PanelType = "log" // 日志
|
||||
PanelTypeAlertList PanelType = "alert_list" // 告警列表
|
||||
PanelTypeHeatmap PanelType = "heatmap" // 热力图
|
||||
PanelTypeText PanelType = "text" // 文本
|
||||
)
|
||||
|
||||
// ChartType 图表类型
|
||||
@@ -298,13 +298,13 @@ type DashboardPanel struct {
|
||||
QueryExpr string `gorm:"type:text;comment:查询表达式" json:"query_expr,omitempty"`
|
||||
QueryConfig string `gorm:"type:text;comment:查询配置JSON" json:"query_config,omitempty"`
|
||||
// 展示配置
|
||||
TimeRange string `gorm:"type:varchar(16);default:'1h';comment:时间范围" json:"time_range"`
|
||||
RefreshRate int `gorm:"default:0;comment:刷新间隔(秒),0表示继承大屏" json:"refresh_rate"`
|
||||
Thresholds string `gorm:"type:text;comment:阈值配置JSON" json:"thresholds,omitempty"`
|
||||
Colors string `gorm:"type:text;comment:颜色配置JSON" json:"colors,omitempty"`
|
||||
Legend string `gorm:"type:varchar(64);comment:图例配置" json:"legend,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:显示单位" json:"unit,omitempty"`
|
||||
Decimals int `gorm:"default:2;comment:小数位数" json:"decimals"`
|
||||
TimeRange string `gorm:"type:varchar(16);default:'1h';comment:时间范围" json:"time_range"`
|
||||
RefreshRate int `gorm:"default:0;comment:刷新间隔(秒),0表示继承大屏" json:"refresh_rate"`
|
||||
Thresholds string `gorm:"type:text;comment:阈值配置JSON" json:"thresholds,omitempty"`
|
||||
Colors string `gorm:"type:text;comment:颜色配置JSON" json:"colors,omitempty"`
|
||||
Legend string `gorm:"type:varchar(64);comment:图例配置" json:"legend,omitempty"`
|
||||
Unit string `gorm:"type:varchar(32);comment:显示单位" json:"unit,omitempty"`
|
||||
Decimals int `gorm:"default:2;comment:小数位数" json:"decimals"`
|
||||
// 状态
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
@@ -314,18 +314,18 @@ type DashboardPanel struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (DashboardPanel) TableName() string {
|
||||
return "dashboard_panels"
|
||||
return "monitor_dashboard_panels"
|
||||
}
|
||||
|
||||
// PanelQueryConfig 面板查询配置
|
||||
type PanelQueryConfig struct {
|
||||
Metrics []string `json:"metrics"` // 指标名称列表
|
||||
Targets []uint `json:"targets"` // 目标ID列表
|
||||
Instances []string `json:"instances"` // 实例列表
|
||||
Aggregations []string `json:"aggregations"` // 聚合函数
|
||||
GroupBy []string `json:"group_by"` // 分组标签
|
||||
Filters map[string]string `json:"filters"` // 过滤条件
|
||||
Step int `json:"step"` // 步长
|
||||
Metrics []string `json:"metrics"` // 指标名称列表
|
||||
Targets []uint `json:"targets"` // 目标ID列表
|
||||
Instances []string `json:"instances"` // 实例列表
|
||||
Aggregations []string `json:"aggregations"` // 聚合函数
|
||||
GroupBy []string `json:"group_by"` // 分组标签
|
||||
Filters map[string]string `json:"filters"` // 过滤条件
|
||||
Step int `json:"step"` // 步长
|
||||
LegendFormat string `json:"legend_format"` // 图例格式
|
||||
}
|
||||
|
||||
@@ -362,9 +362,9 @@ func (HostGroup) TableName() string {
|
||||
type ProbeType string
|
||||
|
||||
const (
|
||||
ProbeTypeHTTP ProbeType = "http_get" // HTTP GET 探测
|
||||
ProbeTypeTCP ProbeType = "tcp_socket" // TCP 端口连接探测
|
||||
ProbeTypeExec ProbeType = "exec_command" // 命令执行探测
|
||||
ProbeTypeHTTP ProbeType = "http_get" // HTTP GET 探测
|
||||
ProbeTypeTCP ProbeType = "tcp_socket" // TCP 端口连接探测
|
||||
ProbeTypeExec ProbeType = "exec_command" // 命令执行探测
|
||||
)
|
||||
|
||||
// ProbeStatus 探针结果状态
|
||||
@@ -378,33 +378,33 @@ const (
|
||||
// HealthProbe 健康探针配置表
|
||||
// 存储在平台 DB,Agent 拉取配置后在目标主机本地执行,结果随心跳上报
|
||||
type HealthProbe struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;index" json:"name"`
|
||||
Hostname string `gorm:"type:varchar(255);index;not null" json:"hostname"`
|
||||
ProbeType ProbeType `gorm:"type:varchar(32);not null" json:"probe_type"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;index" json:"name"`
|
||||
Hostname string `gorm:"type:varchar(255);index;not null" json:"hostname"`
|
||||
ProbeType ProbeType `gorm:"type:varchar(32);not null" json:"probe_type"`
|
||||
// HTTP 探针配置
|
||||
HTTPURL string `gorm:"type:varchar(512)" json:"http_url,omitempty"`
|
||||
HTTPMethod string `gorm:"type:varchar(10);default:GET" json:"http_method,omitempty"`
|
||||
HTTPHeaders string `gorm:"type:text" json:"http_headers,omitempty"`
|
||||
HTTPExpectCode int `gorm:"default:200" json:"http_expect_code,omitempty"`
|
||||
HTTPExpectBody string `gorm:"type:varchar(256)" json:"http_expect_body,omitempty"`
|
||||
HTTPURL string `gorm:"type:varchar(512)" json:"http_url,omitempty"`
|
||||
HTTPMethod string `gorm:"type:varchar(10);default:GET" json:"http_method,omitempty"`
|
||||
HTTPHeaders string `gorm:"type:text" json:"http_headers,omitempty"`
|
||||
HTTPExpectCode int `gorm:"default:200" json:"http_expect_code,omitempty"`
|
||||
HTTPExpectBody string `gorm:"type:varchar(256)" json:"http_expect_body,omitempty"`
|
||||
// TCP 探针配置
|
||||
TCPHost string `gorm:"type:varchar(255)" json:"tcp_host,omitempty"`
|
||||
TCPPort int `json:"tcp_port,omitempty"`
|
||||
TCPHost string `gorm:"type:varchar(255)" json:"tcp_host,omitempty"`
|
||||
TCPPort int `json:"tcp_port,omitempty"`
|
||||
// Exec 探针配置
|
||||
ExecCommand string `gorm:"type:text" json:"exec_command,omitempty"`
|
||||
ExecCommand string `gorm:"type:text" json:"exec_command,omitempty"`
|
||||
// 通用配置
|
||||
Timeout int `gorm:"default:10" json:"timeout"`
|
||||
Interval int `gorm:"default:60" json:"interval"`
|
||||
Enabled bool `gorm:"default:true;index" json:"enabled"`
|
||||
LastStatus ProbeStatus `gorm:"type:varchar(8);default:''" json:"last_status,omitempty"`
|
||||
LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
|
||||
LastLatencyMs int `json:"last_latency_ms"`
|
||||
FailCount int `json:"fail_count"`
|
||||
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
|
||||
Timeout int `gorm:"default:10" json:"timeout"`
|
||||
Interval int `gorm:"default:60" json:"interval"`
|
||||
Enabled bool `gorm:"default:true;index" json:"enabled"`
|
||||
LastStatus ProbeStatus `gorm:"type:varchar(8);default:''" json:"last_status,omitempty"`
|
||||
LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
|
||||
LastLatencyMs int `json:"last_latency_ms"`
|
||||
FailCount int `json:"fail_count"`
|
||||
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
@@ -417,9 +417,8 @@ type HealthProbeResult struct {
|
||||
ProbeID uint `json:"probe_id"`
|
||||
Name string `json:"name"`
|
||||
ProbeType string `json:"probe_type"`
|
||||
Status ProbeStatus `json:"status"` // up / down
|
||||
LatencyMs int `json:"latency_ms"` // 响应延迟(ms)
|
||||
Status ProbeStatus `json:"status"` // up / down
|
||||
LatencyMs int `json:"latency_ms"` // 响应延迟(ms)
|
||||
StatusCode int `json:"status_code,omitempty"` // HTTP 状态码
|
||||
Message string `json:"message,omitempty"` // 错误/附加信息
|
||||
}
|
||||
|
||||
@@ -14,21 +14,21 @@ const (
|
||||
|
||||
// MonitorAlertRule 中间件/站点拨测告警规则(主机规则仍用 AgentRule)// Logan.Li
|
||||
type MonitorAlertRule struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Category MonitorAlertCategory `gorm:"type:varchar(16);not null;index" json:"category"`
|
||||
Name string `gorm:"type:varchar(128);not null" json:"name"`
|
||||
TargetID uint `gorm:"default:0;index;comment:目标ID,0=全部" json:"target_id"`
|
||||
Metric string `gorm:"type:varchar(64);not null" json:"metric"`
|
||||
Operator string `gorm:"type:varchar(8);default:>" json:"operator"`
|
||||
Threshold float64 `gorm:"type:decimal(12,4)" json:"threshold"`
|
||||
Severity string `gorm:"type:varchar(16);default:warning" json:"severity"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
DurationSec int `gorm:"default:0;comment:持续秒数(预留)" json:"duration_sec"`
|
||||
Port int `gorm:"default:0" json:"port,omitempty"`
|
||||
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
|
||||
LastTriggered *time.Time `json:"last_triggered,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Category MonitorAlertCategory `gorm:"type:varchar(16);not null;index" json:"category"`
|
||||
Name string `gorm:"type:varchar(128);not null" json:"name"`
|
||||
TargetID uint `gorm:"default:0;index;comment:目标ID,0=全部" json:"target_id"`
|
||||
Metric string `gorm:"type:varchar(64);not null" json:"metric"`
|
||||
Operator string `gorm:"type:varchar(8);default:>" json:"operator"`
|
||||
Threshold float64 `gorm:"type:decimal(12,4)" json:"threshold"`
|
||||
Severity string `gorm:"type:varchar(16);default:warning" json:"severity"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
DurationSec int `gorm:"default:0;comment:持续秒数(预留)" json:"duration_sec"`
|
||||
Port int `gorm:"default:0" json:"port,omitempty"`
|
||||
Description string `gorm:"type:varchar(256)" json:"description,omitempty"`
|
||||
LastTriggered *time.Time `json:"last_triggered,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (MonitorAlertRule) TableName() string { return "monitor_alert_rules" }
|
||||
func (MonitorAlertRule) TableName() string { return "monitor_probe_alert_rules" }
|
||||
+23
-24
@@ -2,21 +2,20 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// NavigationGroup 导航分组模型
|
||||
type NavigationGroup struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
LinkCount int `gorm:"default:0" json:"link_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
LinkCount int `gorm:"default:0" json:"link_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
@@ -26,18 +25,18 @@ func (NavigationGroup) TableName() string {
|
||||
|
||||
// NavigationLink 导航链接模型
|
||||
type NavigationLink struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
GroupID uint `json:"group_id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
URL string `gorm:"size:500;not null" json:"url"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
IsFavorite bool `gorm:"default:false" json:"is_favorite"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
GroupID uint `json:"group_id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
URL string `gorm:"size:500;not null" json:"url"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
IsFavorite bool `gorm:"default:false" json:"is_favorite"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Group *NavigationGroup `json:"group,omitempty"`
|
||||
@@ -45,7 +44,7 @@ type NavigationLink struct {
|
||||
|
||||
// TableName 表名
|
||||
func (NavigationLink) TableName() string {
|
||||
return "navigation_links"
|
||||
return "sys_navigation_links"
|
||||
}
|
||||
|
||||
// CreateNavigationGroupRequest 创建导航分组请求
|
||||
|
||||
@@ -2,83 +2,82 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// AnsiblePlaybook Playbook 模型 // Logan.Li
|
||||
type AnsiblePlaybook struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Content string `gorm:"type:text;not null" json:"content"` // YAML 内容
|
||||
Tags string `gorm:"size:500" json:"tags"` // 逗号分隔
|
||||
Category string `gorm:"size:100" json:"category"` // deployment/maintenance/etc
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Content string `gorm:"type:text;not null" json:"content"` // YAML 内容
|
||||
Tags string `gorm:"size:500" json:"tags"` // 逗号分隔
|
||||
Category string `gorm:"size:100" json:"category"` // deployment/maintenance/etc
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AnsiblePlaybook) TableName() string { return "ops_ansible_playbooks" }
|
||||
|
||||
// AnsibleJob 执行任务记录 // Logan.Li
|
||||
type AnsibleJob struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PlaybookID uint `gorm:"not null" json:"playbook_id"`
|
||||
PlaybookName string `gorm:"size:255" json:"playbook_name"`
|
||||
Status string `gorm:"size:20;default:pending" json:"status"` // pending/running/success/failed
|
||||
TargetHosts string `gorm:"type:text" json:"target_hosts"` // JSON 数组
|
||||
Variables string `gorm:"type:text" json:"variables"` // JSON
|
||||
Output string `gorm:"type:text" json:"output"`
|
||||
Duration int64 `gorm:"default:0" json:"duration"` // 毫秒
|
||||
TriggeredBy string `gorm:"size:255" json:"triggered_by"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PlaybookID uint `gorm:"not null" json:"playbook_id"`
|
||||
PlaybookName string `gorm:"size:255" json:"playbook_name"`
|
||||
Status string `gorm:"size:20;default:pending" json:"status"` // pending/running/success/failed
|
||||
TargetHosts string `gorm:"type:text" json:"target_hosts"` // JSON 数组
|
||||
Variables string `gorm:"type:text" json:"variables"` // JSON
|
||||
Output string `gorm:"type:text" json:"output"`
|
||||
Duration int64 `gorm:"default:0" json:"duration"` // 毫秒
|
||||
TriggeredBy string `gorm:"size:255" json:"triggered_by"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AnsibleJob) TableName() string { return "ops_ansible_jobs" }
|
||||
|
||||
// AnsibleInventory 主机清单 // Logan.Li
|
||||
type AnsibleInventory struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Hosts string `gorm:"type:text" json:"hosts"` // JSON 数组 [{name,ip,port,user,os}]
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Hosts string `gorm:"type:text" json:"hosts"` // JSON 数组 [{name,ip,port,user,os}]
|
||||
CreatedBy string `gorm:"size:255" json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (AnsibleInventory) TableName() string { return "ops_ansible_inventories" }
|
||||
|
||||
// LogSource 日志源 // Logan.Li
|
||||
type LogSource struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Type string `gorm:"size:50;not null" json:"type"` // application/syslog/docker/kubernetes
|
||||
Status string `gorm:"size:20;default:active" json:"status"`
|
||||
Config string `gorm:"type:text" json:"config"` // JSON {path/pattern}
|
||||
LogCount int64 `gorm:"default:0" json:"log_count"`
|
||||
LastSeen *time.Time `json:"last_seen"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Type string `gorm:"size:50;not null" json:"type"` // application/syslog/docker/kubernetes
|
||||
Status string `gorm:"size:20;default:active" json:"status"`
|
||||
Config string `gorm:"type:text" json:"config"` // JSON {path/pattern}
|
||||
LogCount int64 `gorm:"default:0" json:"log_count"`
|
||||
LastSeen *time.Time `json:"last_seen"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (LogSource) TableName() string { return "sys_log_sources" }
|
||||
|
||||
// LogEntry 日志条目 // Logan.Li
|
||||
type LogEntry struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
SourceID uint `gorm:"index" json:"source_id"`
|
||||
Timestamp time.Time `gorm:"index" json:"timestamp"`
|
||||
Level string `gorm:"size:20;index" json:"level"` // error/warn/info/debug
|
||||
Service string `gorm:"size:255;index" json:"service"`
|
||||
Host string `gorm:"size:255;index" json:"host"`
|
||||
Message string `gorm:"type:text" json:"message"`
|
||||
TraceID string `gorm:"size:100;index" json:"trace_id"`
|
||||
Raw string `gorm:"type:text" json:"raw"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
SourceID uint `gorm:"index" json:"source_id"`
|
||||
Timestamp time.Time `gorm:"index" json:"timestamp"`
|
||||
Level string `gorm:"size:20;index" json:"level"` // error/warn/info/debug
|
||||
Service string `gorm:"size:255;index" json:"service"`
|
||||
Host string `gorm:"size:255;index" json:"host"`
|
||||
Message string `gorm:"type:text" json:"message"`
|
||||
TraceID string `gorm:"size:100;index" json:"trace_id"`
|
||||
Raw string `gorm:"type:text" json:"raw"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (LogEntry) TableName() string { return "sys_log_entries" }
|
||||
@@ -12,10 +12,10 @@ type PrometheusDataSource struct {
|
||||
Access string `gorm:"type:varchar(16);default:'server';comment:访问模式: server/proxy" json:"access"`
|
||||
|
||||
// Basic Auth
|
||||
BasicAuth bool `gorm:"default:false;comment:启用基础认证" json:"basic_auth"`
|
||||
BasicAuthUser string `gorm:"type:varchar(128);comment:认证用户名" json:"basic_auth_user,omitempty"`
|
||||
BasicAuthPass string `gorm:"type:varchar(256);comment:认证密码" json:"basic_auth_pass,omitempty"`
|
||||
WithCredentials bool `gorm:"default:false;comment:携带凭证" json:"with_credentials"`
|
||||
BasicAuth bool `gorm:"default:false;comment:启用基础认证" json:"basic_auth"`
|
||||
BasicAuthUser string `gorm:"type:varchar(128);comment:认证用户名" json:"basic_auth_user,omitempty"`
|
||||
BasicAuthPass string `gorm:"type:varchar(256);comment:认证密码" json:"basic_auth_pass,omitempty"`
|
||||
WithCredentials bool `gorm:"default:false;comment:携带凭证" json:"with_credentials"`
|
||||
|
||||
// TLS Client Auth
|
||||
TLSClientAuth bool `gorm:"default:false;comment:启用TLS客户端认证" json:"tls_client_auth"`
|
||||
@@ -31,8 +31,8 @@ type PrometheusDataSource struct {
|
||||
AlertmanagerDS string `gorm:"type:varchar(128);comment:Alertmanager数据源" json:"alertmanager_ds,omitempty"`
|
||||
|
||||
// 采集与查询
|
||||
ScrapeInterval int `gorm:"default:15;comment:采集间隔(秒)" json:"scrape_interval"`
|
||||
QueryTimeout int `gorm:"default:60;comment:查询超时(秒)" json:"query_timeout"`
|
||||
ScrapeInterval int `gorm:"default:15;comment:采集间隔(秒)" json:"scrape_interval"`
|
||||
QueryTimeout int `gorm:"default:60;comment:查询超时(秒)" json:"query_timeout"`
|
||||
HTTPMethod string `gorm:"type:varchar(8);default:'POST';comment:HTTP方法" json:"http_method"`
|
||||
|
||||
// 杂项
|
||||
@@ -109,9 +109,9 @@ type UpdatePromDSReq struct {
|
||||
|
||||
// TestPromDSReq 测试数据源连接请求
|
||||
type TestPromDSReq struct {
|
||||
URL string `json:"url" binding:"required"`
|
||||
BasicAuth bool `json:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user"`
|
||||
BasicAuthPass string `json:"basic_auth_pass"`
|
||||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||||
URL string `json:"url" binding:"required"`
|
||||
BasicAuth bool `json:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user"`
|
||||
BasicAuthPass string `json:"basic_auth_pass"`
|
||||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||||
}
|
||||
@@ -25,7 +25,7 @@ type RDPSession struct {
|
||||
}
|
||||
|
||||
func (RDPSession) TableName() string {
|
||||
return "sys_rdp_sessions"
|
||||
return "audit_rdp_sessions"
|
||||
}
|
||||
|
||||
// RDPSessionQuery Windows RDP 图形会话查询 // Logan.Li
|
||||
|
||||
@@ -2,20 +2,19 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// ResourceModel 资源模型 (CMDB 模型定义)
|
||||
type ResourceModel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;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:normal" json:"type"` // normal, parent
|
||||
Attributes string `gorm:"type:text" json:"attributes"` // JSON 数组
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;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:normal" json:"type"` // normal, parent
|
||||
Attributes string `gorm:"type:text" json:"attributes"` // JSON 数组
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (ResourceModel) TableName() string {
|
||||
|
||||
+87
-78
@@ -6,40 +6,43 @@ import (
|
||||
|
||||
// Server 服务器模型
|
||||
type Server struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:128;not null" json:"hostname"`
|
||||
IP string `gorm:"size:64;not null" json:"ip"`
|
||||
PublicIP string `gorm:"size:64" json:"public_ip"`
|
||||
Port int `gorm:"default:22" json:"port"`
|
||||
Username string `gorm:"size:64;default:root" json:"username"`
|
||||
Password string `gorm:"size:255" json:"-"`
|
||||
SSHKey string `gorm:"type:text" json:"-"`
|
||||
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
|
||||
OSType string `gorm:"size:32;default:linux" json:"os_type"` // 操作系统类型:linux/windows // Logan.Li
|
||||
Protocol string `gorm:"size:32;default:ssh" json:"protocol"` // 远程协议:ssh/rdp // Logan.Li
|
||||
RDPPort int `gorm:"default:3389" json:"rdp_port"` // Windows RDP 端口 // Logan.Li
|
||||
OS string `gorm:"size:64" json:"os"`
|
||||
Kernel string `gorm:"size:64" json:"kernel"`
|
||||
OSVersion string `gorm:"size:64" json:"os_version"`
|
||||
Arch string `gorm:"size:32" json:"arch"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"` // MB
|
||||
Disk int64 `json:"disk"` // GB
|
||||
Status string `gorm:"size:32;default:stopped" json:"status"` // running, stopped, maintenance, error
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
Uptime int64 `json:"uptime"` // seconds
|
||||
AgentVersion string `gorm:"size:32" json:"agent_version"`
|
||||
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
|
||||
HasAuth bool `gorm:"-" json:"has_auth"` // 是否有认证凭据(密码或SSH密钥) — 不存DB,handler 计算后返回 // Logan.Li
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
LastCheckAt *time.Time `json:"last_check_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:128;not null" json:"hostname"`
|
||||
Alias string `gorm:"size:128" json:"alias"` // 人工可读别名,展示优先级高于 hostname // Logan.Li
|
||||
CloudInstanceName string `gorm:"size:128" json:"cloud_instance_name"` // 云平台实例名称,低于人工别名高于 hostname 展示 // Logan.Li
|
||||
CloudInstanceID string `gorm:"size:128;index" json:"cloud_instance_id"` // 云平台实例 ID,仅做关联/去重,不作为首选展示名 // Logan.Li
|
||||
IP string `gorm:"size:64;not null" json:"ip"`
|
||||
PublicIP string `gorm:"size:64" json:"public_ip"`
|
||||
Port int `gorm:"default:22" json:"port"`
|
||||
Username string `gorm:"size:64;default:root" json:"username"`
|
||||
Password string `gorm:"size:255" json:"-"`
|
||||
SSHKey string `gorm:"type:text" json:"-"`
|
||||
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
|
||||
OSType string `gorm:"size:32;default:linux" json:"os_type"` // 操作系统类型:linux/windows // Logan.Li
|
||||
Protocol string `gorm:"size:32;default:ssh" json:"protocol"` // 远程协议:ssh/rdp // Logan.Li
|
||||
RDPPort int `gorm:"default:3389" json:"rdp_port"` // Windows RDP 端口 // Logan.Li
|
||||
OS string `gorm:"size:64" json:"os"`
|
||||
Kernel string `gorm:"size:64" json:"kernel"`
|
||||
OSVersion string `gorm:"size:64" json:"os_version"`
|
||||
Arch string `gorm:"size:32" json:"arch"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"` // MB
|
||||
Disk int64 `json:"disk"` // GB
|
||||
Status string `gorm:"size:32;default:stopped" json:"status"` // running, stopped, maintenance, error
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
Uptime int64 `json:"uptime"` // seconds
|
||||
AgentVersion string `gorm:"size:32" json:"agent_version"`
|
||||
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
|
||||
HasAuth bool `gorm:"-" json:"has_auth"` // 是否有认证凭据(密码或SSH密钥) — 不存DB,handler 计算后返回 // Logan.Li
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
LastCheckAt *time.Time `json:"last_check_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Region *Region `json:"region,omitempty"`
|
||||
@@ -66,7 +69,7 @@ type Cloud struct {
|
||||
|
||||
// TableName 表名
|
||||
func (Cloud) TableName() string {
|
||||
return "asset_clouds"
|
||||
return "asset_cloud_platforms"
|
||||
}
|
||||
|
||||
// CloudAccount 云账号模型
|
||||
@@ -106,7 +109,7 @@ type Region struct {
|
||||
|
||||
// TableName 表名
|
||||
func (Region) TableName() string {
|
||||
return "asset_regions"
|
||||
return "asset_cloud_regions"
|
||||
}
|
||||
|
||||
// Domain 域名模型
|
||||
@@ -131,52 +134,58 @@ func (Domain) TableName() string {
|
||||
|
||||
// CreateServerRequest 创建服务器请求
|
||||
type CreateServerRequest struct {
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
IP string `json:"ip" binding:"required,ip"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
CredentialID *uint `json:"credential_id,omitempty"` // 关联 SSH 凭证,非空则后端解密覆盖认证字段
|
||||
OSType string `json:"os_type" binding:"omitempty,oneof=linux windows"` // 操作系统类型 // Logan.Li
|
||||
Protocol string `json:"protocol" binding:"omitempty,oneof=ssh rdp"` // 远程协议 // Logan.Li
|
||||
RDPPort int `json:"rdp_port" binding:"omitempty,min=1,max=65535"` // RDP 端口 // Logan.Li
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
Status string `json:"status" binding:"omitempty,oneof=running stopped maintenance error"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
Alias string `json:"alias"`
|
||||
CloudInstanceName string `json:"cloud_instance_name"`
|
||||
CloudInstanceID string `json:"cloud_instance_id"`
|
||||
IP string `json:"ip" binding:"required,ip"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
CredentialID *uint `json:"credential_id,omitempty"` // 关联 SSH 凭证,非空则后端解密覆盖认证字段
|
||||
OSType string `json:"os_type" binding:"omitempty,oneof=linux windows"` // 操作系统类型 // Logan.Li
|
||||
Protocol string `json:"protocol" binding:"omitempty,oneof=ssh rdp"` // 远程协议 // Logan.Li
|
||||
RDPPort int `json:"rdp_port" binding:"omitempty,min=1,max=65535"` // RDP 端口 // Logan.Li
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
Status string `json:"status" binding:"omitempty,oneof=running stopped maintenance error"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// UpdateServerRequest 更新服务器请求
|
||||
type UpdateServerRequest struct {
|
||||
Hostname string `json:"hostname"`
|
||||
IP string `json:"ip" binding:"omitempty,ip"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
CredentialID *uint `json:"credential_id,omitempty"` // 关联 SSH 凭证,非空则后端解密覆盖认证字段
|
||||
OSType string `json:"os_type" binding:"omitempty,oneof=linux windows"` // 操作系统类型 // Logan.Li
|
||||
Protocol string `json:"protocol" binding:"omitempty,oneof=ssh rdp"` // 远程协议 // Logan.Li
|
||||
RDPPort int `json:"rdp_port" binding:"omitempty,min=1,max=65535"` // RDP 端口 // Logan.Li
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
Status string `json:"status" binding:"omitempty,oneof=running stopped maintenance error"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
Hostname string `json:"hostname"`
|
||||
Alias *string `json:"alias"`
|
||||
CloudInstanceName string `json:"cloud_instance_name"`
|
||||
CloudInstanceID string `json:"cloud_instance_id"`
|
||||
IP string `json:"ip" binding:"omitempty,ip"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
CredentialID *uint `json:"credential_id,omitempty"` // 关联 SSH 凭证,非空则后端解密覆盖认证字段
|
||||
OSType string `json:"os_type" binding:"omitempty,oneof=linux windows"` // 操作系统类型 // Logan.Li
|
||||
Protocol string `json:"protocol" binding:"omitempty,oneof=ssh rdp"` // 远程协议 // Logan.Li
|
||||
RDPPort int `json:"rdp_port" binding:"omitempty,min=1,max=65535"` // RDP 端口 // Logan.Li
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
Status string `json:"status" binding:"omitempty,oneof=running stopped maintenance error"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// BatchServerItem 批量导入单条服务器 // Logan.Li
|
||||
|
||||
@@ -18,7 +18,7 @@ type SessionCommand struct {
|
||||
}
|
||||
|
||||
func (SessionCommand) TableName() string {
|
||||
return "sys_session_commands"
|
||||
return "audit_session_commands"
|
||||
}
|
||||
|
||||
// SessionCommandQuery 会话命令查询 // Logan.Li
|
||||
|
||||
@@ -4,4 +4,4 @@ package model
|
||||
type SessionCommandItem struct {
|
||||
SessionCommand
|
||||
SessionRecordSize int `gorm:"column:session_record_size" json:"session_record_size"` // 关联会话 record_size,0=无录制 // Logan.Li
|
||||
}
|
||||
}
|
||||
+95
-95
@@ -12,14 +12,14 @@ import (
|
||||
type SiteTaskType string
|
||||
|
||||
const (
|
||||
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS Web 拨测
|
||||
SiteTaskTypeSSL SiteTaskType = "ssl" // SSL/TLS 证书拨测
|
||||
SiteTaskTypeTCP SiteTaskType = "tcp" // TCP拨测
|
||||
SiteTaskTypePing SiteTaskType = "ping" // ICMP Ping拨测
|
||||
SiteTaskTypeDNS SiteTaskType = "dns" // DNS拨测
|
||||
SiteTaskTypeUDP SiteTaskType = "udp" // UDP拨测
|
||||
SiteTaskTypeFTP SiteTaskType = "ftp" // FTP拨测
|
||||
SiteTaskTypeSMTP SiteTaskType = "smtp" // SMTP拨测
|
||||
SiteTaskTypeHTTP SiteTaskType = "http" // HTTP/HTTPS Web 拨测
|
||||
SiteTaskTypeSSL SiteTaskType = "ssl" // SSL/TLS 证书拨测
|
||||
SiteTaskTypeTCP SiteTaskType = "tcp" // TCP拨测
|
||||
SiteTaskTypePing SiteTaskType = "ping" // ICMP Ping拨测
|
||||
SiteTaskTypeDNS SiteTaskType = "dns" // DNS拨测
|
||||
SiteTaskTypeUDP SiteTaskType = "udp" // UDP拨测
|
||||
SiteTaskTypeFTP SiteTaskType = "ftp" // FTP拨测
|
||||
SiteTaskTypeSMTP SiteTaskType = "smtp" // SMTP拨测
|
||||
SiteTaskTypeTraceroute SiteTaskType = "traceroute" // 路由追踪
|
||||
)
|
||||
|
||||
@@ -27,9 +27,9 @@ const (
|
||||
type SiteTaskMethod string
|
||||
|
||||
const (
|
||||
SiteTaskMethodGET SiteTaskMethod = "GET"
|
||||
SiteTaskMethodPOST SiteTaskMethod = "POST"
|
||||
SiteTaskMethodHEAD SiteTaskMethod = "HEAD"
|
||||
SiteTaskMethodGET SiteTaskMethod = "GET"
|
||||
SiteTaskMethodPOST SiteTaskMethod = "POST"
|
||||
SiteTaskMethodHEAD SiteTaskMethod = "HEAD"
|
||||
)
|
||||
|
||||
// SiteTaskStatus 拨测任务状态
|
||||
@@ -44,37 +44,37 @@ const (
|
||||
// SiteTask 站点拨测任务表
|
||||
// 定义对网站、服务等进行主动拨测的任务配置
|
||||
type SiteTask struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:任务名称" json:"name"`
|
||||
URL string `gorm:"type:varchar(512);not null;comment:拨测URL/地址" json:"url"`
|
||||
TaskType SiteTaskType `gorm:"type:varchar(16);not null;comment:拨测类型" json:"task_type"`
|
||||
Method SiteTaskMethod `gorm:"type:varchar(8);default:'GET';comment:HTTP方法" json:"method"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:任务名称" json:"name"`
|
||||
URL string `gorm:"type:varchar(512);not null;comment:拨测URL/地址" json:"url"`
|
||||
TaskType SiteTaskType `gorm:"type:varchar(16);not null;comment:拨测类型" json:"task_type"`
|
||||
Method SiteTaskMethod `gorm:"type:varchar(8);default:'GET';comment:HTTP方法" json:"method"`
|
||||
// HTTP 拨测配置
|
||||
Headers string `gorm:"type:text;comment:请求头JSON" json:"headers,omitempty"`
|
||||
Body string `gorm:"type:text;comment:请求体" json:"body,omitempty"`
|
||||
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
|
||||
FollowRedirect bool `gorm:"default:true;comment:是否跟随重定向" json:"follow_redirect"`
|
||||
VerifySSL bool `gorm:"default:true;comment:是否验证SSL证书" json:"verify_ssl"`
|
||||
Headers string `gorm:"type:text;comment:请求头JSON" json:"headers,omitempty"`
|
||||
Body string `gorm:"type:text;comment:请求体" json:"body,omitempty"`
|
||||
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
|
||||
FollowRedirect bool `gorm:"default:true;comment:是否跟随重定向" json:"follow_redirect"`
|
||||
VerifySSL bool `gorm:"default:true;comment:是否验证SSL证书" json:"verify_ssl"`
|
||||
// 期望响应配置
|
||||
ExpectedStatus int `gorm:"default:200;comment:期望状态码" json:"expected_status"`
|
||||
ExpectedContent string `gorm:"type:text;comment:期望响应内容(支持正则)" json:"expected_content,omitempty"`
|
||||
ExpectedLength int `gorm:"default:0;comment:期望响应长度(0表示不检查)" json:"expected_length"`
|
||||
// 执行配置
|
||||
Frequency int `gorm:"default:60;comment:拨测频率(秒)" json:"frequency"`
|
||||
Nodes string `gorm:"type:varchar(256);comment:执行节点列表JSON" json:"nodes,omitempty"`
|
||||
Frequency int `gorm:"default:60;comment:拨测频率(秒)" json:"frequency"`
|
||||
Nodes string `gorm:"type:varchar(256);comment:执行节点列表JSON" json:"nodes,omitempty"`
|
||||
// DNS 配置
|
||||
DNSResolver string `gorm:"type:varchar(64);comment:DNS解析服务器" json:"dns_resolver,omitempty"`
|
||||
DNSResolver string `gorm:"type:varchar(64);comment:DNS解析服务器" json:"dns_resolver,omitempty"`
|
||||
// 状态
|
||||
Status SiteTaskStatus `gorm:"type:varchar(16);default:'running';comment:任务状态" json:"status"`
|
||||
LastResult string `gorm:"type:varchar(16);comment:最近结果: success/fail" json:"last_result,omitempty"`
|
||||
LastCheckAt *time.Time `gorm:"comment:最近检查时间" json:"last_check_at,omitempty"`
|
||||
SuccessRate float64 `gorm:"type:decimal(5,2);default:100.00;comment:成功率(%)" json:"success_rate"`
|
||||
AvgResponse float64 `gorm:"comment:平均响应时间(ms)" json:"avg_response,omitempty"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
Status SiteTaskStatus `gorm:"type:varchar(16);default:'running';comment:任务状态" json:"status"`
|
||||
LastResult string `gorm:"type:varchar(16);comment:最近结果: success/fail" json:"last_result,omitempty"`
|
||||
LastCheckAt *time.Time `gorm:"comment:最近检查时间" json:"last_check_at,omitempty"`
|
||||
SuccessRate float64 `gorm:"type:decimal(5,2);default:100.00;comment:成功率(%)" json:"success_rate"`
|
||||
AvgResponse float64 `gorm:"comment:平均响应时间(ms)" json:"avg_response,omitempty"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedBy uint `gorm:"index;comment:创建人ID" json:"created_by"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联关系
|
||||
Results []SiteResult `gorm:"foreignKey:TaskID" json:"results,omitempty"`
|
||||
@@ -83,7 +83,7 @@ type SiteTask struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SiteTask) TableName() string {
|
||||
return "ops_site_tasks"
|
||||
return "monitor_site_tasks"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@@ -117,16 +117,16 @@ type SiteResult struct {
|
||||
ResponseSize int `gorm:"comment:响应大小(bytes)" json:"response_size,omitempty"`
|
||||
ResponseBody string `gorm:"type:text;comment:响应内容摘要" json:"response_body,omitempty"`
|
||||
// 网络信息
|
||||
RemoteIP string `gorm:"type:varchar(64);comment:远端IP" json:"remote_ip,omitempty"`
|
||||
LocalNode string `gorm:"type:varchar(64);comment:执行节点" json:"local_node,omitempty"`
|
||||
RemoteIP string `gorm:"type:varchar(64);comment:远端IP" json:"remote_ip,omitempty"`
|
||||
LocalNode string `gorm:"type:varchar(64);comment:执行节点" json:"local_node,omitempty"`
|
||||
// 错误信息
|
||||
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
|
||||
ErrorDetail string `gorm:"type:text;comment:错误详情" json:"error_detail,omitempty"`
|
||||
// SSL 证书信息
|
||||
SSLCertExpiry *time.Time `gorm:"comment:SSL证书过期时间" json:"ssl_cert_expiry,omitempty"`
|
||||
SSLCertIssuer string `gorm:"type:varchar(256);comment:SSL证书签发者" json:"ssl_cert_issuer,omitempty"`
|
||||
SSLCertSubject string `gorm:"type:varchar(256);comment:SSL证书主题" json:"ssl_cert_subject,omitempty"`
|
||||
SSLDaysRemaining int `gorm:"comment:SSL证书剩余天数" json:"ssl_days_remaining,omitempty"`
|
||||
SSLCertExpiry *time.Time `gorm:"comment:SSL证书过期时间" json:"ssl_cert_expiry,omitempty"`
|
||||
SSLCertIssuer string `gorm:"type:varchar(256);comment:SSL证书签发者" json:"ssl_cert_issuer,omitempty"`
|
||||
SSLCertSubject string `gorm:"type:varchar(256);comment:SSL证书主题" json:"ssl_cert_subject,omitempty"`
|
||||
SSLDaysRemaining int `gorm:"comment:SSL证书剩余天数" json:"ssl_days_remaining,omitempty"`
|
||||
// 检查内容匹配
|
||||
ContentMatch bool `gorm:"comment:内容匹配结果" json:"content_match,omitempty"`
|
||||
// 时间戳
|
||||
@@ -139,7 +139,7 @@ type SiteResult struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SiteResult) TableName() string {
|
||||
return "ops_site_results"
|
||||
return "monitor_site_results"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@@ -167,31 +167,31 @@ const (
|
||||
// SiteAlert 拨测告警表
|
||||
// 记录拨测任务触发的告警事件
|
||||
type SiteAlert struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
TaskID uint `gorm:"not null;index;comment:任务ID" json:"task_id"`
|
||||
Severity SiteAlertSeverity `gorm:"type:varchar(16);not null;comment:告警级别" json:"severity"`
|
||||
Status SiteAlertStatus `gorm:"type:varchar(16);default:'active';index;comment:告警状态" json:"status"`
|
||||
Title string `gorm:"type:varchar(256);not null;comment:告警标题" json:"title"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
TaskID uint `gorm:"not null;index;comment:任务ID" json:"task_id"`
|
||||
Severity SiteAlertSeverity `gorm:"type:varchar(16);not null;comment:告警级别" json:"severity"`
|
||||
Status SiteAlertStatus `gorm:"type:varchar(16);default:'active';index;comment:告警状态" json:"status"`
|
||||
Title string `gorm:"type:varchar(256);not null;comment:告警标题" json:"title"`
|
||||
Message string `gorm:"type:text;comment:告警详情" json:"message,omitempty"`
|
||||
// 触发条件
|
||||
TriggerType string `gorm:"type:varchar(32);comment:触发类型: timeout/status_error/response_time/ssl_expiry" json:"trigger_type"`
|
||||
TriggerValue string `gorm:"type:varchar(128);comment:触发值" json:"trigger_value,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
TriggerType string `gorm:"type:varchar(32);comment:触发类型: timeout/status_error/response_time/ssl_expiry" json:"trigger_type"`
|
||||
TriggerValue string `gorm:"type:varchar(128);comment:触发值" json:"trigger_value,omitempty"`
|
||||
Threshold float64 `gorm:"comment:阈值" json:"threshold,omitempty"`
|
||||
// 响应信息
|
||||
ResponseTime float64 `gorm:"comment:响应时间(ms)" json:"response_time,omitempty"`
|
||||
HTTPStatus int `gorm:"comment:HTTP状态码" json:"http_status,omitempty"`
|
||||
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
|
||||
ResponseTime float64 `gorm:"comment:响应时间(ms)" json:"response_time,omitempty"`
|
||||
HTTPStatus int `gorm:"comment:HTTP状态码" json:"http_status,omitempty"`
|
||||
ErrorMessage string `gorm:"type:text;comment:错误信息" json:"error_message,omitempty"`
|
||||
// 状态变化
|
||||
StartedAt time.Time `gorm:"not null;comment:告警开始时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:告警恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
StartedAt time.Time `gorm:"not null;comment:告警开始时间" json:"started_at"`
|
||||
ResolvedAt *time.Time `gorm:"comment:告警恢复时间" json:"resolved_at,omitempty"`
|
||||
Duration int `gorm:"comment:持续时间(秒)" json:"duration,omitempty"`
|
||||
NotifyCount int `gorm:"default:0;comment:通知次数" json:"notify_count"`
|
||||
LastNotifyAt *time.Time `gorm:"comment:最近通知时间" json:"last_notify_at,omitempty"`
|
||||
Acknowledged bool `gorm:"default:false;comment:是否已确认" json:"acknowledged"`
|
||||
AcknowledgedBy uint `gorm:"comment:确认人ID" json:"acknowledged_by,omitempty"`
|
||||
AcknowledgedAt *time.Time `gorm:"comment:确认时间" json:"acknowledged_at,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
|
||||
// 关联关系
|
||||
Task *SiteTask `gorm:"foreignKey:TaskID" json:"task,omitempty"`
|
||||
@@ -199,45 +199,45 @@ type SiteAlert struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SiteAlert) TableName() string {
|
||||
return "ops_site_alerts"
|
||||
return "monitor_site_alerts"
|
||||
}
|
||||
|
||||
// SiteTaskCreateRequest 拨测任务创建请求
|
||||
type SiteTaskCreateRequest struct {
|
||||
Name string `json:"name" binding:"required,max=128"`
|
||||
URL string `json:"url" binding:"required,max=512,url"`
|
||||
TaskType SiteTaskType `json:"task_type" binding:"required"`
|
||||
Method SiteTaskMethod `json:"method"`
|
||||
Headers string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
Timeout int `json:"timeout"`
|
||||
FollowRedirect bool `json:"follow_redirect"`
|
||||
VerifySSL bool `json:"verify_ssl"`
|
||||
ExpectedStatus int `json:"expected_status"`
|
||||
ExpectedContent string `json:"expected_content"`
|
||||
ExpectedLength int `json:"expected_length"`
|
||||
Frequency int `json:"frequency"`
|
||||
Nodes []string `json:"nodes"`
|
||||
DNSResolver string `json:"dns_resolver"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name" binding:"required,max=128"`
|
||||
URL string `json:"url" binding:"required,max=512,url"`
|
||||
TaskType SiteTaskType `json:"task_type" binding:"required"`
|
||||
Method SiteTaskMethod `json:"method"`
|
||||
Headers string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
Timeout int `json:"timeout"`
|
||||
FollowRedirect bool `json:"follow_redirect"`
|
||||
VerifySSL bool `json:"verify_ssl"`
|
||||
ExpectedStatus int `json:"expected_status"`
|
||||
ExpectedContent string `json:"expected_content"`
|
||||
ExpectedLength int `json:"expected_length"`
|
||||
Frequency int `json:"frequency"`
|
||||
Nodes []string `json:"nodes"`
|
||||
DNSResolver string `json:"dns_resolver"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// SiteTaskUpdateRequest 拨测任务更新请求
|
||||
type SiteTaskUpdateRequest struct {
|
||||
Name string `json:"name" binding:"max=128"`
|
||||
URL string `json:"url" binding:"max=512,url"`
|
||||
Method SiteTaskMethod `json:"method"`
|
||||
Headers string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
Timeout int `json:"timeout"`
|
||||
FollowRedirect bool `json:"follow_redirect"`
|
||||
VerifySSL bool `json:"verify_ssl"`
|
||||
ExpectedStatus int `json:"expected_status"`
|
||||
ExpectedContent string `json:"expected_content"`
|
||||
Frequency int `json:"frequency"`
|
||||
Nodes []string `json:"nodes"`
|
||||
Status SiteTaskStatus `json:"status"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name" binding:"max=128"`
|
||||
URL string `json:"url" binding:"max=512,url"`
|
||||
Method SiteTaskMethod `json:"method"`
|
||||
Headers string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
Timeout int `json:"timeout"`
|
||||
FollowRedirect bool `json:"follow_redirect"`
|
||||
VerifySSL bool `json:"verify_ssl"`
|
||||
ExpectedStatus int `json:"expected_status"`
|
||||
ExpectedContent string `json:"expected_content"`
|
||||
Frequency int `json:"frequency"`
|
||||
Nodes []string `json:"nodes"`
|
||||
Status SiteTaskStatus `json:"status"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// SiteTaskStatistics 拨测任务统计
|
||||
|
||||
+66
-66
@@ -30,9 +30,9 @@ const (
|
||||
type SNMPPrivProtocol string
|
||||
|
||||
const (
|
||||
SNMPPrivDES SNMPPrivProtocol = "DES" // DES加密
|
||||
SNMPPrivAES SNMPPrivProtocol = "AES" // AES加密
|
||||
SNMPPrivAES256 SNMPPrivProtocol = "AES256" // AES256加密
|
||||
SNMPPrivDES SNMPPrivProtocol = "DES" // DES加密
|
||||
SNMPPrivAES SNMPPrivProtocol = "AES" // AES加密
|
||||
SNMPPrivAES256 SNMPPrivProtocol = "AES256" // AES256加密
|
||||
)
|
||||
|
||||
// SNMPDeviceStatus SNMP设备状态
|
||||
@@ -47,43 +47,43 @@ const (
|
||||
// SNMPDevice SNMP设备表
|
||||
// 存储通过SNMP协议监控的网络设备信息
|
||||
type SNMPDevice struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:设备名称" json:"name"`
|
||||
IP string `gorm:"type:varchar(64);not null;index;comment:设备IP地址" json:"ip"`
|
||||
Port int `gorm:"default:161;comment:SNMP端口" json:"port"`
|
||||
Version SNMPVersion `gorm:"type:varchar(4);default:'v2c';comment:SNMP版本: v1/v2c/v3" json:"version"`
|
||||
Community string `gorm:"type:varchar(64);comment:共同体字符串(v1/v2c)" json:"community,omitempty"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:设备名称" json:"name"`
|
||||
IP string `gorm:"type:varchar(64);not null;index;comment:设备IP地址" json:"ip"`
|
||||
Port int `gorm:"default:161;comment:SNMP端口" json:"port"`
|
||||
Version SNMPVersion `gorm:"type:varchar(4);default:'v2c';comment:SNMP版本: v1/v2c/v3" json:"version"`
|
||||
Community string `gorm:"type:varchar(64);comment:共同体字符串(v1/v2c)" json:"community,omitempty"`
|
||||
// SNMP v3 安全参数
|
||||
Username string `gorm:"type:varchar(64);comment:v3用户名" json:"username,omitempty"`
|
||||
AuthProtocol SNMPAuthProtocol `gorm:"type:varchar(16);comment:v3认证协议" json:"auth_protocol,omitempty"`
|
||||
AuthPassword string `gorm:"type:varchar(128);comment:v3认证密码" json:"auth_password,omitempty"`
|
||||
PrivProtocol SNMPPrivProtocol `gorm:"type:varchar(16);comment:v3加密协议" json:"priv_protocol,omitempty"`
|
||||
PrivPassword string `gorm:"type:varchar(128);comment:v3加密密码" json:"priv_password,omitempty"`
|
||||
SecurityLevel string `gorm:"type:varchar(16);comment:v3安全级别: noAuthNoPriv/authNoPriv/authPriv" json:"security_level,omitempty"`
|
||||
Username string `gorm:"type:varchar(64);comment:v3用户名" json:"username,omitempty"`
|
||||
AuthProtocol SNMPAuthProtocol `gorm:"type:varchar(16);comment:v3认证协议" json:"auth_protocol,omitempty"`
|
||||
AuthPassword string `gorm:"type:varchar(128);comment:v3认证密码" json:"auth_password,omitempty"`
|
||||
PrivProtocol SNMPPrivProtocol `gorm:"type:varchar(16);comment:v3加密协议" json:"priv_protocol,omitempty"`
|
||||
PrivPassword string `gorm:"type:varchar(128);comment:v3加密密码" json:"priv_password,omitempty"`
|
||||
SecurityLevel string `gorm:"type:varchar(16);comment:v3安全级别: noAuthNoPriv/authNoPriv/authPriv" json:"security_level,omitempty"`
|
||||
// 设备信息
|
||||
DeviceType string `gorm:"type:varchar(64);comment:设备类型: switch/router/firewall/printer/server" json:"device_type"`
|
||||
Vendor string `gorm:"type:varchar(64);comment:厂商" json:"vendor,omitempty"`
|
||||
Model string `gorm:"type:varchar(64);comment:型号" json:"model,omitempty"`
|
||||
SysDescr string `gorm:"type:text;comment:系统描述" json:"sys_descr,omitempty"`
|
||||
SysObjectID string `gorm:"type:varchar(128);comment:系统OID" json:"sys_object_id,omitempty"`
|
||||
SysUptime uint64 `gorm:"comment:系统运行时间(百分之一秒)" json:"sys_uptime,omitempty"`
|
||||
SysContact string `gorm:"type:varchar(128);comment:系统联系人" json:"sys_contact,omitempty"`
|
||||
SysName string `gorm:"type:varchar(128);comment:系统名称" json:"sys_name,omitempty"`
|
||||
SysLocation string `gorm:"type:varchar(128);comment:系统位置" json:"sys_location,omitempty"`
|
||||
DeviceType string `gorm:"type:varchar(64);comment:设备类型: switch/router/firewall/printer/server" json:"device_type"`
|
||||
Vendor string `gorm:"type:varchar(64);comment:厂商" json:"vendor,omitempty"`
|
||||
Model string `gorm:"type:varchar(64);comment:型号" json:"model,omitempty"`
|
||||
SysDescr string `gorm:"type:text;comment:系统描述" json:"sys_descr,omitempty"`
|
||||
SysObjectID string `gorm:"type:varchar(128);comment:系统OID" json:"sys_object_id,omitempty"`
|
||||
SysUptime uint64 `gorm:"comment:系统运行时间(百分之一秒)" json:"sys_uptime,omitempty"`
|
||||
SysContact string `gorm:"type:varchar(128);comment:系统联系人" json:"sys_contact,omitempty"`
|
||||
SysName string `gorm:"type:varchar(128);comment:系统名称" json:"sys_name,omitempty"`
|
||||
SysLocation string `gorm:"type:varchar(128);comment:系统位置" json:"sys_location,omitempty"`
|
||||
// 采集配置
|
||||
TemplateID uint `gorm:"index;comment:OID模板ID" json:"template_id,omitempty"`
|
||||
CollectInterval int `gorm:"default:300;comment:采集间隔(秒)" json:"collect_interval"`
|
||||
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
|
||||
Retries int `gorm:"default:3;comment:重试次数" json:"retries"`
|
||||
MaxRepetitions uint32 `gorm:"default:25;comment:BulkWalk最大重复数" json:"max_repetitions"`
|
||||
TemplateID uint `gorm:"index;comment:OID模板ID" json:"template_id,omitempty"`
|
||||
CollectInterval int `gorm:"default:300;comment:采集间隔(秒)" json:"collect_interval"`
|
||||
Timeout int `gorm:"default:10;comment:超时时间(秒)" json:"timeout"`
|
||||
Retries int `gorm:"default:3;comment:重试次数" json:"retries"`
|
||||
MaxRepetitions uint32 `gorm:"default:25;comment:BulkWalk最大重复数" json:"max_repetitions"`
|
||||
// 状态
|
||||
Status SNMPDeviceStatus `gorm:"type:varchar(16);default:'offline';index;comment:状态" json:"status"`
|
||||
LastCollectAt *time.Time `gorm:"comment:最后采集时间" json:"last_collect_at,omitempty"`
|
||||
LastError string `gorm:"type:text;comment:最后错误信息" json:"last_error,omitempty"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
Status SNMPDeviceStatus `gorm:"type:varchar(16);default:'offline';index;comment:状态" json:"status"`
|
||||
LastCollectAt *time.Time `gorm:"comment:最后采集时间" json:"last_collect_at,omitempty"`
|
||||
LastError string `gorm:"type:text;comment:最后错误信息" json:"last_error,omitempty"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联关系
|
||||
Template *SNMPTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
|
||||
@@ -92,7 +92,7 @@ type SNMPDevice struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SNMPDevice) TableName() string {
|
||||
return "ops_snmp_devices"
|
||||
return "monitor_snmp_devices"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@@ -102,16 +102,16 @@ func (SNMPDevice) TableName() string {
|
||||
// SNMPTemplate OID模板表
|
||||
// 预定义的OID模板,用于快速配置同类设备的监控
|
||||
type SNMPTemplate struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
DeviceType string `gorm:"type:varchar(64);comment:适用设备类型" json:"device_type,omitempty"`
|
||||
Vendor string `gorm:"type:varchar(64);comment:适用厂商" json:"vendor,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
IsSystem bool `gorm:"default:false;comment:是否系统模板" json:"is_system"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:模板名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
DeviceType string `gorm:"type:varchar(64);comment:适用设备类型" json:"device_type,omitempty"`
|
||||
Vendor string `gorm:"type:varchar(64);comment:适用厂商" json:"vendor,omitempty"`
|
||||
IsDefault bool `gorm:"default:false;comment:是否默认模板" json:"is_default"`
|
||||
IsSystem bool `gorm:"default:false;comment:是否系统模板" json:"is_system"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
|
||||
// 关联关系
|
||||
@@ -120,7 +120,7 @@ type SNMPTemplate struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SNMPTemplate) TableName() string {
|
||||
return "ops_snmp_templates"
|
||||
return "monitor_snmp_templates"
|
||||
}
|
||||
|
||||
// SNMPTemplateOID OID模板条目表
|
||||
@@ -142,7 +142,7 @@ type SNMPTemplateOID struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SNMPTemplateOID) TableName() string {
|
||||
return "ops_snmp_template_oids"
|
||||
return "monitor_snmp_template_oids"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@@ -170,7 +170,7 @@ type SNMPMetric struct {
|
||||
|
||||
// TableName 指定表名
|
||||
func (SNMPMetric) TableName() string {
|
||||
return "ops_snmp_metrics"
|
||||
return "monitor_snmp_samples"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@@ -180,26 +180,26 @@ func (SNMPMetric) TableName() string {
|
||||
// SNMPInterface SNMP接口信息表
|
||||
// 存储网络设备的接口详细信息
|
||||
type SNMPInterface struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
DeviceID uint `gorm:"not null;index;comment:设备ID" json:"device_id"`
|
||||
IfIndex int `gorm:"not null;comment:接口索引" json:"if_index"`
|
||||
IfDescr string `gorm:"type:varchar(128);comment:接口描述" json:"if_descr,omitempty"`
|
||||
IfName string `gorm:"type:varchar(64);comment:接口名称" json:"if_name,omitempty"`
|
||||
IfAlias string `gorm:"type:varchar(128);comment:接口别名" json:"if_alias,omitempty"`
|
||||
IfType int `gorm:"comment:接口类型" json:"if_type,omitempty"`
|
||||
IfSpeed uint64 `gorm:"comment:接口速率(bps)" json:"if_speed,omitempty"`
|
||||
IfPhysAddr string `gorm:"type:varchar(32);comment:物理地址(MAC)" json:"if_phys_addr,omitempty"`
|
||||
IfAdminStatus int `gorm:"comment:管理状态: 1=up 2=down 3=testing" json:"if_admin_status,omitempty"`
|
||||
IfOperStatus int `gorm:"comment:操作状态: 1=up 2=down 3=testing" json:"if_oper_status,omitempty"`
|
||||
IfHighSpeed uint32 `gorm:"comment:高速接口速率(Mbps)" json:"if_high_speed,omitempty"`
|
||||
Status int `gorm:"default:1;comment:状态" json:"status"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
DeviceID uint `gorm:"not null;index;comment:设备ID" json:"device_id"`
|
||||
IfIndex int `gorm:"not null;comment:接口索引" json:"if_index"`
|
||||
IfDescr string `gorm:"type:varchar(128);comment:接口描述" json:"if_descr,omitempty"`
|
||||
IfName string `gorm:"type:varchar(64);comment:接口名称" json:"if_name,omitempty"`
|
||||
IfAlias string `gorm:"type:varchar(128);comment:接口别名" json:"if_alias,omitempty"`
|
||||
IfType int `gorm:"comment:接口类型" json:"if_type,omitempty"`
|
||||
IfSpeed uint64 `gorm:"comment:接口速率(bps)" json:"if_speed,omitempty"`
|
||||
IfPhysAddr string `gorm:"type:varchar(32);comment:物理地址(MAC)" json:"if_phys_addr,omitempty"`
|
||||
IfAdminStatus int `gorm:"comment:管理状态: 1=up 2=down 3=testing" json:"if_admin_status,omitempty"`
|
||||
IfOperStatus int `gorm:"comment:操作状态: 1=up 2=down 3=testing" json:"if_oper_status,omitempty"`
|
||||
IfHighSpeed uint32 `gorm:"comment:高速接口速率(Mbps)" json:"if_high_speed,omitempty"`
|
||||
Status int `gorm:"default:1;comment:状态" json:"status"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (SNMPInterface) TableName() string {
|
||||
return "ops_snmp_interfaces"
|
||||
return "monitor_snmp_interfaces"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
|
||||
@@ -13,4 +13,4 @@ type SystemTaskStatus struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (SystemTaskStatus) TableName() string { return "sys_system_task_status" }
|
||||
func (SystemTaskStatus) TableName() string { return "sys_system_task_statuses" }
|
||||
@@ -12,10 +12,10 @@ type TerminalSession struct {
|
||||
ServerIP string `gorm:"size:64" json:"server_ip"`
|
||||
ServerPort int `json:"server_port"`
|
||||
ClientIP string `gorm:"size:64" json:"client_ip"`
|
||||
Status string `gorm:"size:32" json:"status"` // active, closed, failed
|
||||
Duration int `json:"duration"` // seconds
|
||||
Status string `gorm:"size:32" json:"status"` // active, closed, failed
|
||||
Duration int `json:"duration"` // seconds
|
||||
RecordData string `gorm:"type:mediumtext" json:"-"` // 终端录制原始输出(asciicast v2 格式,max 16MB)
|
||||
RecordSize int `json:"record_size"` // 录制字节数
|
||||
RecordSize int `json:"record_size"` // 录制字节数
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime *time.Time `json:"end_time"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
@@ -23,18 +23,18 @@ type TerminalSession struct {
|
||||
|
||||
// TableName 表名
|
||||
func (TerminalSession) TableName() string {
|
||||
return "sys_terminal_sessions"
|
||||
return "audit_terminal_sessions"
|
||||
}
|
||||
|
||||
// TerminalSessionQuery 终端会话查询 // Logan.Li
|
||||
type TerminalSessionQuery struct {
|
||||
ServerID uint `form:"server_id"`
|
||||
Username string `form:"username"`
|
||||
Status string `form:"status"`
|
||||
Keyword string `form:"keyword"` // 模糊匹配用户/主机名/IP/客户端IP
|
||||
StartDate string `form:"start_date"` // YYYY-MM-DD
|
||||
EndDate string `form:"end_date"` // YYYY-MM-DD
|
||||
HasRecord string `form:"has_record"` // 1/true 仅含录制
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
ServerID uint `form:"server_id"`
|
||||
Username string `form:"username"`
|
||||
Status string `form:"status"`
|
||||
Keyword string `form:"keyword"` // 模糊匹配用户/主机名/IP/客户端IP
|
||||
StartDate string `form:"start_date"` // YYYY-MM-DD
|
||||
EndDate string `form:"end_date"` // YYYY-MM-DD
|
||||
HasRecord string `form:"has_record"` // 1/true 仅含录制
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
}
|
||||
+36
-37
@@ -2,22 +2,21 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
// User 用户模型
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
||||
Password string `gorm:"size:255;not null" json:"-"`
|
||||
Email string `gorm:"size:128" json:"email"`
|
||||
Phone string `gorm:"size:32" json:"phone"`
|
||||
RealName string `gorm:"size:64" json:"real_name"`
|
||||
Avatar string `gorm:"size:255" json:"avatar"`
|
||||
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
||||
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
||||
AuthSource string `gorm:"size:20;default:'local'" json:"auth_source"` // local / ldap
|
||||
LastLogin *time.Time `json:"last_login"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
||||
Password string `gorm:"size:255;not null" json:"-"`
|
||||
Email string `gorm:"size:128" json:"email"`
|
||||
Phone string `gorm:"size:32" json:"phone"`
|
||||
RealName string `gorm:"size:64" json:"real_name"`
|
||||
Avatar string `gorm:"size:255" json:"avatar"`
|
||||
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
||||
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
||||
AuthSource string `gorm:"size:20;default:'local'" json:"auth_source"` // local / ldap
|
||||
LastLogin *time.Time `json:"last_login"`
|
||||
// CI/CD Webhook 长期访问密钥(每用户仅一条,明文仅生成时返回一次)// Logan.Li
|
||||
ApiAccessKeyHash string `gorm:"size:255" json:"-"`
|
||||
ApiAccessKeyPrefix string `gorm:"size:32;index" json:"api_access_key_prefix,omitempty"`
|
||||
@@ -27,8 +26,8 @@ type User struct {
|
||||
ApiAccessKeyAt *time.Time `json:"api_access_key_at,omitempty"`
|
||||
ApiAccessKeyExpiresAt *time.Time `json:"api_access_key_expires_at,omitempty"`
|
||||
ApiAccessKeyLastUsedAt *time.Time `json:"api_access_key_last_used_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Roles []Role `gorm:"many2many:iam_user_roles;" json:"roles,omitempty"`
|
||||
@@ -41,17 +40,17 @@ func (User) TableName() string {
|
||||
|
||||
// Role 角色模型
|
||||
type Role struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
IsSystem bool `gorm:"default:false" json:"is_system"` // 系统默认角色,禁止删除
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
IsSystem bool `gorm:"default:false" json:"is_system"` // 系统默认角色,禁止删除
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
|
||||
Permissions []Permission `gorm:"many2many:iam_role_permissions;" json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
@@ -61,17 +60,17 @@ func (Role) TableName() string {
|
||||
|
||||
// Permission 权限模型
|
||||
type Permission struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
||||
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
||||
Path string `gorm:"size:255" json:"path"`
|
||||
Method string `gorm:"size:32" json:"method"`
|
||||
ParentID *uint `json:"parent_id"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
||||
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
||||
Path string `gorm:"size:255" json:"path"`
|
||||
Method string `gorm:"size:32" json:"method"`
|
||||
ParentID *uint `json:"parent_id"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
@@ -147,9 +146,9 @@ type UpdateUserRequest struct {
|
||||
|
||||
// CreateRoleRequest 创建角色请求 // Logan.Li
|
||||
type CreateRoleRequest struct {
|
||||
Name string `json:"name" binding:"required,min=1,max=64"`
|
||||
Code string `json:"code" binding:"required,min=1,max=64"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name" binding:"required,min=1,max=64"`
|
||||
Code string `json:"code" binding:"required,min=1,max=64"`
|
||||
Description string `json:"description"`
|
||||
PermissionIDs []uint `json:"permission_ids"`
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user