chore: 统一本地服务器与远程仓库源码
- 合并 main 与 master 历史并以服务器结构为基线 - 保留迁移、数据保留、AWS 账单与部署安全能力 - 建立 SDD 规格和 CI 验证闭环
This commit is contained in:
commit
fd60361d93
460 files changed
+37492
-23871
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"ezops/middleware"
|
||||
"ezops/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -25,7 +26,7 @@ func NewAgentTaskHandler(db *gorm.DB) *AgentTaskHandler {
|
||||
func (h *AgentTaskHandler) CreateTask(c *gin.Context) {
|
||||
var req struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Type string `json:"type"` // command / script
|
||||
Type string `json:"type"` // command / script
|
||||
Command string `json:"command"`
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
@@ -47,12 +48,12 @@ func (h *AgentTaskHandler) CreateTask(c *gin.Context) {
|
||||
username, _ := c.Get("username")
|
||||
|
||||
task := model.AgentTask{
|
||||
TaskID: uuid.New().String(),
|
||||
Hostname: req.Hostname,
|
||||
Type: req.Type,
|
||||
Command: req.Command,
|
||||
Timeout: req.Timeout,
|
||||
Status: "pending",
|
||||
TaskID: uuid.New().String(),
|
||||
Hostname: req.Hostname,
|
||||
Type: req.Type,
|
||||
Command: req.Command,
|
||||
Timeout: req.Timeout,
|
||||
Status: "pending",
|
||||
CreatedBy: fmt.Sprintf("%v", username),
|
||||
}
|
||||
|
||||
@@ -72,6 +73,9 @@ func (h *AgentTaskHandler) PollTasks(c *gin.Context) {
|
||||
c.JSON(400, model.Response{Code: 400, Message: "hostname 不能为空"})
|
||||
return
|
||||
}
|
||||
if !middleware.RequireAgentHostname(c, hostname) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查找该主机 pending 的任务,按时间排序,最多取 5 个
|
||||
var tasks []model.AgentTask
|
||||
@@ -94,6 +98,14 @@ func (h *AgentTaskHandler) PollTasks(c *gin.Context) {
|
||||
// POST /api/v1/agent/tasks/:task_id/result
|
||||
func (h *AgentTaskHandler) SubmitResult(c *gin.Context) {
|
||||
taskID := c.Param("task_id")
|
||||
var task model.AgentTask
|
||||
if err := h.db.Where("task_id = ?", taskID).Take(&task).Error; err != nil {
|
||||
c.JSON(404, model.Response{Code: 404, Message: "任务不存在"})
|
||||
return
|
||||
}
|
||||
if !middleware.RequireAgentHostname(c, task.Hostname) {
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
ExitCode int `json:"exit_code"`
|
||||
@@ -167,9 +179,9 @@ func (h *AgentTaskHandler) QuickSetupRules(c *gin.Context) {
|
||||
Pluck("hostname", &onlineHosts)
|
||||
|
||||
if len(onlineHosts) == 0 {
|
||||
// 如果没有在线主机,尝试从 agent_reports 中获取最近 3 分钟活跃的主机名
|
||||
// 如果没有在线主机,使用 UTC 边界从 Agent 报告中查找最近 3 分钟活跃主机。 // Logan.Li
|
||||
h.db.Model(&model.AgentReport{}).
|
||||
Where("report_time >= ?", time.Now().Add(-3*time.Minute)).
|
||||
Where("report_time >= ?", time.Now().UTC().Add(-3*time.Minute)).
|
||||
Distinct("hostname").
|
||||
Pluck("hostname", &onlineHosts)
|
||||
}
|
||||
@@ -180,11 +192,11 @@ func (h *AgentTaskHandler) QuickSetupRules(c *gin.Context) {
|
||||
}
|
||||
|
||||
type ruleDef struct {
|
||||
Name string
|
||||
Metric string
|
||||
Operator string
|
||||
Name string
|
||||
Metric string
|
||||
Operator string
|
||||
Threshold float64
|
||||
Duration int
|
||||
Duration int
|
||||
}
|
||||
|
||||
defaultRules := []ruleDef{
|
||||
|
||||
Reference in new issue
Block a user