package server import ( "net/http" "strconv" "time" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store" ) func init() { // GET /api/v1/sessions/funnel?range|from&to&host: every session of the // period counted by stage, plus the 200 sessions the study keeps and the // escalation chains. With peers the counts fall back to the merged sample. registerUserRoute("GET /api/v1/sessions/funnel", func(s *Server) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { p, ok := s.periodStudy(w, r) if !ok { return } var counts *store.StageCounts if eq, ok := s.eventFilter(w, r, 24*time.Hour); ok { if local, peers, _, ok := s.studyHosts(w, eq.Host); ok && local && !peers && s.userSlot(w) { defer func() { <-s.user }() pq := store.PeriodQuery{From: eq.From, To: eq.To, IP: eq.IP, Cat: eq.Cat, Fam: eq.Fam} if n, err := strconv.ParseInt(r.URL.Query().Get("gap"), 10, 64); err == nil { pq.Gap = n } c := s.opt.Store.CountStages(pq) counts = &c } } writeJSON(w, 200, store.FunnelOf(p, counts)) } }) }