[BUG] method renderField in message_tpl.go will cause the alert info to generate line break error on third-party platform

Author: lpq131004Created Sep 3, 2026Updated Sep 3, 2026

Question and Steps to reproduce

These two lines of code escape all newline characters in the alert event, and then send the alert message to third-party platforms. After the third-party receives and sends the message, the newlines are displayed directly as \n instead of actual line breaks. escaped = strings.ReplaceAll(escaped, "\n", "\\n") escaped = strings.ReplaceAll(escaped, "\r", "\\r")

`func (t *MessageTemplate) renderField(key, msgTpl string, renderData map[string]interface{}) (interface{}, error) { text := strings.Join(append(GetDefs(renderData), msgTpl), "")

if t.NotifyChannelIdent == "email" {
	tpl, err := texttemplate.New(key).Funcs(tplx.TemplateFuncMap).Parse(text)
	if err != nil {
		return nil, fmt.Errorf("failed to parse template: %v", err)
	}
	var body bytes.Buffer
	if err = tpl.Execute(&body, renderData); err != nil {
		return nil, fmt.Errorf("failed to execute template: %v", err)
	}
	return body.String(), nil
}

tpl, err := template.New(key).Funcs(tplx.TemplateFuncMap).Parse(text)
if err != nil {
	return nil, fmt.Errorf("failed to parse template: %v", err)
}
var body bytes.Buffer
if err = tpl.Execute(&body, renderData); err != nil {
	return nil, fmt.Errorf("failed to execute template: %v", err)
}

escaped := strings.ReplaceAll(body.String(), `"`, `\"`)
escaped = strings.ReplaceAll(escaped, "\n", "\\n")
escaped = strings.ReplaceAll(escaped, "\r", "\\r")
if isSlackIdent(t.NotifyChannelIdent) {
	escaped = strings.ReplaceAll(escaped, "&lt;", "<")
}
return template.HTML(escaped), nil

}`

Relevant logs and configurations

平台接收到的告警: 级别状态: S3 Triggered   \n规则标题: 服务器通用告警-主机内存不足   \n规则备注: 主机 xx 内存使用率为 85.75%     \n监控指标: [cluster=xx rulename=服务器通用告警-主机内存不足]   \n触发时值: 85.75   \n首次触发时间: 2026-09-01 19:25:09   \n距离首次告警: 21h 13m 4s\n发送时间: 2026-09-02 16:38:13

Version

v9.1.1