1.资源管理列表添加资源分组筛选
2.通知模板添加执行命令变量 3.打包脚本微调 4.更新readme.md
This commit is contained in:
18
README.md
18
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
|
||||
|
||||
----
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
18
jobs/job.go
18
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)
|
||||
|
||||
39
package.sh
39
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
|
||||
}
|
||||
|
||||
@@ -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<p style=\"font-size:16px;\">任务执行详情:</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n任务 ID:{{TaskId}}<br/>\r\n任务名称:{{TaskName}}<br/>\r\n执行时间:{{ExecuteTime}}<br/>\r\n执行耗时:{{ProcessTime}}秒<br/>\r\n执行状态:{{ExecuteStatus}}\r\n</p>\r\n<p style=\"font-size:16px;\">任务执行输出</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n{{TaskOutput}}\r\n</p>', 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<p style=\"font-size:16px;\">任务执行详情:</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n任务 ID:{{TaskId}}<br/>\r\n任务名称:{{TaskName}}<br/>\r\n执行命令:{{ExecuteCommand}}<br/>\r\n执行时间:{{ExecuteTime}}<br/>\r\n执行耗时:{{ProcessTime}}秒<br/>\r\n执行状态:{{ExecuteStatus}}\r\n</p>\r\n<p style=\"font-size:16px;\">任务执行输出</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n{{TaskOutput}}\r\n</p>', 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;
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
{{"任务 ID {{TaskId}}"}}
|
||||
{{"任务名称 {{TaskName}}"}}
|
||||
{{"执行命令 {{ExecuteCommand}}"}}
|
||||
{{"执行时间 {{ExecuteTime}}"}}
|
||||
{{"执行耗时 {{ProcessTime}}"}}
|
||||
{{"执行状态 {{ExecuteStatus}}"}}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
{{"任务 ID {{TaskId}}"}}
|
||||
{{"任务名称 {{TaskName}}"}}
|
||||
{{"执行命令 {{ExecuteCommand}}"}}
|
||||
{{"执行时间 {{ExecuteTime}}"}}
|
||||
{{"执行耗时 {{ProcessTime}}"}}
|
||||
{{"执行状态 {{ExecuteStatus}}"}}
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
<div class="layui-inline" style="width: 40%">
|
||||
<input class="layui-input" name="serverName" id="serverName" autocomplete="off" placeholder="资源名称" >
|
||||
</div>
|
||||
<div class="layui-inline" style="width: 20%;text-align: left;">
|
||||
<select name="serverGroupId" id="serverGroupId">
|
||||
<option value="0">全部</option>
|
||||
{{range $k, $v := .serverGroup}}
|
||||
<option value="{{$k}}">{{$v}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<button class="layui-btn" data-type="reload">查询</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -64,6 +72,7 @@
|
||||
table.reload('listReload', {
|
||||
where: {
|
||||
serverName: $('#serverName').val(),
|
||||
serverGroupId:$('#serverGroupId').val(),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user