Files
aiops/backend/internal/models/agent_task.go
T

72 lines
3.3 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
// 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"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentTask) TableName() string {
return "agent_tasks"
}
// 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
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"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentRule) TableName() string {
return "agent_rules"
}
// 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"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (AgentAlert) TableName() string {
return "agent_alerts"
}