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 <pnair@redhat.com>
This commit is contained in:
Prashant Balachandran 2021-11-26 12:57:53 +05:30
parent 8f54fac654
commit a79a4baa1c
1 changed files with 11 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-kit/log/level"
"io/ioutil" "io/ioutil"
"net/http" "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) tmplText = notify.TmplText(n.tmpl, data, &err)
) )
var markdownIn []string var markdownIn []string
if len(n.conf.MrkdwnIn) == 0 { if len(n.conf.MrkdwnIn) == 0 {
markdownIn = []string{"fallback", "pretext", "text"} markdownIn = []string{"fallback", "pretext", "text"}
} else { } else {
markdownIn = n.conf.MrkdwnIn 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{ att := &attachment{
Title: tmplText(n.conf.Title), Title: title,
TitleLink: tmplText(n.conf.TitleLink), TitleLink: tmplText(n.conf.TitleLink),
Pretext: tmplText(n.conf.Pretext), Pretext: tmplText(n.conf.Pretext),
Text: tmplText(n.conf.Text), Text: tmplText(n.conf.Text),