From 090e2a1823a3d709160e887e241d3d98873a698f Mon Sep 17 00:00:00 2001 From: linxiaozhi Date: Tue, 19 Mar 2019 19:43:45 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=E8=B5=84=E6=BA=90=E5=88=86?= =?UTF-8?q?=E7=BB=84=E7=AD=9B=E9=80=89=202.=E9=80=9A=E7=9F=A5=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=B7=BB=E5=8A=A0=E6=89=A7=E8=A1=8C=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=8F=98=E9=87=8F=203.=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=BE=AE=E8=B0=83=204.=E6=9B=B4=E6=96=B0readme.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++++++---- controllers/server.go | 20 ++++++++++++++++++-- jobs/job.go | 18 ++++++++---------- package.sh | 39 ++++++++++++++++++++++++++++++++++++++- ppgo_job2.sql | 8 ++++---- views/notifytpl/add.html | 1 + views/notifytpl/edit.html | 1 + views/server/list.html | 9 +++++++++ 8 files changed, 93 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ffc7280..37c8514 100644 --- a/README.md +++ b/README.md @@ -53,28 +53,38 @@ V1.x版本是一个简单的定时任务管理系统,进入V1.0 :https://git - 运行 go build - 运行 ./run.sh start|stop +mac +- 运行 ./package.sh -a amd64 -p darwin -v v2.3.0 + +linux +- 运行 ./package.sh -a 386 -p linux -v v2.3.0 +- 运行 ./package.sh -a amd64 -p linux -v v2.3.0 + +windows +- 运行 ./package.sh -a amd64 -p windows -v v2.3.0 + + 方法二、直接使用 linux - 进入 https://github.com/george518/PPGo_Job/releases -- 下载 ppgo_job-linux-2.1.0.zip 并解压 +- 下载 ppgo_job-linux-2.3.0.zip 并解压 - 进入文件夹,设置好数据库(创建数据库,导入ppgo_job2.sql)和配置文件(conf/app.conf) - 运行 ./run.sh start|stop mac - 进入https://github.com/george518/PPGo_Job/releases -- 下载 ppgo_job-mac-2.1.0.zip 并解压 +- 下载 ppgo_job-mac-2.3.0.zip 并解压 - 进入文件夹,设置好数据库(创建数据库,导入ppgo_job2.sql)和配置文件(conf/app.conf) - 运行 ./run.sh start|stop windows - 进入 https://github.com/george518/PPGo_Job/releases -- 下载 ppgo_job-linux-2.1.0.zip 并解压 +- 下载 ppgo_job-windows-2.3.0.zip 并解压 - 进入文件夹,设置好数据库(创建数据库,导入ppgo_job2.sql)和配置文件(conf/app.conf) -- 运行 go build - 运行 run.bat ---- diff --git a/controllers/server.go b/controllers/server.go index f5109b7..71ef930 100644 --- a/controllers/server.go +++ b/controllers/server.go @@ -26,6 +26,7 @@ type ServerController struct { func (self *ServerController) List() { self.Data["pageTitle"] = "资源管理" + self.Data["serverGroup"] = serverGroupLists(self.serverGroups, self.userId) self.display() } @@ -368,6 +369,9 @@ func (self *ServerController) Table() { if err != nil { limit = 30 } + + serverGroupId, err := self.GetInt("serverGroupId") + serverName := strings.TrimSpace(self.GetString("serverName")) StatusText := []string{ "正常", @@ -390,16 +394,28 @@ func (self *ServerController) Table() { //查询条件 filters := make([]interface{}, 0) filters = append(filters, "status", 0) + + groupsIds := make([]int, 0) if self.userId != 1 { groups := strings.Split(self.serverGroups, ",") - groupsIds := make([]int, 0) for _, v := range groups { id, _ := strconv.Atoi(v) - groupsIds = append(groupsIds, id) + if serverGroupId > 0 { + if id == serverGroupId { + groupsIds = append(groupsIds, id) + break + } + } else { + groupsIds = append(groupsIds, id) + } } filters = append(filters, "group_id__in", groupsIds) + } else if serverGroupId > 0 { + groupsIds = append(groupsIds, serverGroupId) + filters = append(filters, "group_id__in", groupsIds) } + if serverName != "" { filters = append(filters, "server_name__icontains", serverName) } diff --git a/jobs/job.go b/jobs/job.go index 9539c43..df9f623 100644 --- a/jobs/job.go +++ b/jobs/job.go @@ -240,28 +240,24 @@ func RemoteCommandJobByTelnetPassword(id int, name string, command string, serve defer conn.Close() buf := make([]byte, 4096) - _, err = conn.Read(buf) - if err != nil { + + if _, err = conn.Read(buf); err != nil { return "", "", err, false } - _, err = conn.Write([]byte(servers.ServerAccount + "\r\n")) - if err != nil { + if _, err = conn.Write([]byte(servers.ServerAccount + "\r\n")); err != nil { return "", "", err, false } - _, err = conn.Read(buf) - if err != nil { + if _, err = conn.Read(buf); err != nil { return "", "", err, false } - _, err = conn.Write([]byte(servers.Password + "\r\n")) - if err != nil { + if _, err = conn.Write([]byte(servers.Password + "\r\n")); err != nil { return "", "", err, false } - _, err = conn.Read(buf) - if err != nil { + if _, err = conn.Read(buf); err != nil { return "", "", err, false } @@ -409,6 +405,7 @@ func (j *Job) Run() { if title != "" { title = strings.Replace(title, "{{TaskId}}", strconv.Itoa(j.task.Id), -1) title = strings.Replace(title, "{{TaskName}}", j.task.TaskName, -1) + title = strings.Replace(title, "{{ExecuteCommand}}", j.task.Command, -1) title = strings.Replace(title, "{{ExecuteTime}}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1) title = strings.Replace(title, "{{ProcessTime}}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1) title = strings.Replace(title, "{{ExecuteStatus}}", TextStatus[status], -1) @@ -418,6 +415,7 @@ func (j *Job) Run() { if content != "" { content = strings.Replace(content, "{{TaskId}}", strconv.Itoa(j.task.Id), -1) content = strings.Replace(content, "{{TaskName}}", j.task.TaskName, -1) + content = strings.Replace(content, "{{ExecuteCommand}}", j.task.Command, -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, "{{ExecuteStatus}}", TextStatus[status], -1) diff --git a/package.sh b/package.sh index 71b1147..03d50a1 100755 --- a/package.sh +++ b/package.sh @@ -43,6 +43,13 @@ SUPPORT_ARCH=(386 amd64) LDFLAGS='' # 需要打包的文件 INCLUDE_FILE=() +# linux需要打包的文件 +INCLUDE_LINUX_FILE=() +# darwin需要打包的文件 +INCLUDE_DARWIN_FILE=() +# windows需要打包的文件 +INCLUDE_WINDOWS_FILE=() + # 打包文件生成目录 PACKAGE_DIR='' # 编译文件生成目录 @@ -164,6 +171,33 @@ package_file() { for item in "${INCLUDE_FILE[@]}"; do cp -r ../${item} $1 done + + for OS in "${INPUT_OS[@]}";do + if [[ "${OS}" = "linux" ]];then + for item in "${INCLUDE_LINUX_FILE[@]}"; do + cp -r ../${item} $1 + done + elif [[ "${OS}" = "darwin" ]];then + for item in "${INCLUDE_DARWIN_FILE[@]}"; do + cp -r ../${item} $1 + done + elif [[ "${OS}" = "windows" ]];then + for item in "${INCLUDE_WINDOWS_FILE[@]}"; do + cp -r ../${item} $1 + done + fi + done +} + +package_cp_include_file() { + FILEs=$2 + if [[ "${#FILEs[@]}" = "0" ]];then + return + fi + + for item in "${FILEs[@]}"; do + cp -r ../${item} $1 + done } # 清理 @@ -184,7 +218,10 @@ run() { package_ppgo_job() { BINARY_NAME='PPGo_Job' MAIN_FILE="./main.go" - INCLUDE_FILE=("conf" "static" "views" "ppgo_job2.sql" "run.sh" "run.bat") + INCLUDE_FILE=("conf" "static" "views" "ppgo_job2.sql") + INCLUDE_LINUX_FILE=("run.sh") + INCLUDE_DARWIN_FILE=("run.sh") + INCLUDE_WINDOWS_FILE=("run.bat") run } diff --git a/ppgo_job2.sql b/ppgo_job2.sql index 35447b3..c0a462a 100644 --- a/ppgo_job2.sql +++ b/ppgo_job2.sql @@ -312,10 +312,10 @@ CREATE TABLE `pp_notify_tpl` ( -- 转存表中的数据 `pp_notify_tpl` -- BEGIN; -INSERT INTO `pp_notify_tpl` VALUES(1, 'system', '默认邮箱通知模板', 0, '定时任务异常:{{TaskName}}', 'Hello,定时任务出问题了:\r\n

