告警中心 - 新增统一告警(alert_unified)、监控告警规则(monitor_alert_rule)、指标目录(alert_metric_catalog) - 通知策略与消息分发(alert_notify_policy/dispatch/message)、静默规则 - 告警引擎按阈值/SNMP 拆分(alert_engine_monitor/snmp) 监控采集 - SNMP 常量/模板与历史指标(snmp templates/constants、snmp_metrics_history、snmp_collect) - 中间件监控 Redis 采集与种子(middleware_monitor_redis/seed) - 站点探测 pkg(siteprobe) + 站点视图(site_view) 自动化任务 - cron 调度器(cronscheduler)、脚本运行器(scriptrunner)、系统任务(systask)及运行记录(cron_job_run、system_task) 审计与凭证 - 审计设置(audit_setting) + 历史清理(auditcleaner) 前端 - 监控页面(host/middleware/site/snmp)拆分为子模块并大屏化 - 告警中心多 Tab(规则/指标目录/通知策略/静默)、任务管理组件重构、Agent CLI Markdown 渲染 - 移除旧脚本卡片/详情/日志组件,统一为 ScriptTable/ScriptCodeEditor/TerminalOutput Co-Authored-By: Claude <noreply@anthropic.com>
126 lines
5.2 KiB
Go
126 lines
5.2 KiB
Go
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"`
|
||
|
||
// 关联
|
||
Script *Script `json:"script,omitempty"`
|
||
}
|
||
|
||
// TableName 表名
|
||
func (CronJob) TableName() string {
|
||
return "ops_cron_jobs"
|
||
}
|
||
|
||
// 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"`
|
||
}
|
||
|
||
// TableName 表名
|
||
func (Script) TableName() string {
|
||
return "ops_scripts"
|
||
}
|
||
|
||
// 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"`
|
||
}
|
||
|
||
// TableName 表名
|
||
func (TaskExecution) TableName() string {
|
||
return "ops_task_executions"
|
||
}
|
||
|
||
// 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"`
|
||
}
|
||
|
||
// CreateScriptRequest 创建脚本请求
|
||
type CreateScriptRequest struct {
|
||
Name string `json:"name" binding:"required"`
|
||
Code string `json:"code"` // 为空时由 handler 自动生成 // Logan.Li
|
||
Description string `json:"description"`
|
||
Type string `json:"type" binding:"omitempty,oneof=shell python powershell command bash"`
|
||
Content string `json:"content" binding:"required"`
|
||
Params string `json:"params"`
|
||
Timeout int `json:"timeout"`
|
||
}
|
||
|
||
// ExecuteScriptRequest 执行脚本请求
|
||
type ExecuteScriptRequest struct {
|
||
TargetType string `json:"target_type" binding:"required,oneof=server group tag"`
|
||
Targets []uint `json:"targets" binding:"required"`
|
||
Params map[string]string `json:"params"`
|
||
}
|
||
|
||
// 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"`
|
||
}
|