Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1c12af8
GRAPHITE_BASE -> GraphiteBase
thraxil Jul 29, 2017
ac3b432
email_to -> emailTo
thraxil Jul 29, 2017
a519e3f
CARBON_BASE -> CarbonBase
thraxil Jul 29, 2017
3250d89
METRIC_BASE -> MetricBase
thraxil Jul 29, 2017
fdd2029
EMAIL_FROM -> EmailFrom
thraxil Jul 29, 2017
ee08be7
EMAIL_TO -> EmailTo
thraxil Jul 29, 2017
a0a614c
CHECK_INTERVAL -> CheckInterval
thraxil Jul 29, 2017
956b06d
GLOBAL_THROTTLE -> GlobalThrottle
thraxil Jul 29, 2017
b59c4a4
LAST_ERROR_EMAIL -> LastErrorEmail
thraxil Jul 29, 2017
6f7af4b
EMAIL_ON_ERROR -> EmailOnError
thraxil Jul 29, 2017
b088cf4
SMTP_SERVER -> SMTPServer
thraxil Jul 29, 2017
836c47e
SMTP_PORT -> SMTPPort
thraxil Jul 29, 2017
7045e8c
SMTP_USER -> SMTPUser
thraxil Jul 29, 2017
68e4d53
SMTP_PASSWORD -> SMTPPassword
thraxil Jul 29, 2017
5e612e6
WINDOW -> Window
thraxil Jul 29, 2017
02350d2
GLOBAL_BACKOFF -> GlobalBackoff
thraxil Jul 29, 2017
9d09f57
EXP_FAILED -> ExpFailed
thraxil Jul 29, 2017
00dd7ac
EXP_PASSED -> ExpPassed
thraxil Jul 29, 2017
91d116d
EXP_ERRORS -> ExpErrors
thraxil Jul 29, 2017
74af32e
EXP_GLOBAL_THROTTLE -> ExpGlobalThrottle
thraxil Jul 29, 2017
57f15dd
EXP_GLOBAL_BACKOFF -> ExpGlobalBackoff
thraxil Jul 29, 2017
29b717d
EXP_UPTIME -> ExpUptime
thraxil Jul 29, 2017
1f4df4a
global_throttle -> globalThrottle
thraxil Jul 29, 2017
c4cd956
recoveries_sent -> recoveriesSent
thraxil Jul 29, 2017
9f81779
don't export SMTPEmailer
thraxil Jul 29, 2017
5b45e34
don't export expvar variables
thraxil Jul 29, 2017
24877c7
runbook_link -> runbookLink
thraxil Jul 29, 2017
8645b11
alerts_sent -> alertsSent
thraxil Jul 29, 2017
5c48e77
raw_response -> rawResponse
thraxil Jul 29, 2017
bca927b
backoff_time -> backoffTime
thraxil Jul 29, 2017
5a2628f
GRAPH_WIDTH -> graphWidth
thraxil Jul 29, 2017
bf00319
DAILY_GRAPH_HEIGHT -> dailyGraphHeight
thraxil Jul 29, 2017
c732d99
BACKOFF_DURATIONS -> backoffDurations
thraxil Jul 29, 2017
5047ae5
Url -> URL
thraxil Jul 29, 2017
b2927e0
convert elses to guards
thraxil Jul 29, 2017
0e7ff78
don't export as many variables
thraxil Jul 29, 2017
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
284 changes: 139 additions & 145 deletions alert.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions alert.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ <h1><a href="/">Hound</a>: <span class="glyphicon {{$element.GlyphIcon}}" aria-h
</th>
<td>
<h2>Daily Graph</h2>
<img src="{{$element.DailyGraphUrl}}" width="800" height="150" />
<img src="{{$element.DailyGraphURL}}" width="800" height="150" />

<h2>Weekly Graph</h2>
<img src="{{$element.WeeklyGraphUrl}}" width="800" height="75" />
<img src="{{$element.WeeklyGraphURL}}" width="800" height="75" />
</td></tr>

{{ if $element.RunBookLink }}
Expand Down
76 changes: 38 additions & 38 deletions alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type DummyFetcher struct{}
func (d DummyFetcher) Get(url string) (*http.Response, error) { return nil, nil }

