mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Alerting: Add additional newlines to Microsoft Teams notification message where necessary (#36126)
Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
f2bb3faea8
commit
8fe58fc2e3
@ -30,6 +30,32 @@ Labels:
|
||||
|
||||
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
|
||||
{{ template "__text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}
|
||||
|
||||
|
||||
{{ define "__teams_text_alert_list" }}{{ range . }}
|
||||
Labels:
|
||||
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
||||
{{ end }}
|
||||
Annotations:
|
||||
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
||||
{{ end }}
|
||||
{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
|
||||
|
||||
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
|
||||
|
||||
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
|
||||
|
||||
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
|
||||
|
||||
{{ end }}
|
||||
{{ end }}{{ end }}
|
||||
|
||||
|
||||
{{ define "teams.default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
|
||||
{{ template "__teams_text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}
|
||||
|
||||
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
|
||||
{{ template "__teams_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}
|
||||
`
|
||||
|
||||
// TemplateForTestsString is the template used for unit tests and integration tests.
|
||||
@ -56,6 +82,8 @@ Labels:
|
||||
|
||||
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
|
||||
{{ template "__text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}
|
||||
|
||||
{{ define "teams.default.message" }}{{ template "default.message" . }}{{ end }}
|
||||
`
|
||||
|
||||
func templateForTests(t *testing.T) *template.Template {
|
||||
|
@ -127,6 +127,74 @@ Annotations:
|
||||
- ann1 = annv4
|
||||
Source: http://localhost/alert4
|
||||
Silence: http://localhost/grafana/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval4
|
||||
`,
|
||||
},
|
||||
{
|
||||
templateString: `{{ template "teams.default.message" .}}`,
|
||||
expected: `**Firing**
|
||||
|
||||
Labels:
|
||||
- alertname = alert1
|
||||
- lbl1 = val1
|
||||
|
||||
Annotations:
|
||||
- ann1 = annv1
|
||||
|
||||
Source: http://localhost/alert1
|
||||
|
||||
Silence: http://localhost/grafana/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval1
|
||||
|
||||
Dashboard: http://localhost/grafana/d/dbuid123
|
||||
|
||||
Panel: http://localhost/grafana/d/dbuid123?viewPanel=puid123
|
||||
|
||||
|
||||
|
||||
Labels:
|
||||
- alertname = alert1
|
||||
- lbl1 = val2
|
||||
|
||||
Annotations:
|
||||
- ann1 = annv2
|
||||
|
||||
Source: http://localhost/alert2
|
||||
|
||||
Silence: http://localhost/grafana/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval2
|
||||
|
||||
|
||||
|
||||
|
||||
**Resolved**
|
||||
|
||||
Labels:
|
||||
- alertname = alert1
|
||||
- lbl1 = val3
|
||||
|
||||
Annotations:
|
||||
- ann1 = annv3
|
||||
|
||||
Source: http://localhost/alert3
|
||||
|
||||
Silence: http://localhost/grafana/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval3
|
||||
|
||||
Dashboard: http://localhost/grafana/d/dbuid456
|
||||
|
||||
Panel: http://localhost/grafana/d/dbuid456?viewPanel=puid456
|
||||
|
||||
|
||||
|
||||
Labels:
|
||||
- alertname = alert1
|
||||
- lbl1 = val4
|
||||
|
||||
Annotations:
|
||||
- ann1 = annv4
|
||||
|
||||
Source: http://localhost/alert4
|
||||
|
||||
Silence: http://localhost/grafana/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval4
|
||||
|
||||
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func NewTeamsNotifier(model *NotificationChannelConfig, t *template.Template) (*
|
||||
Settings: model.Settings,
|
||||
}),
|
||||
URL: u,
|
||||
Message: model.Settings.Get("message").MustString(`{{ template "default.message" .}}`),
|
||||
Message: model.Settings.Get("message").MustString(`{{ template "teams.default.message" .}}`),
|
||||
log: log.New("alerting.notifier.teams"),
|
||||
tmpl: t,
|
||||
}, nil
|
||||
|
Loading…
Reference in New Issue
Block a user