Skip to content

Commit

Permalink
minify fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kotkovkirill committed Oct 16, 2024
1 parent 7a02f13 commit 2a5444e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/services/ngalert/notifier/channels/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (sn *SlackNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
}

//logger.Info("Sending Slack API request", "url", sn.URL.String(), "data", string(b))
logger.Info("Sending Slack API request", "url", sn.URL.String(), "body", "testbody")
logger.Info("Sending Slack API request", "url", sn.URL.String(), "body", sn.minify(b))

request, err := http.NewRequestWithContext(ctx, http.MethodPost, sn.URL.String(), bytes.NewReader(b))
if err != nil {
Expand Down Expand Up @@ -351,3 +351,11 @@ func (sn *SlackNotifier) buildSlackMessage(ctx context.Context, as []*types.Aler
func (sn *SlackNotifier) SendResolved() bool {
return !sn.GetDisableResolveMessage()
}

func (sn *SlackNotifier) minify(src []byte) string {
dst := &bytes.Buffer{}
if err := json.Compact(dst, []byte(src)); err != nil {
return strings.ReplaceAll(string(src), "\n", "")
}
return dst.String()
}

0 comments on commit 2a5444e

Please sign in to comment.