-
Notifications
You must be signed in to change notification settings - Fork 491
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
List open incidents #1764
Changes from 11 commits
03264c9
a64f343
4ed60ed
59736a6
6bf8c5a
3e37c06
65b7f6c
cc7e262
8238332
d3c3f9a
3f3b4c3
b3d7c22
2847542
c1a4d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
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) { | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"github.com/tatsushid/go-fastping" | ||
) | ||
|
||
|
@@ -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 { | ||
|
@@ -391,7 +396,18 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro | |
} | ||
continue | ||
} | ||
if matches(s.Conf, a, v) { | ||
if parsedExpr == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
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 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.