-
Notifications
You must be signed in to change notification settings - Fork 494
/
incident.go
44 lines (40 loc) · 1.07 KB
/
incident.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package web
import (
"fmt"
"net/http"
"bosun.org/cmd/bosun/sched"
"github.com/MiniProfiler/go/miniprofiler"
"github.com/kylebrandt/boolq"
)
func ListOpenIncidents(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) {
// TODO: Retune this when we no longer store email bodies with incidents
list, err := schedule.DataAccess.State().GetAllOpenIncidents()
if err != nil {
return nil, err
}
suppressor := schedule.Silenced()
if suppressor == nil {
return nil, fmt.Errorf("failed to get silences")
}
summaries := []*sched.IncidentSummaryView{}
filterText := r.FormValue("filter")
var parsedExpr *boolq.Tree
parsedExpr, err = boolq.Parse(filterText)
if err != nil {
return nil, fmt.Errorf("bad filter: %v", err)
}
for _, iState := range list {
is, err := sched.MakeIncidentSummary(schedule.RuleConf, suppressor, iState)
if err != nil {
return nil, err
}
match, err := boolq.AskParsedExpr(parsedExpr, is)
if err != nil {
return nil, err
}
if match {
summaries = append(summaries, is)
}
}
return summaries, nil
}