package app import ( "log/slog" "path/filepath" "strconv" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/ingress" "git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store" ) // IngressPath is the aggregate of the firewall telemetry inside a node directory. func IngressPath(dir string) string { return filepath.Join(dir, "ingress.json") } // newIngress builds the firewall telemetry aggregate of one node. A source // address is "banned" by the node's own ban state (the jails it has read from // fail2ban.log, the urutau jail included). The aggregate only reads that state: // it has no way to write an event, a score or a decision, so attempts from a // banned address never become evidence. func newIngress(st *store.Store, dir string, log *slog.Logger) *ingress.Agg { a := ingress.New() a.Banned = st.Banned a.Geo = func(ip string) (string, string, string) { g := st.GeoOf(ip) asn := "" if g.ASN != 0 { asn = "AS" + strconv.FormatUint(uint64(g.ASN), 10) } return g.CC, asn, g.ASOrg } if err := a.Load(IngressPath(dir)); err != nil { log.Warn("ingress state ignored", "dir", dir, "err", err) } return a }