Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow lookups for notification validation. #2168

Merged
merged 7 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 5 additions & 19 deletions cmd/bosun/conf/rule/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,18 @@ func (c *Conf) loadAlert(s *parse.SectionNode) {
c.errorf("Depends and crit/warn must share at least one tag.")
}
}
warnLength := len(a.WarnNotification.Notifications) + len(a.WarnNotification.Lookups)
critLength := len(a.CritNotification.Notifications) + len(a.CritNotification.Lookups)
allNots := c.getAllPossibleNotifications(&a)
if a.Log {
for _, n := range a.CritNotification.Notifications {
for _, n := range allNots {
if n.Next != nil {
c.errorf("cannot use log with a chained notification")
}
}
for _, n := range a.WarnNotification.Notifications {
if n.Next != nil {
c.errorf("cannot use log with a chained notification")
}
}
if warnLength+critLength == 0 {
if len(allNots) == 0 {
c.errorf("log specified but no notification")
}
}
if warnLength+critLength > 0 && a.Template == nil {
if len(allNots) > 0 && a.Template == nil {
c.errorf("notifications specified but no template")
}
if a.Template != nil {
Expand Down Expand Up @@ -334,17 +328,9 @@ func (c *Conf) loadAlert(s *parse.SectionNode) {
checkTplKeys(ntk, key, false)
}
}
uniqNots := map[string]*conf.Notification{}
for n, not := range a.CritNotification.GetAllChained() {
uniqNots[n] = not
}
for n, not := range a.WarnNotification.GetAllChained() {
uniqNots[n] = not
}
for _, not := range uniqNots {
for _, not := range allNots {
checkNotification(not)
}

}
a.ReturnType = ret
c.Alerts[name] = &a
Expand Down
29 changes: 29 additions & 0 deletions cmd/bosun/conf/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,32 @@ func (c *Conf) genHash() {
func (c *Conf) GetHash() string {
return c.Hash
}

// returns any notifications accessible from the alert vis warn/critNotification, including chains and lookups
func (c *Conf) getAllPossibleNotifications(a *conf.Alert) map[string]*conf.Notification {
nots := map[string]*conf.Notification{}
for k, v := range a.WarnNotification.GetAllChained() {
nots[k] = v
}
for k, v := range a.CritNotification.GetAllChained() {
nots[k] = v
}
followLookup := func(l map[string]*conf.Lookup) {
for target, lookup := range l {
for _, entry := range lookup.Entries {
if notNames, ok := entry.Values[target]; ok {
for _, k := range strings.Split(notNames, ",") {
if not, ok := c.Notifications[k]; ok {
nots[k] = not
} else {
c.errorf("Notification %s needed by lookup %s in %s is not defined.", k, lookup.Name, a.Name)
}
}
}
}
}
}
followLookup(a.CritNotification.Lookups)
followLookup(a.WarnNotification.Lookups)
return nots
}
2 changes: 1 addition & 1 deletion cmd/bosun/w.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

while echo "(RE)STARTING BOSUN"; do
go run main.go -w -q || exit
go run main.go -w -q -dev || exit
done
62 changes: 32 additions & 30 deletions cmd/bosun/web/static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions cmd/bosun/web/static/js/ace/mode-bosun.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ var BosunHighlightRules = function() {
var inAlertKeywords = "macro|template|crit|warn|depends|squelch|critNotification|" +
"warnNotification|unknown|unjoinedOk|ignoreUnknown|log|maxLogFrequency"

var inNotificationKeywords = "email|post|get|print|contentType|next|timeout|body|useBody";

var inNotificationKeywords = "email|post|get|print|contentType|next|timeout|bodyTemplate|postTemplate|getTemplate|emailSubjectTemplate|runOnActions|groupActions|unknownMinGroupSize|unknownThreshold";
for (var action of ["Get","Post","Body","EmailSubject"]){
inNotificationKeywords += "|action"+action;
inNotificationKeywords += "|unknown"+action;
inNotificationKeywords += "|unknownMulti"+action;
for (var type of ["Ack", "Close", "Forget", "ForceClose", "Purge", "Note", "DelayedClose","CancelClose"]){
inNotificationKeywords += "|action"+action+type;
}
}
var inTemplateKeywords = "subject|body";

var inSectionKeywords = [inAlertKeywords, inNotificationKeywords, inTemplateKeywords].join("|");
Expand Down