Skip to content

Commit

Permalink
Fix title inconsistency in slack and victorops
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinmprabhu committed Aug 16, 2019
1 parent b17e5d7 commit aa636eb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
15 changes: 7 additions & 8 deletions senders/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/karriereat/blackfriday-slack"
slackdown "github.com/karriereat/blackfriday-slack"
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders"
blackfriday "gopkg.in/russross/blackfriday.v2"
Expand Down Expand Up @@ -113,20 +113,19 @@ func (sender *Sender) buildDescription(trigger moira.TriggerData) string {

func (sender *Sender) buildTitle(events moira.NotificationEvents, trigger moira.TriggerData) string {
title := fmt.Sprintf("*%s*", events.GetSubjectState())

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

triggerURI := trigger.GetTriggerURI(sender.frontURI)
if triggerURI != "" {
title += fmt.Sprintf(" <%s|%s>", triggerURI, trigger.Name)
} else if trigger.Name != "" {
title += " " + trigger.Name
}
title += "\n"

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

title += "\n"
return title
}

Expand Down
8 changes: 4 additions & 4 deletions senders/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ some other text italic text

Convey("Print moira message with one event", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)```"
So(actual, ShouldResemble, expected)
})
Expand All @@ -133,21 +133,21 @@ some other text italic text
Convey("Print moira message with one event and message", func() {
event.Message = &message
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA). This is message```"
So(actual, ShouldResemble, expected)
})

Convey("Print moira message with one event and throttled", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event}, trigger, true)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)```\nPlease, *fix your system or tune this trigger* to generate less events."
So(actual, ShouldResemble, expected)
})

Convey("Print moira message with 6 events", func() {
actual := sender.buildMessage([]moira.NotificationEvent{event, event, event, event, event, event}, trigger, false)
expected := "*NODATA* [tag1][tag2] <http://moira.url/trigger/TriggerID|Name>\n" + slackCompatibleMD +
expected := "*NODATA* <http://moira.url/trigger/TriggerID|Name> [tag1][tag2]\n" + slackCompatibleMD +
"\n\n```\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)\n02:40: Metric = 123 (OK to NODATA)```"
So(actual, ShouldResemble, expected)
})
Expand Down
5 changes: 2 additions & 3 deletions senders/victorops/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/writeas/go-strip-markdown"
stripmd "github.com/writeas/go-strip-markdown"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders/victorops/api"
Expand Down Expand Up @@ -72,15 +72,14 @@ func (sender *Sender) getMessageType(events moira.NotificationEvents) api.Messag

func (sender *Sender) buildTitle(events moira.NotificationEvents, trigger moira.TriggerData) string {
title := string(events.GetSubjectState())
title += " " + trigger.Name

tags := trigger.GetTags()
if tags != "" {
title += " " + tags
}

title += trigger.Name
title += "\n"

return title
}

Expand Down
31 changes: 30 additions & 1 deletion senders/victorops/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/moira-alert/moira/senders/victorops/api"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/mock/moira-alert"
mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -120,3 +120,32 @@ func TestBuildCreateAlertRequest(t *testing.T) {
})
})
}

func TestBuildTitle(t *testing.T) {
sender := Sender{}
value := float64(123)

Convey("Build title test", t, func() {
event := moira.NotificationEvent{
TriggerID: "TriggerID",
Value: &value,
Timestamp: 150000000,
Metric: "Metric",
OldState: moira.StateOK,
State: moira.StateNODATA,
Message: nil,
}

trigger := moira.TriggerData{
Tags: []string{"tag1", "tag2"},
Name: "Name",
ID: "TriggerID",
}

Convey("Build title", func() {
actual := sender.buildTitle(moira.NotificationEvents{event}, trigger)
expected := "NODATA Name [tag1][tag2]\n"
So(actual, ShouldResemble, expected)
})
})
}

0 comments on commit aa636eb

Please sign in to comment.