feat: 脚本/定时任务真实执行+输出捕获+执行历史 — 替换pending空壳为本地执行,采集stdout/stderr,更新统计;修复CronJobManager/Automation字段名不匹配(status→enabled,cron→cron_expr,command→content,language→type)
This commit is contained in:
1 parent
85bc2a8e05
commit
a4fd5fc178
19 files changed
+2715
-114
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Register 注册所有路由
|
||||
@@ -260,6 +261,9 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config) {
|
||||
scripts.POST("/:id/execute", automationHandler.ExecuteScript)
|
||||
}
|
||||
|
||||
// 任务执行记录(脚本/定时任务执行历史)
|
||||
authorized.GET("/task-executions", automationHandler.ListExecutions)
|
||||
|
||||
// 审批流程路由
|
||||
approvalHandler := handlers.NewApprovalHandler(db)
|
||||
approvals := authorized.Group("/approvals")
|
||||
@@ -306,16 +310,44 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config) {
|
||||
audit.POST("/logs/clear", auditHandler.ClearAuditLogs)
|
||||
}
|
||||
|
||||
// Agent 上报路由(无需 JWT,使用 Agent Token 鉴权)
|
||||
// Agent 上报路由(无需 JWT)
|
||||
agentHandler := handlers.NewAgentHandler(db)
|
||||
taskHandler := handlers.NewAgentTaskHandler(db)
|
||||
agentGroup := api.Group("/agent")
|
||||
{
|
||||
agentGroup.POST("/report", agentHandler.ReceiveReport)
|
||||
agentGroup.GET("/tasks/poll", taskHandler.PollTasks)
|
||||
agentGroup.POST("/tasks/:task_id/result", taskHandler.SubmitResult)
|
||||
}
|
||||
// Agent 数据查询(需要 JWT)
|
||||
// Agent 数据查询 + 任务管理(需要 JWT)
|
||||
agentQuery := authorized.Group("/agent")
|
||||
{
|
||||
agentQuery.GET("/latest", agentHandler.GetLatestReports)
|
||||
agentQuery.GET("/history/:hostname", agentHandler.GetHostHistory)
|
||||
|
||||
// 远程任务
|
||||
agentQuery.POST("/tasks", taskHandler.CreateTask)
|
||||
agentQuery.GET("/tasks", taskHandler.ListTasks)
|
||||
agentQuery.GET("/tasks/:id", taskHandler.GetTask)
|
||||
|
||||
// 告警规则
|
||||
agentQuery.GET("/rules", taskHandler.ListRules)
|
||||
agentQuery.POST("/rules", taskHandler.CreateRule)
|
||||
agentQuery.PUT("/rules/:id", taskHandler.UpdateRule)
|
||||
agentQuery.DELETE("/rules/:id", taskHandler.DeleteRule)
|
||||
|
||||
// 告警事件
|
||||
agentQuery.GET("/alerts", taskHandler.ListAlerts)
|
||||
agentQuery.POST("/alerts/:id/resolve", taskHandler.ResolveAlert)
|
||||
}
|
||||
|
||||
// 启动告警引擎(每 30 秒检查一次)
|
||||
alertEngine := handlers.NewAlertEngine(db)
|
||||
go func() {
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
alertEngine.Check()
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in new issue
Block a user