Merge pull request #45 from whoisix/master

修复任务列表下次执行时间问题,修改错别字
This commit is contained in:
George Hao
2021-05-18 00:06:40 +08:00
committed by GitHub
3 changed files with 20 additions and 9 deletions

View File

@@ -735,7 +735,7 @@ func (self *TaskController) Table() {
TaskServerIdsArr := strings.Split(v.ServerIds, ",") TaskServerIdsArr := strings.Split(v.ServerIds, ",")
serverId := 0 serverId := 0
if len(TaskServerIdsArr) > 1 { if len(TaskServerIdsArr) > 0 {
serverId, _ = strconv.Atoi(TaskServerIdsArr[0]) serverId, _ = strconv.Atoi(TaskServerIdsArr[0])
} }
jobskey := libs.JobKey(v.Id, serverId) jobskey := libs.JobKey(v.Id, serverId)

View File

@@ -222,16 +222,19 @@ func RemoteCommandJob(id int, serverId int, name string, command string, servers
jobresult.OutMsg = "" jobresult.OutMsg = ""
jobresult.ErrMsg = "" jobresult.ErrMsg = ""
jobresult.IsTimeout = false jobresult.IsTimeout = false
jobresult.IsOk = true
key, err := ioutil.ReadFile(servers.PrivateKeySrc) key, err := ioutil.ReadFile(servers.PrivateKeySrc)
if err != nil { if err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("读取私钥失败,%v", err.Error())
return return
} }
// Create the Signer for this private key. // Create the Signer for this private key.
signer, err := ssh.ParsePrivateKey(key) signer, err := ssh.ParsePrivateKey(key)
if err != nil { if err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("创建签名失败,%v", err.Error())
return return
} }
addr := fmt.Sprintf("%s:%d", servers.ServerIp, servers.Port) addr := fmt.Sprintf("%s:%d", servers.ServerIp, servers.Port)
@@ -250,6 +253,7 @@ func RemoteCommandJob(id int, serverId int, name string, command string, servers
client, err := ssh.Dial("tcp", addr, config) client, err := ssh.Dial("tcp", addr, config)
if err != nil { if err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败,%v", err.Error())
return return
} }
@@ -258,6 +262,7 @@ func RemoteCommandJob(id int, serverId int, name string, command string, servers
session, err := client.NewSession() session, err := client.NewSession()
if err != nil { if err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败,%v", err.Error())
return return
} }
defer session.Close() defer session.Close()
@@ -272,13 +277,11 @@ func RemoteCommandJob(id int, serverId int, name string, command string, servers
//session.Output(command) //session.Output(command)
if err := session.Run(command); err != nil { if err := session.Run(command); err != nil {
jobresult.ErrMsg = err.Error()
jobresult.IsOk = false jobresult.IsOk = false
return
} }
jobresult.OutMsg = b.String() jobresult.OutMsg = b.String()
jobresult.ErrMsg = c.String() jobresult.ErrMsg = c.String()
jobresult.IsOk = true
jobresult.IsTimeout = false
return return
} }
return job return job
@@ -306,6 +309,7 @@ func RemoteCommandJobByPassword(id int, serverId int, name string, command strin
jobresult.OutMsg = "" jobresult.OutMsg = ""
jobresult.ErrMsg = "" jobresult.ErrMsg = ""
jobresult.IsTimeout = false jobresult.IsTimeout = false
jobresult.IsOk = true
// get auth method // get auth method
auth = make([]ssh.AuthMethod, 0) auth = make([]ssh.AuthMethod, 0)
@@ -325,6 +329,7 @@ func RemoteCommandJobByPassword(id int, serverId int, name string, command strin
if client, err = ssh.Dial("tcp", addr, clientConfig); err != nil { if client, err = ssh.Dial("tcp", addr, clientConfig); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("连接服务器失败,%v", err.Error())
return return
} }
@@ -333,6 +338,7 @@ func RemoteCommandJobByPassword(id int, serverId int, name string, command strin
// create session // create session
if session, err = client.NewSession(); err != nil { if session, err = client.NewSession(); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("连接服务器失败,%v", err.Error())
return return
} }
@@ -343,12 +349,9 @@ func RemoteCommandJobByPassword(id int, serverId int, name string, command strin
//session.Output(command) //session.Output(command)
if err := session.Run(command); err != nil { if err := session.Run(command); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
return
} }
jobresult.OutMsg = b.String() jobresult.OutMsg = b.String()
jobresult.ErrMsg = c.String() jobresult.ErrMsg = c.String()
jobresult.IsOk = true
jobresult.IsTimeout = false
return return
} }
@@ -369,11 +372,13 @@ func RemoteCommandJobByTelnetPassword(id int, serverId int, name string, command
jobresult.OutMsg = "" jobresult.OutMsg = ""
jobresult.ErrMsg = "" jobresult.ErrMsg = ""
jobresult.IsTimeout = false jobresult.IsTimeout = false
jobresult.IsOk = true
addr := fmt.Sprintf("%s:%d", servers.ServerIp, servers.Port) addr := fmt.Sprintf("%s:%d", servers.ServerIp, servers.Port)
conn, err := gote.DialTimeout("tcp", addr, timeout) conn, err := gote.DialTimeout("tcp", addr, timeout)
if err != nil { if err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败0%v", err.Error())
return return
} }
@@ -383,26 +388,31 @@ func RemoteCommandJobByTelnetPassword(id int, serverId int, name string, command
if _, err = conn.Read(buf); err != nil { if _, err = conn.Read(buf); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-1%v", err.Error())
return return
} }
if _, err = conn.Write([]byte(servers.ServerAccount + "\r\n")); err != nil { if _, err = conn.Write([]byte(servers.ServerAccount + "\r\n")); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-2%v", err.Error())
return return
} }
if _, err = conn.Read(buf); err != nil { if _, err = conn.Read(buf); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-3%v", err.Error())
return return
} }
if _, err = conn.Write([]byte(servers.Password + "\r\n")); err != nil { if _, err = conn.Write([]byte(servers.Password + "\r\n")); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-4%v", err.Error())
return return
} }
if _, err = conn.Read(buf); err != nil { if _, err = conn.Read(buf); err != nil {
jobresult.IsOk = false jobresult.IsOk = false
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-5%v", err.Error())
return return
} }
@@ -419,6 +429,7 @@ func RemoteCommandJobByTelnetPassword(id int, serverId int, name string, command
for _, c := range commandArr { for _, c := range commandArr {
_, err = conn.Write([]byte(c + "\r\n")) _, err = conn.Write([]byte(c + "\r\n"))
if err != nil { if err != nil {
jobresult.ErrMsg = fmt.Sprintf("服务器连接失败-6%v", err.Error())
jobresult.IsOk = false jobresult.IsOk = false
return return
} }
@@ -717,7 +728,7 @@ func (j *Job) Run() {
content = strings.Replace(content, "{{TaskId}}", strconv.Itoa(j.Task.Id), -1) content = strings.Replace(content, "{{TaskId}}", strconv.Itoa(j.Task.Id), -1)
content = strings.Replace(content, "{{ServerId}}", strconv.Itoa(j.ServerId), -1) content = strings.Replace(content, "{{ServerId}}", strconv.Itoa(j.ServerId), -1)
content = strings.Replace(content, "{{TaskName}}", j.Task.TaskName, -1) content = strings.Replace(content, "{{TaskName}}", j.Task.TaskName, -1)
content = strings.Replace(content, "{{ExecuteCommand}}", j.Task.Command, -1) content = strings.Replace(content, "{{ExecuteCommand}}", strings.Replace(j.Task.Command, "\"", "\\\"", -1), -1)
content = strings.Replace(content, "{{ExecuteTime}}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1) content = strings.Replace(content, "{{ExecuteTime}}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1)
content = strings.Replace(content, "{{ProcessTime}}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1) content = strings.Replace(content, "{{ProcessTime}}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1)
content = strings.Replace(content, "{{ExecuteStatus}}", TextStatus[status], -1) content = strings.Replace(content, "{{ExecuteStatus}}", TextStatus[status], -1)

View File

@@ -331,7 +331,7 @@ ALTER TABLE `pp_task_server` ADD `connection_type` TINYINT(1) NOT NULL DEFAULT '
COMMIT; COMMIT;
BEGIN; BEGIN;
ALTER TABLE `pp_task` CHANGE COLUMN `server_id` `server_ids` varchar(200) NOT NULL DEFAULT '0' COMMENT '服务器id字符串英文都好隔开'; ALTER TABLE `pp_task` CHANGE COLUMN `server_id` `server_ids` varchar(200) NOT NULL DEFAULT '0' COMMENT '服务器id字符串英文逗号隔开';
COMMIT; COMMIT;
BEGIN; BEGIN;