package app import ( "fmt" "os" "path/filepath" "sort" "time" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/ingress" ) // ingressFresh is how old the last counters line may be before the firewall // telemetry of a host counts as stale: the kit writes one every minute. const ingressFresh = 5 * time.Minute // doctorIngress reports, per host that ever sent it, whether the firewall // telemetry (host kit --ingress) is present and fresh. It reads the saved // aggregate of each node; no host sending it is "off", not a failure. func doctorIngress(c Config, add func(name, status, detail string)) { dirs := map[string]string{c.Name: c.DataDir} if ents, err := os.ReadDir(filepath.Join(c.DataDir, "probes")); err == nil { for _, e := range ents { if e.IsDir() { dirs[e.Name()] = filepath.Join(c.DataDir, "probes", e.Name()) } } } names := make([]string, 0, len(dirs)) for n := range dirs { names = append(names, n) } sort.Strings(names) any := false for _, n := range names { p := IngressPath(dirs[n]) if _, err := os.Stat(p); err != nil { continue } a := ingress.New() if err := a.Load(p); err != nil { add("ingress "+n, "warn", err.Error()) any = true continue } in := a.Info() any = true switch { case in.LastCounters == 0: add("ingress "+n, "warn", "sampled log seen but no counters yet: check ingress.counters and urutau-ingress-tick.timer") case time.Since(time.Unix(in.LastCounters, 0)) > ingressFresh: add("ingress "+n, "warn", fmt.Sprintf("stale: last counters %s ago (is urutau-ingress-tick.timer running?)", time.Since(time.Unix(in.LastCounters, 0)).Round(time.Second))) default: add("ingress "+n, "ok", fmt.Sprintf("fresh: counters %s ago, %d sampled lines", time.Since(time.Unix(in.LastCounters, 0)).Round(time.Second), in.Lines)) } } if !any { add("ingress", "off", "no firewall telemetry received (host kit: install.sh --ingress)") } }