Skip to content

Commit

Permalink
Merge pull request #2774 from prashbnair/issue-slack
Browse files Browse the repository at this point in the history
Truncating fields that are sent to slack
  • Loading branch information
simonpasquier authored Dec 21, 2021
2 parents 8f54fac + a79a4ba commit dcaa3a0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion notify/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/go-kit/log/level"
"io/ioutil"
"net/http"

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit dcaa3a0

Please sign in to comment.