mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
added routes and bgp parse stub
This commit is contained in:
parent
eed6e71b0b
commit
9337b1c32c
6 changed files with 164 additions and 3 deletions
18
bird/bird.go
18
bird/bird.go
|
@ -3,6 +3,7 @@ package bird
|
|||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func Run(args string) ([]byte, error) {
|
||||
|
@ -30,6 +31,23 @@ func Protocols() Parsed {
|
|||
return RunAndParse("protocols all", parseProtocols)
|
||||
}
|
||||
|
||||
func ProtocolsBgp() Parsed {
|
||||
protocols := Protocols()
|
||||
|
||||
bgpProto := Parsed{}
|
||||
bgp_rx := regexp.MustCompile(`^(\w+)\s+BGP\s+.*`)
|
||||
|
||||
for _, v := range protocols {
|
||||
vs := v.(string)
|
||||
if bgp_rx.MatchString(vs) {
|
||||
key := bgp_rx.FindStringSubmatch(vs)[1]
|
||||
bgpProto[key] = parseBgp(vs)
|
||||
}
|
||||
}
|
||||
|
||||
return bgpProto
|
||||
}
|
||||
|
||||
func Symbols() Parsed {
|
||||
return RunAndParse("symbols", parseSymbols)
|
||||
}
|
||||
|
|
|
@ -230,3 +230,9 @@ func parseRoutesCount(input []byte) Parsed {
|
|||
|
||||
return res
|
||||
}
|
||||
|
||||
func parseBgp(input string) Parsed {
|
||||
res := Parsed{}
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -112,9 +112,18 @@ func main() {
|
|||
fmt.Printf("%v\n", conf)
|
||||
|
||||
r := httprouter.New()
|
||||
r.GET("/status", Status)
|
||||
r.GET("/routes/protocol/:protocol", ProtoRoutes)
|
||||
r.GET("/protocols", Protocols)
|
||||
r.GET("/status", Status) // done
|
||||
r.GET("/protocols/bgp", Bgp)
|
||||
r.GET("/symbols", Symbols) // done
|
||||
r.GET("/symbols/tables", SymbolTables) //done
|
||||
r.GET("/symbols/protocols", SymbolProtocols) // done
|
||||
r.GET("/routes/protocol/:protocol", ProtoRoutes) //done
|
||||
r.GET("/routes/table/:table", TableRoutes) //done
|
||||
r.GET("/routes/count/protocol/:protocol", ProtoCount) //done
|
||||
r.GET("/routes/count/table/:table", TableCount) // done
|
||||
r.GET("/route/net/:net", RouteNet) // done
|
||||
r.GET("/route/net/:net/table/:table", RouteNetTable) // done
|
||||
r.GET("/protocols", Protocols) // done
|
||||
|
||||
log.Fatal(http.ListenAndServe(":29184", r))
|
||||
}
|
||||
|
|
13
protocols.go
13
protocols.go
|
@ -20,3 +20,16 @@ func Protocols(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func Bgp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
|
||||
res["protocols"] = bird.ProtocolsBgp()["protocols"]
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
|
64
routes.go
64
routes.go
|
@ -18,3 +18,67 @@ func ProtoRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func TableRoutes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
res["routes"] = bird.RoutesTable(ps.ByName("table"))["routes"]
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func ProtoCount(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
res["count"] = bird.RoutesProtoCount(ps.ByName("protocol"))
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func TableCount(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
res["count"] = bird.RoutesTable(ps.ByName("table"))
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func RouteNet(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
res["routes"] = bird.RoutesLookupTable(ps.ByName("net"), "master")
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
|
||||
func RouteNetTable(w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
res["routes"] = bird.RoutesLookupTable(ps.ByName("net"),
|
||||
ps.ByName("table"))
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
|
51
symbols.go
Normal file
51
symbols.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/mchackorg/birdwatcher/bird"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Symbols(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
|
||||
res["symbols"] = bird.Symbols()
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func SymbolTables(w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
|
||||
res["symbols"] = bird.Symbols()["routing table"]
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func SymbolProtocols(w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
ps httprouter.Params) {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
res["api"] = GetApiInfo()
|
||||
|
||||
res["symbols"] = bird.Symbols()["protocol"]
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(js)
|
||||
}
|
Loading…
Add table
Reference in a new issue