Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update slack alert format #423

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions alertmanager/plugin/slack_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/samber/lo"
Expand Down Expand Up @@ -50,10 +51,10 @@ func (s *SlackWebhook) SendAlert(data *AlertPayload) error {
payload := Payload{
Blocks: []Block{
{
Type: "section",
Type: "header",
Text: &TextBlock{
Type: "mrkdwn",
Text: ":alert: " + data.Summary,
Type: "plain_text",
Text: "🚨 " + data.Summary,
},
},
{
Expand All @@ -64,19 +65,23 @@ func (s *SlackWebhook) SendAlert(data *AlertPayload) error {

// Iterate through the map to construct the remaining blocks
for key, value := range data.Details {
// Split value into sentences by period followed by space
sentences := strings.Split(value.(string), ". ")
formattedValue := fmt.Sprintf("• *%s*\n", key)

// Add a bullet point before each trimmed sentence
for _, sentence := range sentences {
trimmedSentence := strings.TrimSpace(sentence) // Trim leading and trailing spaces
if trimmedSentence != "" {
formattedValue += fmt.Sprintf("• %s.\n", trimmedSentence) // Add period back and newline
}
}
payload.Blocks = append(payload.Blocks,
Block{
Type: "header",
Text: &TextBlock{
Type: "plain_text",
Text: key,
},
},
Block{
Type: "section",
Text: &TextBlock{
Type: "plain_text",
Text: fmt.Sprintf("%v", value),
Type: "mrkdwn",
Text: formattedValue,
},
},
Block{
Expand Down