diff --git a/src/bean/entity/task_history.go b/src/bean/entity/task_history.go new file mode 100644 index 0000000000000000000000000000000000000000..9af4321344711915621f7e7d932672dcc6141e6c --- /dev/null +++ b/src/bean/entity/task_history.go @@ -0,0 +1,14 @@ +package entity + +import "time" + +type TaskHistory struct { + Id int `json:"id" xorm:"pk autoincr" ` // id + TaskId int `json:"task_id" xorm:"task_id"` // 任务id + ExecStartTime time.Time `json:"exec_start_time" xorm:"exec_start_time" ` // 执行开始时间 + ExecEndTime time.Time `json:"exec_end_time" xorm:"exec_end_time" ` // 执行结束时间 + CreateUser string `json:"create_user" xorm:"create_user"` // 操作人 + ExecDesc string `json:"exec_desc" xorm:"exec_desc" ` // 执行说明 + State int `json:"state" xorm:"state"` // 状态(0执行中 1成功 2失败) + ExecLog string `json:"exec_log" xorm:"exec_log"` // 执行日志 +} diff --git a/src/bean/vo/request/host_manage.go b/src/bean/vo/request/host_manage.go index 42872afb3b156a28882a5537d276037fc303e6a5..70b9d6a897acbddbac8d514ffd6b5b2eb4052f64 100644 --- a/src/bean/vo/request/host_manage.go +++ b/src/bean/vo/request/host_manage.go @@ -28,9 +28,9 @@ type DelHostManageReq struct { } type ListHostManageReq struct { - Search string `json:"search"` //关键词 - CreateDateFrom string `json:"create_date_from"` //创建时间从 - CreateDateTo string `json:"create_date_to"` //创建时间至 + Search string `json:"search" form:"search"` //关键词 + CreateDateFrom string `json:"create_date_from" form:"create_date_from"` //创建时间从 + CreateDateTo string `json:"create_date_to" form:"create_date_to"` //创建时间至 Pagination } @@ -44,8 +44,8 @@ type StateHostManageReq struct { // HostIpExceptionListReq 异常列表 type HostIpExceptionListReq struct { - DetectionType int `json:"detection_type" binding:"oneof=1 2"` //1主页异常ip列表 2保存检测时异常列表 - Id int `json:"id"` //主机分组ID - Uuid string `json:"uuid"` //临时缓存uuid + DetectionType int `json:"detection_type" form:"detection_type" binding:"oneof=1 2"` //1主页异常ip列表 2保存检测时异常列表 + Id int `json:"id" form:"id"` //主机分组ID + Uuid string `json:"uuid" form:"uuid"` //临时缓存uuid Pagination } diff --git a/src/bean/vo/request/task_history.go b/src/bean/vo/request/task_history.go new file mode 100644 index 0000000000000000000000000000000000000000..725b8fc210d39a62328ca5206e351ffd995fc29e --- /dev/null +++ b/src/bean/vo/request/task_history.go @@ -0,0 +1 @@ +package request diff --git a/src/bean/vo/response/task_history.go b/src/bean/vo/response/task_history.go new file mode 100644 index 0000000000000000000000000000000000000000..a467149d46e348a3eecd64404c7d3677b8bc7bfd --- /dev/null +++ b/src/bean/vo/response/task_history.go @@ -0,0 +1 @@ +package response diff --git a/src/controller/host_manage.go b/src/controller/host_manage.go index 6cc8e66965370c4ccb1a2f5f1b3a3c9029c0d3fd..1236760aff106f8bcb210d1051ca6743ae81384d 100644 --- a/src/controller/host_manage.go +++ b/src/controller/host_manage.go @@ -182,7 +182,7 @@ func DetailsHostManage(c *gin.Context) { // PageListHostManage 列表-分页 func PageListHostManage(c *gin.Context) { var req request.ListHostManageReq - if err := c.ShouldBindJSON(&req); err != nil { + if err := c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } @@ -276,7 +276,7 @@ func StateHostManage(c *gin.Context) { // HostIpExceptionList 主机ip异常列表 func HostIpExceptionList(c *gin.Context) { var req request.HostIpExceptionListReq - if err := c.ShouldBindJSON(&req); err != nil { + if err := c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } diff --git a/src/controller/task_history.go b/src/controller/task_history.go new file mode 100644 index 0000000000000000000000000000000000000000..c43669395723efa36ee1ed088728ff784a8ab351 --- /dev/null +++ b/src/controller/task_history.go @@ -0,0 +1,25 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" +) + +// TaskHistoryList 任务历史 +func TaskHistoryList(c *gin.Context) { + var req request.ListTaskManageReq + if err := c.ShouldBindJSON(&req); err != nil { + SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + return + } + + taskManageSvc := service.TaskManageSvc{} + total, list, err := taskManageSvc.ListTaskManage(req) + if err != nil { + SendJsonPageResponse(c, err, nil, 0) + return + } + SendJsonPageResponse(c, resp.OK, list, total) +} diff --git a/src/controller/task_manage.go b/src/controller/task_manage.go index eae8a7b8a8a186ca35f0823b7a69855ef6192d5a..39036024025a0b36bcebece9f91995a241a27014 100644 --- a/src/controller/task_manage.go +++ b/src/controller/task_manage.go @@ -103,7 +103,7 @@ func DetailsTaskManage(c *gin.Context) { // ListTaskManage 任务列表 func ListTaskManage(c *gin.Context) { var req request.ListTaskManageReq - if err := c.ShouldBindJSON(&req); err != nil { + if err := c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) return } diff --git a/src/router/automatedmaintenrouter.go b/src/router/automatedmaintenrouter.go index c9ed75e2aaedabe7158f608bedc1d32a9ec22d1a..a8bdfd3c05a5a0268af8ec10c21899998e411f1f 100644 --- a/src/router/automatedmaintenrouter.go +++ b/src/router/automatedmaintenrouter.go @@ -20,6 +20,13 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { task.GET("/list", controller.ListTaskManage) // 列表 task.POST("/exec/script", controller.ExecScript) // 立即执行 } + + //任务历史 + taskHistory := so.Group("/task_history") + { + taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史 + } + //主机管理 host := so.Group("/host_manage") { diff --git a/src/service/task_history.go b/src/service/task_history.go new file mode 100644 index 0000000000000000000000000000000000000000..6d43c3366ca3e6c323c783077e9aa02280048c57 --- /dev/null +++ b/src/service/task_history.go @@ -0,0 +1 @@ +package service diff --git a/src/service/task_manage.go b/src/service/task_manage.go index 5a2e5828446fa707a64ec95da35b1ad75fd1cd4a..f8c9c70676ace54b49abbb405cc564557599f90c 100644 --- a/src/service/task_manage.go +++ b/src/service/task_manage.go @@ -193,6 +193,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{}, } req.Value = fmt.Sprintf("@/etc/ansible/ansible_extra.yml") } + var cmd *exec.Cmd if req.Value != "" { cmd = exec.Command("ansible-playbook", "-i", "/etc/ansible/hosts", "/etc/ansible/ansible.yml", "--extra-vars", req.Value)