Skip to content

Commit 7ab9da5

Browse files
committed
Add summary to msteams notification
Signed-off-by: Roman Kubů <[email protected]>
1 parent aaf9490 commit 7ab9da5

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

config/notifiers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ var (
169169
NotifierConfig: NotifierConfig{
170170
VSendResolved: true,
171171
},
172-
Title: `{{ template "msteams.default.title" . }}`,
173-
Text: `{{ template "msteams.default.text" . }}`,
172+
Title: `{{ template "msteams.default.title" . }}`,
173+
Summary: `{{ template "msteams.default.summary" . }}`,
174+
Text: `{{ template "msteams.default.text" . }}`,
174175
}
175176
)
176177

@@ -788,8 +789,9 @@ type MSTeamsConfig struct {
788789
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
789790
WebhookURL *SecretURL `yaml:"webhook_url,omitempty" json:"webhook_url,omitempty"`
790791

791-
Title string `yaml:"title,omitempty" json:"title,omitempty"`
792-
Text string `yaml:"text,omitempty" json:"text,omitempty"`
792+
Title string `yaml:"title,omitempty" json:"title,omitempty"`
793+
Summary string `yaml:"summary,omitempty" json:"summary,omitempty"`
794+
Text string `yaml:"text,omitempty" json:"text,omitempty"`
793795
}
794796

795797
func (c *MSTeamsConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {

docs/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ Microsoft Teams notifications are sent via the [Incoming Webhooks](https://learn
736736
# Message title template.
737737
[ title: <tmpl_string> | default = '{{ template "msteams.default.title" . }}' ]
738738
739+
# Message title template.
740+
[ summary: <tmpl_string> | default = '{{ template "msteams.default.summary" . }}' ]
741+
739742
# Message body template.
740743
[ text: <tmpl_string> | default = '{{ template "msteams.default.text" . }}' ]
741744

notify/msteams/msteams.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type teamsMessage struct {
5252
Context string `json:"@context"`
5353
Type string `json:"type"`
5454
Title string `json:"title"`
55+
Summary string `json:"summary"`
5556
Text string `json:"text"`
5657
ThemeColor string `json:"themeColor"`
5758
}
@@ -98,6 +99,10 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
9899
if err != nil {
99100
return false, err
100101
}
102+
summary := tmpl(n.conf.Summary)
103+
if err != nil {
104+
return false, err
105+
}
101106

102107
alerts := types.Alerts(as...)
103108
color := colorGrey
@@ -112,6 +117,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
112117
Context: "http://schema.org/extensions",
113118
Type: "MessageCard",
114119
Title: title,
120+
Summary: summary,
115121
Text: text,
116122
ThemeColor: color,
117123
}

notify/msteams/msteams_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ func TestMSTeamsTemplating(t *testing.T) {
7777
{
7878
title: "full-blown message",
7979
cfg: &config.MSTeamsConfig{
80-
Title: `{{ template "msteams.default.title" . }}`,
81-
Text: `{{ template "msteams.default.text" . }}`,
80+
Title: `{{ template "msteams.default.title" . }}`,
81+
Summary: `{{ template "msteams.default.summary" . }}`,
82+
Text: `{{ template "msteams.default.text" . }}`,
8283
},
8384
retry: false,
8485
},
@@ -89,11 +90,20 @@ func TestMSTeamsTemplating(t *testing.T) {
8990
},
9091
errMsg: "template: :1: unclosed action",
9192
},
93+
{
94+
title: "summary with templating errors",
95+
cfg: &config.MSTeamsConfig{
96+
Title: `{{ template "msteams.default.title" . }}`,
97+
Summary: "{{ ",
98+
},
99+
errMsg: "template: :1: unclosed action",
100+
},
92101
{
93102
title: "message with templating errors",
94103
cfg: &config.MSTeamsConfig{
95-
Title: `{{ template "msteams.default.title" . }}`,
96-
Text: "{{ ",
104+
Title: `{{ template "msteams.default.title" . }}`,
105+
Summary: `{{ template "msteams.default.summary" . }}`,
106+
Text: "{{ ",
97107
},
98108
errMsg: "template: :1: unclosed action",
99109
},

template/default.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Alerts Resolved:
146146
{{ end }}
147147
{{ end }}
148148

149+
{{ define "msteams.default.summary" }}{{ template "__subject" . }}{{ end }}
149150
{{ define "msteams.default.title" }}{{ template "__subject" . }}{{ end }}
150151
{{ define "msteams.default.text" }}
151152
{{ if gt (len .Alerts.Firing) 0 }}

0 commit comments

Comments
 (0)