Skip to content

Commit

Permalink
List open incidents (#1764)
Browse files Browse the repository at this point in the history
cmd/bosun: API route to list summaries of open incidents

added for grafana integration
  • Loading branch information
kylebrandt committed Jun 8, 2016
1 parent 6337b9f commit bdab335
Show file tree
Hide file tree
Showing 16 changed files with 1,118 additions and 119 deletions.
33 changes: 29 additions & 4 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit bdab335

Please sign in to comment.