任务执行详情:

\r\n

\r\n任务 ID:{{TaskId}}
\r\n任务名称:{{TaskName}}
\r\n执行时间:{{ExecuteTime}}
\r\n执行耗时:{{ProcessTime}}秒
\r\n执行状态:{{ExecuteStatus}}\r\n

\r\n

任务执行输出

\r\n

\r\n{{TaskOutput}}\r\n

', 1, 1550255030, 1, 1550338305, 1); -INSERT INTO `pp_notify_tpl` VALUES(2, 'system', '默认短信通知模板', 1, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550255030, 1, 1550338215, 1); -INSERT INTO `pp_notify_tpl` VALUES(3, 'system', '默认钉钉通知模板', 2, '', '任务执行异常详情:\r\n任务 ID:{{TaskId}}\r\n任务名称:{{TaskName}}\r\n执行时间:{{ExecuteTime}}\r\n执行耗时:{{ProcessTime}}秒\r\n执行状态:{{ExecuteStatus}}\r\n任务执行输出:\r\n{{TaskOutput}}', 1, 1550255030, 1, 1550338880, 1); -INSERT INTO `pp_notify_tpl` VALUES(4, 'system', '默认微信通知模板', 3, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550347183, 1, 1550347201, 1); +INSERT INTO `pp_notify_tpl` VALUES(1, 'system', '默认邮箱通知模板', 0, '定时任务异常:{{TaskName}}', 'Hello,定时任务出问题了:\r\n

