diff --git a/bird/bird.go b/bird/bird.go index 97639c4..867fe99 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -172,29 +172,22 @@ func Protocols() (Parsed, bool) { } func ProtocolsBgp() (Parsed, bool) { - p, from_cache := Protocols() - if isSpecial(p) { - return p, from_cache + protocols, from_cache := Protocols() + if isSpecial(protocols) { + return protocols, from_cache } - protocols := p["protocols"].([]string) - bgpProto := Parsed{} + bgpProtocols := Parsed{} - for _, v := range protocols { - if strings.Contains(v, " BGP ") { - key := strings.Split(v, " ")[0] - bgpProto[key], from_cache = fromCache(key) - if !from_cache { - parsed := parseProtocol(v) - bgpProto[key] = parsed - toCache(key, parsed) - } + for key, protocol := range protocols["protocols"].(Parsed) { + if protocol.(Parsed)["bird_protocol"] == "BGP" { + bgpProtocols[key] = protocol } } - return Parsed{"protocols": bgpProto, - "ttl": p["ttl"], - "cached_at": p["cached_at"]}, from_cache + return Parsed{"protocols": bgpProtocols, + "ttl": protocols["ttl"], + "cached_at": protocols["cached_at"]}, from_cache } func Symbols() (Parsed, bool) { diff --git a/bird/parser.go b/bird/parser.go index 7762686..408c8db 100644 --- a/bird/parser.go +++ b/bird/parser.go @@ -132,7 +132,6 @@ func parseStatus(reader io.Reader) Parsed { func parseProtocols(reader io.Reader) Parsed { res := Parsed{} - protocols := []string{} proto := "" @@ -142,7 +141,9 @@ func parseProtocols(reader io.Reader) Parsed { if emptyString(line) { if !emptyString(proto) { - protocols = append(protocols, proto) + parsed := parseProtocol(proto) + + res[parsed["protocol"].(string)] = parsed } proto = "" } else { @@ -150,8 +151,7 @@ func parseProtocols(reader io.Reader) Parsed { } } - res["protocols"] = protocols - return res + return Parsed{"protocols": res} } func parseSymbols(reader io.Reader) Parsed { diff --git a/etc/ecix/birdwatcher.conf b/etc/ecix/birdwatcher.conf index b28e60d..eb727f5 100644 --- a/etc/ecix/birdwatcher.conf +++ b/etc/ecix/birdwatcher.conf @@ -6,25 +6,35 @@ # Restrict access to certain IPs. Leave empty to allow from all. allow_from = [] -# All modules: +# Available modules: +## low-level modules (translation from birdc output to JSON objects) # status -# protocols -# protocols_bgp # symbols # symbols_tables # symbols_protocols +# protocols +# protocols_bgp # routes_protocol # routes_table # routes_count_protocol # routes_count_table -# route_net # routes_filtered # routes_prefixed # routes_noexport +# route_net +## high-level modules (aggregated data from multiple birdc invocations) # routes_dump # routes_peer -# -modules_enabled = ["status", "protocols_bgp", "routes_protocol", "routes_peer"] + + +modules_enabled = ["status", + "protocols", + "protocols_bgp", + "routes_protocol", + "routes_peer", + "routes_prefixed", + "routes_dump" + ] [status] #