func Test_String(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.String() != "OK\tfoo [foo]" {
t.Error("wrong value")
}
Expand All @@ -24,53 +24,53 @@ func Test_String(t *testing.T) {
}

func Test_StringWhiteSpaceRemoval(t *testing.T) {
a := NewAlert("foo", " foo\n\n \t \r", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", " foo\n\n \t \r", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.Metric != "foo" {
t.Error("whitespace not removed from metric")
}
}

func Test_Url(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.Url() != "?target=keepLastValue(foo)&format=raw&from=-"+WINDOW {
t.Error(fmt.Sprintf("wrong value: %s", a.Url()))
func Test_URL(t *testing.T) {
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.URL() != "?target=keepLastValue(foo)&format=raw&from=-"+window {
t.Error(fmt.Sprintf("wrong value: %s", a.URL()))
}
}

func Test_DailyGraphUrl(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.DailyGraphUrl() != "?target=foo&target=threshold(10.000000)&width=800&height=150&bgcolor=FFFFFF&fgcolor=000000&hideGrid=true&colorList=%23999999,%23006699&from=-24hours" {
t.Error(fmt.Sprintf("wrong value: %s", a.DailyGraphUrl()))
func Test_DailyGraphURL(t *testing.T) {
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.DailyGraphURL() != "?target=foo&target=threshold(10.000000)&width=800&height=150&bgcolor=FFFFFF&fgcolor=000000&hideGrid=true&colorList=%23999999,%23006699&from=-24hours" {
t.Error(fmt.Sprintf("wrong value: %s", a.DailyGraphURL()))
}
}

func Test_WeeklyGraphUrl(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.WeeklyGraphUrl() != "?target=foo&target=threshold(10.000000)&width=800&height=75&hideGrid=true&hideLegend=true&graphOnly=true&hideAxes=true&bgcolor=EEEEEE&fgcolor=000000&hideGrid=true&colorList=%23cccccc,%236699cc&from=-7days" {
t.Error(fmt.Sprintf("wrong value: %s", a.WeeklyGraphUrl()))
func Test_WeeklyGraphURL(t *testing.T) {
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.WeeklyGraphURL() != "?target=foo&target=threshold(10.000000)&width=800&height=75&hideGrid=true&hideLegend=true&graphOnly=true&hideAxes=true&bgcolor=EEEEEE&fgcolor=000000&hideGrid=true&colorList=%23cccccc,%236699cc&from=-7days" {
t.Error(fmt.Sprintf("wrong value: %s", a.WeeklyGraphURL()))
}
}

func Test_RecoveryEmailSubject(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.RecoveryEmailSubject() != "[RECOVERED] foo" {
t.Error(fmt.Sprintf("wrong value: %s", a.RecoveryEmailSubject()))
}
}

func Test_AlertEmailSubject(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.AlertEmailSubject() != "[ALERT] foo" {
t.Error(fmt.Sprintf("wrong value: %s", a.AlertEmailSubject()))
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.alertEmailSubject() != "[ALERT] foo" {
t.Error(fmt.Sprintf("wrong value: %s", a.alertEmailSubject()))
}
a.Type = "Notice"
if a.AlertEmailSubject() != "[NOTICE] foo" {
t.Error(fmt.Sprintf("wrong value: %s", a.AlertEmailSubject()))
if a.alertEmailSubject() != "[NOTICE] foo" {
t.Error(fmt.Sprintf("wrong value: %s", a.alertEmailSubject()))
}
}

func Test_GlyphIcon(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.GlyphIcon() != "glyphicon-warning-sign" {
t.Error(fmt.Sprintf("wrong value: %s", a.GlyphIcon()))
}
Expand All @@ -80,26 +80,26 @@ func Test_GlyphIcon(t *testing.T) {
}
}

func Test_AlertEmailBody(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if !strings.HasPrefix(a.AlertEmailBody(), "foo [foo] has triggered an alert") {
t.Error(fmt.Sprintf("wrong value: %s", a.AlertEmailBody()))
func Test_alertEmailBody(t *testing.T) {
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if !strings.HasPrefix(a.alertEmailBody(), "foo [foo] has triggered an alert") {
t.Error(fmt.Sprintf("wrong value: %s", a.alertEmailBody()))
}
a = NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "runbooklinkfoo")
if !strings.Contains(a.AlertEmailBody(), "runbooklinkfoo") {
t.Error(fmt.Sprintf("wrong value: %s", a.AlertEmailBody()))
a = newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "runbooklinkfoo")
if !strings.Contains(a.alertEmailBody(), "runbooklinkfoo") {
t.Error(fmt.Sprintf("wrong value: %s", a.alertEmailBody()))
}
}

func Test_RecoveryEmailBody(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if !strings.HasPrefix(a.RecoveryEmailBody(), "foo [foo] has returned below 10.000000") {
t.Error(fmt.Sprintf("wrong value: %s", a.RecoveryEmailBody()))
}
}

func Test_UpdateState(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
s, rs, e, f, as := a.UpdateState(0)
if s != 1 {
t.Error("s is wrong")
Expand Down Expand Up @@ -176,7 +176,7 @@ func Test_extractLastValue(t *testing.T) {
}

func Test_UpdateStatus(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a.UpdateStatus(11.0)
if a.Status != "Failed" {
t.Error("should've failed")
Expand All @@ -197,31 +197,31 @@ func Test_UpdateStatus(t *testing.T) {
}

func Test_RenderDirection(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.RenderDirection() != "<" {
t.Error("(OK, above) expected <, got >")
}

a = NewAlert("foo", "foo", "", 10, "below", DummyFetcher{}, "test@example.com", "")
a = newAlert("foo", "foo", "", 10, "below", DummyFetcher{}, "test@example.com", "")
if a.RenderDirection() != ">" {
t.Error("(OK, below) expected <, got >")
}

a = NewAlert("foo", "foo", "", 10, "below", DummyFetcher{}, "test@example.com", "")
a = newAlert("foo", "foo", "", 10, "below", DummyFetcher{}, "test@example.com", "")
a.Status = "Failed"
if a.RenderDirection() != "<" {
t.Error("(Failed, below) expected >, got <")
}

a = NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a = newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a.Status = "Failed"
if a.RenderDirection() != ">" {
t.Error("(Failed, above) expected <, got >")
}
}

func Test_BootstrapStatus(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
if a.BootstrapStatus() != "OK" {
t.Error("bootstrap status OK expected OK")
}
Expand All @@ -236,7 +236,7 @@ func Test_BootstrapStatus(t *testing.T) {
}

func Test_JustRecovered(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a.PreviousStatus = "Failed"
if !a.JustRecovered() {
t.Error("JustRecovered expected true")
Expand All @@ -252,7 +252,7 @@ func Test_JustRecovered(t *testing.T) {
}

func Test_Hash(t *testing.T) {
a := NewAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
a := newAlert("foo", "foo", "", 10, "above", DummyFetcher{}, "test@example.com", "")
expected := "22138d2e6b"
result := a.Hash()
if result != expected {
Expand Down
Loading