mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
Repair 'protocols' endpoint
* repair 'protocols' endpoint to return a meaningful JSON object * improve example configuration file
This commit is contained in:
parent
712510b3bc
commit
8a69b5ba98
3 changed files with 30 additions and 27 deletions
27
bird/bird.go
27
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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue