1.通知模板添加错误输出变量
2.钉钉通知模板修改为自定义格式 3.更新系统默认通知模板sql
This commit is contained in:
25
jobs/job.go
25
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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(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>\r\n<p style=\"font-size:16px;\">错误输出</p>\r\n<p style=\"display:block; padding:10px; background:#efefef;border:1px solid #e4e4e4\">\r\n{{ErrorOutput}}\r\n</p>', 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;
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
{{"执行耗时 {{ProcessTime}}"}}
|
||||
{{"执行状态 {{ExecuteStatus}}"}}
|
||||
{{"任务输出 {{TaskOutput}}"}}
|
||||
{{"错误输出 {{ErrorOutput}}"}}
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
{{"执行耗时 {{ProcessTime}}"}}
|
||||
{{"执行状态 {{ExecuteStatus}}"}}
|
||||
{{"任务输出 {{TaskOutput}}"}}
|
||||
{{"错误输出 {{ErrorOutput}}"}}
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user