任务执行详情:

\r\n

\r\n任务 ID:{{TaskId}}
\r\n任务名称:{{TaskName}}
\r\n执行命令:{{ExecuteCommand}}
\r\n执行时间:{{ExecuteTime}}
\r\n执行耗时:{{ProcessTime}}秒
\r\n执行状态:{{ExecuteStatus}}\r\n

\r\n

任务执行输出

\r\n

\r\n{{TaskOutput}}\r\n

', 1, 1550255030, 1, 1550338305, 1); +INSERT INTO `pp_notify_tpl` VALUES(2, 'system', '默认短信通知模板', 1, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_command\": \"{{ExecuteCommand}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550255030, 1, 1550338215, 1); +INSERT INTO `pp_notify_tpl` VALUES(3, 'system', '默认钉钉通知模板', 2, '', '任务执行异常详情:\r\n任务 ID:{{TaskId}}\r\n任务名称:{{TaskName}}\r\n执行命令:{{ExecuteCommand}}\r\n执行时间:{{ExecuteTime}}\r\n执行耗时:{{ProcessTime}}秒\r\n执行状态:{{ExecuteStatus}}\r\n任务执行输出:\r\n{{TaskOutput}}', 1, 1550255030, 1, 1550338880, 1); +INSERT INTO `pp_notify_tpl` VALUES(4, 'system', '默认微信通知模板', 3, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_command\": \"{{ExecuteCommand}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550347183, 1, 1550347201, 1); COMMIT; BEGIN; diff --git a/views/notifytpl/add.html b/views/notifytpl/add.html index 409f60b..ffc9c9b 100644 --- a/views/notifytpl/add.html +++ b/views/notifytpl/add.html @@ -41,6 +41,7 @@ {{"任务 ID {{TaskId}}"}} {{"任务名称 {{TaskName}}"}} + {{"执行命令 {{ExecuteCommand}}"}} {{"执行时间 {{ExecuteTime}}"}} {{"执行耗时 {{ProcessTime}}"}} {{"执行状态 {{ExecuteStatus}}"}} diff --git a/views/notifytpl/edit.html b/views/notifytpl/edit.html index f44d0b3..14808ec 100644 --- a/views/notifytpl/edit.html +++ b/views/notifytpl/edit.html @@ -42,6 +42,7 @@ {{"任务 ID {{TaskId}}"}} {{"任务名称 {{TaskName}}"}} + {{"执行命令 {{ExecuteCommand}}"}} {{"执行时间 {{ExecuteTime}}"}} {{"执行耗时 {{ProcessTime}}"}} {{"执行状态 {{ExecuteStatus}}"}} diff --git a/views/server/list.html b/views/server/list.html index ee7ea6a..045dd03 100644 --- a/views/server/list.html +++ b/views/server/list.html @@ -9,6 +9,14 @@
+
+ +
@@ -64,6 +72,7 @@ table.reload('listReload', { where: { serverName: $('#serverName').val(), + serverGroupId:$('#serverGroupId').val(), } }); } From 20ad39117673069608df8b44f8d5704b5739259e Mon Sep 17 00:00:00 2001 From: linxiaozhi Date: Sat, 23 Mar 2019 00:48:51 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0readme.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++----- package.sh | 11 ----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 79ddfaf..cdaba9e 100644 --- a/README.md +++ b/README.md @@ -61,14 +61,14 @@ V1.x版本是一个简单的定时任务管理系统,进入V1.0 :https://git - 运行 ./run.sh start|stop mac -- 运行 ./package.sh -a amd64 -p darwin -v v2.3.0 +- 运行 ./package.sh -a amd64 -p darwin -v v2.x.0 linux -- 运行 ./package.sh -a 386 -p linux -v v2.3.0 -- 运行 ./package.sh -a amd64 -p linux -v v2.3.0 +- 运行 ./package.sh -a 386 -p linux -v v2.x.0 +- 运行 ./package.sh -a amd64 -p linux -v v2.x.0 windows -- 运行 ./package.sh -a amd64 -p windows -v v2.3.0 +- 运行 ./package.sh -a amd64 -p windows -v v2.x.0 方法二、直接使用 @@ -90,7 +90,7 @@ mac windows - 进入 https://github.com/george518/PPGo_Job/releases -- 下载 ppgo_job-linux-2.x.0.zip 并解压 +- 下载 ppgo_job-windows-2.x.0.zip 并解压 - 进入文件夹,设置好数据库(创建数据库,导入ppgo_job2.sql)和配置文件(conf/app.conf) - 运行 run.bat diff --git a/package.sh b/package.sh index 03d50a1..f5d7dff 100755 --- a/package.sh +++ b/package.sh @@ -189,17 +189,6 @@ package_file() { done } -package_cp_include_file() { - FILEs=$2 - if [[ "${#FILEs[@]}" = "0" ]];then - return - fi - - for item in "${FILEs[@]}"; do - cp -r ../${item} $1 - done -} - # 清理 clean() { if [[ -d ${BUILD_DIR} ]];then From 141d6ce3bdab7d644cc40a1db878efe5eb8fcbf9 Mon Sep 17 00:00:00 2001 From: linxiaozhi Date: Sat, 23 Mar 2019 01:31:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?ui=20=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/admin/add.html | 4 ++-- views/admin/edit.html | 4 ++-- views/user/edit.html | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/views/admin/add.html b/views/admin/add.html index 5af1064..c28d40e 100644 --- a/views/admin/add.html +++ b/views/admin/add.html @@ -40,14 +40,14 @@
- +
- +
diff --git a/views/admin/edit.html b/views/admin/edit.html index 7277425..0de4d1f 100644 --- a/views/admin/edit.html +++ b/views/admin/edit.html @@ -35,14 +35,14 @@
- +
- +
diff --git a/views/user/edit.html b/views/user/edit.html index bf5ec6c..29d29af 100644 --- a/views/user/edit.html +++ b/views/user/edit.html @@ -36,14 +36,14 @@
- +
- +
From f1b35a9a25d15f4008b30a84a3f7818f7d113a0e Mon Sep 17 00:00:00 2001 From: linxiaozhi Date: Sat, 23 Mar 2019 03:29:17 +0800 Subject: [PATCH 4/5] =?UTF-8?q?1.=E9=80=9A=E7=9F=A5=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E8=BE=93=E5=87=BA=E5=8F=98?= =?UTF-8?q?=E9=87=8F=202.=E9=92=89=E9=92=89=E9=80=9A=E7=9F=A5=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=BF=AE=E6=94=B9=E4=B8=BA=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=203.=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=80=9A=E7=9F=A5=E6=A8=A1=E6=9D=BFsql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jobs/job.go | 25 ++++++++++++++++++++----- notify/dingtalk.go | 12 +++--------- ppgo_job2.sql | 4 ++-- views/notifytpl/add.html | 1 + views/notifytpl/edit.html | 1 + 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/jobs/job.go b/jobs/job.go index df9f623..7ab9c99 100644 --- a/jobs/job.go +++ b/jobs/job.go @@ -388,7 +388,7 @@ func (j *Job) Run() { status := log.Status + 2 - title, content := "", "" + title, content, taskOutput, errOutput := "", "", "", "" notifyTpl, err := models.NotifyTplGetById(j.task.NotifyTplId) if err != nil { @@ -402,6 +402,11 @@ func (j *Job) Run() { content = notifyTpl.Content } + taskOutput = strings.Replace(log.Output, "\n", " ", -1) + taskOutput = strings.Replace(taskOutput, "\"", "\\\"", -1) + errOutput = strings.Replace(log.Error, "\n", " ", -1) + errOutput = strings.Replace(errOutput, "\"", "\\\"", -1) + if title != "" { title = strings.Replace(title, "{{TaskId}}", strconv.Itoa(j.task.Id), -1) title = strings.Replace(title, "{{TaskName}}", j.task.TaskName, -1) @@ -409,7 +414,8 @@ func (j *Job) Run() { title = strings.Replace(title, "{{ExecuteTime}}", beego.Date(time.Unix(log.CreateTime, 0), "Y-m-d H:i:s"), -1) title = strings.Replace(title, "{{ProcessTime}}", strconv.FormatFloat(float64(log.ProcessTime)/1000, 'f', 6, 64), -1) title = strings.Replace(title, "{{ExecuteStatus}}", TextStatus[status], -1) - title = strings.Replace(title, "{{TaskOutput}}", log.Error, -1) + title = strings.Replace(title, "{{TaskOutput}}", taskOutput, -1) + title = strings.Replace(title, "{{ErrorOutput}}", errOutput, -1) } if content != "" { @@ -419,7 +425,8 @@ func (j *Job) Run() { 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, "{{ExecuteStatus}}", TextStatus[status], -1) - content = strings.Replace(content, "{{TaskOutput}}", log.Error, -1) + content = strings.Replace(content, "{{TaskOutput}}", taskOutput, -1) + content = strings.Replace(content, "{{ErrorOutput}}", errOutput, -1) } if j.task.NotifyType == 0 && toEmail != "" { @@ -444,12 +451,20 @@ func (j *Job) Run() { } } else if j.task.NotifyType == 2 && len(dingtalk) > 0 { //钉钉 - ok := notify.SendDingtalkToChan(dingtalk, content) + param := make(map[string]interface{}) + + err := json.Unmarshal([]byte(content), ¶m) + if err != nil { + fmt.Println("发送钉钉错误", err) + return + } + + ok := notify.SendDingtalkToChan(dingtalk, param) if !ok { fmt.Println("发送钉钉错误", dingtalk) } } else if j.task.NotifyType == 3 && len(wechat) > 0 { - //信息 + //微信 param := make(map[string]string) err := json.Unmarshal([]byte(content), ¶m) if err != nil { diff --git a/notify/dingtalk.go b/notify/dingtalk.go index 4675860..e68bc8a 100644 --- a/notify/dingtalk.go +++ b/notify/dingtalk.go @@ -28,7 +28,7 @@ type Text struct { type Dingtalk struct { Dingtalks map[string]string - Content string + Content map[string]interface{} } var DingtalkChan chan *Dingtalk @@ -57,7 +57,7 @@ func init() { } -func SendDingtalkToChan(dingtalks map[string]string, content string) bool { +func SendDingtalkToChan(dingtalks map[string]string, content map[string]interface{}) bool { dingTalk := &Dingtalk{ Dingtalks: dingtalks, Content: content, @@ -74,13 +74,7 @@ func SendDingtalkToChan(dingtalks map[string]string, content string) bool { func (s *Dingtalk) SendDingtalk() error { for _, v := range s.Dingtalks { - - msg := Msg{MsgType: "text"} - text := new(Text) - text.Content = s.Content - msg.Text = text - - body, err := json.Marshal(msg) + body, err := json.Marshal(s.Content) if err != nil { log.Println(err) return err diff --git a/ppgo_job2.sql b/ppgo_job2.sql index c0a462a..0104b78 100644 --- a/ppgo_job2.sql +++ b/ppgo_job2.sql @@ -312,9 +312,9 @@ CREATE TABLE `pp_notify_tpl` ( -- 转存表中的数据 `pp_notify_tpl` -- BEGIN; -INSERT INTO `pp_notify_tpl` VALUES(1, 'system', '默认邮箱通知模板', 0, '定时任务异常:{{TaskName}}', 'Hello,定时任务出问题了:\r\n

任务执行详情:

\r\n

\r\n任务 ID:{{TaskId}}
\r\n任务名称:{{TaskName}}
\r\n执行命令:{{ExecuteCommand}}
\r\n执行时间:{{ExecuteTime}}
\r\n执行耗时:{{ProcessTime}}秒
\r\n执行状态:{{ExecuteStatus}}\r\n

\r\n

任务执行输出

\r\n

\r\n{{TaskOutput}}\r\n

', 1, 1550255030, 1, 1550338305, 1); +INSERT INTO `pp_notify_tpl` VALUES(1, 'system', '默认邮箱通知模板', 0, '定时任务异常:{{TaskName}}', 'Hello,定时任务出问题了:\r\n

任务执行详情:

\r\n

\r\n任务 ID:{{TaskId}}
\r\n任务名称:{{TaskName}}
\r\n执行命令:{{ExecuteCommand}}
\r\n执行时间:{{ExecuteTime}}
\r\n执行耗时:{{ProcessTime}}秒
\r\n执行状态:{{ExecuteStatus}}\r\n

\r\n

任务执行输出

\r\n

\r\n{{TaskOutput}}\r\n

\r\n

错误输出

\r\n

\r\n{{ErrorOutput}}\r\n

', 1, 1550255030, 1, 1553282382, 1); INSERT INTO `pp_notify_tpl` VALUES(2, 'system', '默认短信通知模板', 1, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_command\": \"{{ExecuteCommand}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550255030, 1, 1550338215, 1); -INSERT INTO `pp_notify_tpl` VALUES(3, 'system', '默认钉钉通知模板', 2, '', '任务执行异常详情:\r\n任务 ID:{{TaskId}}\r\n任务名称:{{TaskName}}\r\n执行命令:{{ExecuteCommand}}\r\n执行时间:{{ExecuteTime}}\r\n执行耗时:{{ProcessTime}}秒\r\n执行状态:{{ExecuteStatus}}\r\n任务执行输出:\r\n{{TaskOutput}}', 1, 1550255030, 1, 1550338880, 1); +INSERT INTO `pp_notify_tpl` VALUES(3, 'system', '默认钉钉通知模板', 2, '', '{\r\n \"msgtype\": \"text\",\r\n \"text\": {\r\n \"content\": \"任务执行异常详情:\\n任务 ID:{{TaskId}}\\n任务名称:{{TaskName}}\\n执行命令:{{ExecuteCommand}}\\n执行时间:{{ExecuteTime}}\\n执行耗时:{{ProcessTime}}秒\\n执行状态:{{ExecuteStatus}}\\n任务执行输出:\\n{{TaskOutput}}\\n错误输出:\\n{{ErrorOutput}}\"\r\n }\r\n}', 1, 1550255030, 1, 1553282245, 1); INSERT INTO `pp_notify_tpl` VALUES(4, 'system', '默认微信通知模板', 3, '', '{\r\n \"task_id\": \"{{TaskId}}\",\r\n \"task_name\": \"{{TaskName}}\",\r\n \"execute_command\": \"{{ExecuteCommand}}\",\r\n \"execute_status\": \"{{ExecuteStatus}}\"\r\n}', 1, 1550347183, 1, 1550347201, 1); COMMIT; diff --git a/views/notifytpl/add.html b/views/notifytpl/add.html index ffc9c9b..a259f6c 100644 --- a/views/notifytpl/add.html +++ b/views/notifytpl/add.html @@ -46,6 +46,7 @@ {{"执行耗时 {{ProcessTime}}"}} {{"执行状态 {{ExecuteStatus}}"}} {{"任务输出 {{TaskOutput}}"}} + {{"错误输出 {{ErrorOutput}}"}} diff --git a/views/notifytpl/edit.html b/views/notifytpl/edit.html index 14808ec..5997ea8 100644 --- a/views/notifytpl/edit.html +++ b/views/notifytpl/edit.html @@ -47,6 +47,7 @@ {{"执行耗时 {{ProcessTime}}"}} {{"执行状态 {{ExecuteStatus}}"}} {{"任务输出 {{TaskOutput}}"}} + {{"错误输出 {{ErrorOutput}}"}} From fab467f4ec65e4b78e2b9f6b610c80110f97dba0 Mon Sep 17 00:00:00 2001 From: linxiaozhi Date: Sat, 23 Mar 2019 20:40:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E9=92=89=E9=92=89=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=A0=BC=E5=BC=8F=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/notify_tpl.go | 4 ++-- notify/dingtalk.go | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/controllers/notify_tpl.go b/controllers/notify_tpl.go index fbf1e05..95aaecb 100644 --- a/controllers/notify_tpl.go +++ b/controllers/notify_tpl.go @@ -59,7 +59,7 @@ func (self *NotifyTplController) AjaxSave() { notifyTpl.Type = models.NotifyTplTypeDefault notifyTpl.Status, _ = self.GetInt("status") - if notifyTpl.TplType == 1 || notifyTpl.TplType == 3 { + if notifyTpl.TplType == 1 || notifyTpl.TplType == 2 || notifyTpl.TplType == 3 { m := make(map[string]string) err := json.Unmarshal([]byte(notifyTpl.Content), &m) if err != nil { @@ -85,7 +85,7 @@ func (self *NotifyTplController) AjaxSave() { notifyTpl.Content = strings.TrimSpace(self.GetString("content")) notifyTpl.Status, _ = self.GetInt("status") - if notifyTpl.TplType == 1 || notifyTpl.TplType == 3 { + if notifyTpl.TplType == 1 || notifyTpl.TplType == 2 || notifyTpl.TplType == 3 { m := make(map[string]string) err := json.Unmarshal([]byte(notifyTpl.Content), &m) if err != nil { diff --git a/notify/dingtalk.go b/notify/dingtalk.go index e68bc8a..7f3e05f 100644 --- a/notify/dingtalk.go +++ b/notify/dingtalk.go @@ -17,15 +17,6 @@ import ( "bytes" ) -type Msg struct { - MsgType string `json:"msgtype"` - Text *Text `json:"text"` -} - -type Text struct { - Content string `json:"content"` -} - type Dingtalk struct { Dingtalks map[string]string Content map[string]interface{}