From 7fd2dfd0cf3d4f2fe6a825a868c5ca884e5c404d Mon Sep 17 00:00:00 2001 From: Patrick Seeburger Date: Fri, 28 Sep 2018 16:44:08 +0200 Subject: [PATCH] Implement new endpoint /routes/count/primary --- bird/bird.go | 5 +++++ birdwatcher.go | 3 +++ endpoints/routes.go | 8 ++++++++ etc/ecix/birdwatcher.conf | 1 + 4 files changed, 17 insertions(+) diff --git a/bird/bird.go b/bird/bird.go index 16167af..cf18015 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -214,6 +214,11 @@ func RoutesProtoCount(protocol string) (Parsed, bool) { return RunAndParse(cmd, parseRoutesCount) } +func RoutesProtoPrimaryCount(protocol string) (Parsed, bool) { + cmd := routeQueryForChannel("route primary protocol "+protocol) + " count" + return RunAndParse(cmd, parseRoutesCount) +} + func RoutesFiltered(protocol string) (Parsed, bool) { cmd := routeQueryForChannel("route all filtered protocol " + protocol) return RunAndParse(cmd, parseRoutes) diff --git a/birdwatcher.go b/birdwatcher.go index 8f4de3f..efe9710 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -65,6 +65,9 @@ func makeRouter(config endpoints.ServerConfig) *httprouter.Router { if isModuleEnabled("routes_count_table", whitelist) { r.GET("/routes/count/table/:table", endpoints.Endpoint(endpoints.TableCount)) } + if isModuleEnabled("routes_count_primary", whitelist) { + r.GET("/routes/count/primary/:protocol", endpoints.Endpoint(endpoints.ProtoPrimaryCount)) + } if isModuleEnabled("routes_filtered", whitelist) { r.GET("/routes/filtered/:protocol", endpoints.Endpoint(endpoints.RoutesFiltered)) } diff --git a/endpoints/routes.go b/endpoints/routes.go index a7c8c79..1dee4b3 100644 --- a/endpoints/routes.go +++ b/endpoints/routes.go @@ -58,6 +58,14 @@ func ProtoCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { return bird.RoutesProtoCount(protocol) } +func ProtoPrimaryCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { + protocol, err := ValidateProtocolParam(ps.ByName("protocol")) + if err != nil { + return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false + } + return bird.RoutesProtoPrimaryCount(protocol) +} + func TableCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { return bird.RoutesTableCount(ps.ByName("table")) } diff --git a/etc/ecix/birdwatcher.conf b/etc/ecix/birdwatcher.conf index eb727f5..a1cc871 100644 --- a/etc/ecix/birdwatcher.conf +++ b/etc/ecix/birdwatcher.conf @@ -18,6 +18,7 @@ allow_from = [] # routes_table # routes_count_protocol # routes_count_table +# routes_count_primary # routes_filtered # routes_prefixed # routes_noexport