1.通知模板添加错误输出变量

2.钉钉通知模板修改为自定义格式
3.更新系统默认通知模板sql
This commit is contained in:
linxiaozhi
2019-03-23 03:29:17 +08:00
parent 141d6ce3bd
commit f1b35a9a25
5 changed files with 27 additions and 16 deletions

View File

@@ -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), &param)
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), &param)
if err != nil {