ccfos / ccfos/nightingale

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

Open Beginner friendly
#3,371 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
13.3k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
26

Description

### 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, "<", "<")
}
return template.HTML(escaped), nil
}`

### Relevant logs and configurations

```text
平台接收到的告警: 级别状态: 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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in message_tpl.go at MessageTemplate.renderField and inspect the newline escaping applied after template execution for non-email channels. Reproduce the alert with multiline content on a third-party platform, then verify that received messages show actual line breaks while the existing email and Slack handling remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.