Skip to content

Commit

Permalink
Extracting CheckStatusToString out and improving the log message
Browse files Browse the repository at this point in the history
Also removed verbose not enabled log message for now, need to find a better way to do it
  • Loading branch information
ashwanthkumar committed Sep 6, 2016
1 parent de1f715 commit 92e10fb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
5 changes: 2 additions & 3 deletions alert-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ func (a *AlertManager) processCheck(check checks.AppCheck) {
keyPrefix := a.keyPrefix(check)
delete(a.AlertCount, keyPrefix)
}
} else {
fmt.Printf("Monitoring disabled for %s via alerts.enabled label in app config\n", check.App)
}
// TODO - Add a log message that runs only once per every new app / if app state has changed
}

func (a *AlertManager) checkForRouteWithCheckLevel(level checks.CheckStatus, allRoutes []routes.Route) bool {
Expand All @@ -138,7 +137,7 @@ func (a *AlertManager) checkForRouteWithCheckLevel(level checks.CheckStatus, all
}

func (a *AlertManager) notifyCheck(check checks.AppCheck, allRoutes []routes.Route) {
fmt.Printf("[NotifyCheck] Check: %s, Reason: %s ", check.CheckName, check.Message)
fmt.Printf("[NotifyCheck] App: %s, Result: %s, Check: %s, Reason: %s \n", check.App, checks.CheckStatusToString(check.Result), check.CheckName, check.Message)
for _, route := range allRoutes {
if route.Match(check) {
for _, notifier := range a.Notifiers {
Expand Down
16 changes: 16 additions & 0 deletions checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ const (
)

var CheckLevels = [...]CheckStatus{Warning, Critical}

func CheckStatusToString(result CheckStatus) string {
value := "Unknown"
switch result {
case Pass:
value = "Passed"
case Resolved:
value = "Resolved"
case Warning:
value = "Warning"
case Critical:
value = "Critical"
}

return value
}
15 changes: 15 additions & 0 deletions checks/checks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package checks

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestResultToString(t *testing.T) {
assert.Equal(t, "Passed", CheckStatusToString(Pass))
assert.Equal(t, "Warning", CheckStatusToString(Warning))
assert.Equal(t, "Critical", CheckStatusToString(Critical))
assert.Equal(t, "Resolved", CheckStatusToString(Resolved))
assert.Equal(t, "Unknown", CheckStatusToString(127))
}
18 changes: 1 addition & 17 deletions notifiers/slack-notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *Slack) Notify(check checks.AppCheck) {
attachment.
AddField(slack.Field{Title: "App", Value: check.App, Short: true}).
AddField(slack.Field{Title: "Check", Value: check.CheckName, Short: true}).
AddField(slack.Field{Title: "Result", Value: s.resultToString(check.Result), Short: true}).
AddField(slack.Field{Title: "Result", Value: checks.CheckStatusToString(check.Result), Short: true}).
AddField(slack.Field{Title: "Times", Value: fmt.Sprintf("%d", check.Times), Short: true})

destination := maps.GetString(check.Labels, "alerts.slack.channel", s.Channel)
Expand Down Expand Up @@ -78,22 +78,6 @@ func (s *Slack) resultToColor(result checks.CheckStatus) *string {
return &color
}

func (s *Slack) resultToString(result checks.CheckStatus) string {
value := "Unknown"
switch result {
case checks.Pass:
value = "Passed"
case checks.Resolved:
value = "Resolved"
case checks.Warning:
value = "Warning"
case checks.Critical:
value = "Critical"
}

return value
}

func (s *Slack) parseOwners(owners []string) string {
parsedOwners := []string{}
for _, owner := range owners {
Expand Down
9 changes: 0 additions & 9 deletions notifiers/slack-notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,3 @@ func TestResultToColor(t *testing.T) {
assert.Equal(t, "danger", *slack.resultToColor(checks.Critical))
assert.Equal(t, "black", *slack.resultToColor(127))
}

func TestResultToString(t *testing.T) {
slack := Slack{}
assert.Equal(t, "Passed", slack.resultToString(checks.Pass))
assert.Equal(t, "Warning", slack.resultToString(checks.Warning))
assert.Equal(t, "Critical", slack.resultToString(checks.Critical))
assert.Equal(t, "Resolved", slack.resultToString(checks.Resolved))
assert.Equal(t, "Unknown", slack.resultToString(127))
}

0 comments on commit 92e10fb

Please sign in to comment.