This commit is contained in:
Logan committed 2026-07-09 14:16:56 +08:00
1 parent 0690285147
commit 5618cd2738
154 files changed
+5021 -3161

No files matched your search

+37 -38
View File
@@ -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 {