Skip to content

Commit

Permalink
Merge pull request #870 from bosun-monitor/web-template-error-result
Browse files Browse the repository at this point in the history
cmd/bosun: Ensure web instances have their result set
  • Loading branch information
maddyblue committed Apr 3, 2015
2 parents aee9353 + bda7b53 commit 8b0f6ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/bosun/web/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ func procRule(t miniprofiler.Timer, c *conf.Conf, a *conf.Alert, now time.Time,
warning = append(warning, fmt.Sprintf("template group %s was not a subset of any result", template_group))
}
}
if e := instance.History[0]; e.Error != nil {
instance.Result = e.Error
} else if e.Crit != nil {
instance.Result = e.Crit
} else if e.Warn != nil {
instance.Result = e.Warn
}
var b_err, s_err error
func() {
defer func() {
Expand Down
27 changes: 27 additions & 0 deletions cmd/bosun/web/web_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package web

import (
"testing"
"time"

"bosun.org/cmd/bosun/conf"
)

func TestErrorTemplate(t *testing.T) {
c, err := conf.New("", `
template t {
body = {{.Eval "invalid"}}
}
alert a {
template = t
crit = 1
}
`)
if err != nil {
t.Fatal(err)
}
_, err = procRule(nil, c, c.Alerts["a"], time.Time{}, false, "", "")
if err != nil {
t.Fatal(err)
}
}

0 comments on commit 8b0f6ce

Please sign in to comment.