diff --git a/etc/sms.tpl b/etc/sms.tpl index 221116bf..429ea031 100644 --- a/etc/sms.tpl +++ b/etc/sms.tpl @@ -7,8 +7,8 @@ {{end}}监控指标:{{.Metric}} 指标标签:{{.Tags}} 当前值:{{.Value}} -报警说明:{{.Info}} +报警说明:{{.Info | unescaped}} 触发时间:{{.Etime}} -报警详情:{{.Elink}} -报警策略:{{.Slink}} -{{if .HasClaim}}认领报警:{{.Clink}}{{end}} \ No newline at end of file +报警详情:{{.Elink | urlconvert}} +报警策略:{{.Slink | urlconvert}} +{{if .HasClaim}}认领报警:{{.Clink | urlconvert}}{{end}} \ No newline at end of file diff --git a/src/modules/monapi/notify/notify.go b/src/modules/monapi/notify/notify.go index 595dbc7a..7fa9df8f 100644 --- a/src/modules/monapi/notify/notify.go +++ b/src/modules/monapi/notify/notify.go @@ -189,7 +189,10 @@ func genContent(isUpgrade bool, events []*models.Event) (string, string) { // 生成告警短信,短信和IM复用一个内容模板 fp = path.Join(file.SelfDir(), "etc", "sms.tpl") - t, err = template.ParseFiles(fp) + t, err = template.New("sms.tpl").Funcs(template.FuncMap{ + "unescaped": func(str string) interface{} { return template.HTML(str) }, + "urlconvert": func(str string) interface{} { return template.URL(str) }, + }).ParseFiles(fp) if err != nil { logger.Errorf("InternalServerError: cannot parse %s %v", fp, err) smsContent = fmt.Sprintf("InternalServerError: cannot parse %s %v", fp, err)