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

List open incidents #1764

Merged
merged 14 commits into from Jun 8, 2016
33 changes: 29 additions & 4 deletions cmd/bosun/conf/conf.go
Expand Up @@ -295,6 +295,35 @@ func (ns *Notifications) Get(c *Conf, tags opentsdb.TagSet) map[string]*Notifica
return nots
}

// GetNotificationChains returns the warn or crit notification chains for a configured
// alert. Each chain is a list of notification names. If a notification name
// as already been seen in the chain it ends the list with the notification
// name with a of "..." which indicates that the chain will loop.
func GetNotificationChains(c *Conf, n map[string]*Notification) [][]string {
chains := [][]string{}
for _, root := range n {
chain := []string{}
seen := make(map[string]bool)
var walkChain func(next *Notification)
walkChain = func(next *Notification) {
if next == nil {
chains = append(chains, chain)
return
}
if seen[next.Name] {
chain = append(chain, fmt.Sprintf("...%v", next.Name))
chains = append(chains, chain)
return
}
chain = append(chain, next.Name)
seen[next.Name] = true
walkChain(next.Next)
}
walkChain(root)
}
return chains
}

// parseNotifications parses the comma-separated string v for notifications and
// returns them.
func (c *Conf) parseNotifications(v string) (map[string]*Notification, error) {
Expand Down Expand Up @@ -340,10 +369,6 @@ type Notification struct {
body string
}

func (n *Notification) MarshalJSON() ([]byte, error) {
return nil, fmt.Errorf("conf: cannot json marshal notifications")
}

type Vars map[string]string

func ParseFile(fname string) (*Conf, error) {
Expand Down
112 changes: 0 additions & 112 deletions cmd/bosun/sched/filter.go

This file was deleted.

15 changes: 12 additions & 3 deletions cmd/bosun/sched/sched.go
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/MiniProfiler/go/miniprofiler"
"github.com/boltdb/bolt"
"github.com/bradfitz/slice"
"github.com/kylebrandt/boolq"
"github.com/tatsushid/go-fastping"
)

Expand Down Expand Up @@ -372,12 +373,13 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
}
t.FailingAlerts, t.UnclosedErrors = s.getErrorCounts()
T.Step("Setup", func(miniprofiler.Timer) {
matches, err2 := makeFilter(filter)
status2, err2 := s.GetOpenStates()
if err2 != nil {
err = err2
return
}
status2, err2 := s.GetOpenStates()
var parsedExpr *boolq.Tree
parsedExpr, err2 = boolq.Parse(filter)
if err2 != nil {
err = err2
return
Expand All @@ -391,7 +393,14 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
}
continue
}
if matches(s.Conf, a, v) {
is := MakeIncidentSummary(s.Conf, silenced, v)
match := false
match, err2 = boolq.AskParsedExpr(parsedExpr, is)
if err2 != nil {
err = err2
return
}
if match {
status[k] = v
}
}
Expand Down