bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/incident.go (about)

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