Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 11 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
31 changes: 28 additions & 3 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,31 @@ func (ns *Notifications) Get(c *Conf, tags opentsdb.TagSet) map[string]*Notifica
return nots
}

func GetNotificationChains(c *Conf, n map[string]*Notification) ([][]string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a comments about exactly what it returns. I'm kinda confused on the myself. A list of lists of chains for a single alert? With no duplicates. Maybe writing it out will help.

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,9 +365,9 @@ type Notification struct {
body string
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete rather than comment.

// return nil, fmt.Errorf("conf: cannot json marshal notifications")
// }

type Vars map[string]string

Expand Down
112 changes: 0 additions & 112 deletions cmd/bosun/sched/filter.go

This file was deleted.

28 changes: 22 additions & 6 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/MiniProfiler/go/miniprofiler"
"github.com/boltdb/bolt"
"github.com/bradfitz/slice"
"github.com/kylebrandt/boolq"
"github.com/kylebrandt/boolq/parse"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we alias this reference please. We have way too many things called parse. Better yet, maybe it should just be boolq.Parse and nobody else needs to know about the internal parse package.

"github.com/tatsushid/go-fastping"
)

Expand Down Expand Up @@ -372,16 +374,19 @@ 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)
if err2 != nil {
err = err2
return
}
status2, err2 := s.GetOpenStates()
if err2 != nil {
err = err2
return
}
var parsedExpr *parse.Tree
if filter != "" {
parsedExpr, err2 = parse.Parse(filter)
if err2 != nil {
err = err2
return
}
}
for k, v := range status2 {
a := s.Conf.Alerts[k.Name()]
if a == nil {
Expand All @@ -391,7 +396,18 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
}
continue
}
if matches(s.Conf, a, v) {
if parsedExpr == nil {
Copy link
Contributor

@captncraig captncraig Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the logic here is a bit odd. I would like to see the status[k] = v bit only once, and continue if it doesn't match the filter.
Something like if filter and !filter.Matches(is) { continue} status[k] = v. If that makes any sense.

status[k] = v
continue
}
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