Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Add sev to slack alerts (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrain-cb authored Sep 5, 2023
1 parent 840073f commit ca04869
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions internal/alert/interpolator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"

"github.com/base-org/pessimism/internal/core"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// TODO: add timestamp to the message
Expand All @@ -13,7 +16,7 @@ const (

// slackMsgFmt ... Slack message format
SlackMsgFmt = `
⚠️🚨 Pessimism Alert: %s 🚨⚠️
⚠️🚨%s Severity Pessimism Alert: %s 🚨⚠️
_Heuristic activation conditions met_
Expand All @@ -40,7 +43,7 @@ const (

// Interpolator ... Interface for interpolating messages
type Interpolator interface {
InterpolateSlackMessage(sUUID core.SUUID, content string, msg string) string
InterpolateSlackMessage(sev core.Severity, sUUID core.SUUID, content string, msg string) string
InterpolatePagerDutyMessage(sUUID core.SUUID, message string) string
}

Expand All @@ -53,8 +56,9 @@ func NewInterpolator() Interpolator {
}

// InterpolateSlackMessage ... Interpolates a slack message with the given heuristic session UUID and message
func (*interpolator) InterpolateSlackMessage(sUUID core.SUUID, content string, msg string) string {
func (*interpolator) InterpolateSlackMessage(sev core.Severity, sUUID core.SUUID, content string, msg string) string {
return fmt.Sprintf(SlackMsgFmt,
cases.Title(language.English).String(sev.String()),
sUUID.PID.HeuristicType().String(),
sUUID.PID.Network(),
sUUID.String(),
Expand Down
5 changes: 3 additions & 2 deletions internal/alert/interpolator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ func Test_InterpolateSlackMessage(t *testing.T) {

msg := "Friedrich Nietzsche"
content := "optimism"
sev := core.HIGH

expected := "\n\t⚠️🚨 Pessimism Alert: unknown 🚨⚠️\n\n\t_Heuristic activation conditions met_\n\n\t_Network:_ unknown\n\t_Session UUID:_ unknown:unknown:unknown::000000000\n\n\t*Assessment Content:* \n\t```optimism```\t\n\n\t*Message:*\n\tFriedrich Nietzsche\n\n\t"
expected := "\n\t⚠️🚨High Severity Pessimism Alert: unknown 🚨⚠️\n\n\t_Heuristic activation conditions met_\n\n\t_Network:_ unknown\n\t_Session UUID:_ unknown:unknown:unknown::000000000\n\n\t*Assessment Content:* \n\t```optimism```\t\n\n\t*Message:*\n\tFriedrich Nietzsche\n\n\t"

actual := alert.NewInterpolator().
InterpolateSlackMessage(sUUID, content, msg)
InterpolateSlackMessage(sev, sUUID, content, msg)

assert.Equal(t, expected, actual, "should be equal")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/alert/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (am *alertManager) handleSlackPost(alert core.Alert, policy *core.AlertPoli

// Create event trigger
event := &client.AlertEventTrigger{
Message: am.interpolator.InterpolateSlackMessage(alert.SUUID, alert.Content, policy.Msg),
Message: am.interpolator.InterpolateSlackMessage(alert.Criticality, alert.SUUID, alert.Content, policy.Msg),
Severity: alert.Criticality,
}

Expand Down

0 comments on commit ca04869

Please sign in to comment.