Commit 59555fcd authored by 陈子龙's avatar 陈子龙

新增任务历史

parent b17036ed
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"` // 执行日志
}
......@@ -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
}
......@@ -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
}
......
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)
}
......@@ -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
}
......
......@@ -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")
{
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment