From a79a4baa1ce1c154461815f167373b2a508f3d95 Mon Sep 17 00:00:00 2001 From: Prashant Balachandran Date: Fri, 26 Nov 2021 12:57:53 +0530 Subject: [PATCH] adding max_alerts parameter to slack webhook config correcting the logic to trucate fields instead of dropping alerts in the slack integration Signed-off-by: Prashant Balachandran --- notify/slack/slack.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index 08dd783b..5e8d515b 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/go-kit/log/level" "io/ioutil" "net/http" @@ -92,13 +93,22 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) tmplText = notify.TmplText(n.tmpl, data, &err) ) var markdownIn []string + if len(n.conf.MrkdwnIn) == 0 { markdownIn = []string{"fallback", "pretext", "text"} } else { markdownIn = n.conf.MrkdwnIn } + title, truncated := notify.Truncate(tmplText(n.conf.Title), 1024) + if truncated { + key, err := notify.ExtractGroupKey(ctx) + if err != nil { + return false, err + } + level.Debug(n.logger).Log("msg", "Truncated title", "text", title, "key", key) + } att := &attachment{ - Title: tmplText(n.conf.Title), + Title: title, TitleLink: tmplText(n.conf.TitleLink), Pretext: tmplText(n.conf.Pretext), Text: tmplText(n.conf.Text),