mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
added parser stubs
This commit is contained in:
parent
6f9473c3a8
commit
8c9e695fb6
3 changed files with 101 additions and 0 deletions
75
bird/bird.go
Normal file
75
bird/bird.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package bird
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Run(args string) ([]byte, error) {
|
||||
args = "show" + args
|
||||
argsList := strings.Split(args, " ")
|
||||
return exec.Command("birdc", argsList...).Output()
|
||||
}
|
||||
|
||||
func RunAndParse(cmd string, parser func([]byte)([]Parsed)) []Parsed {
|
||||
out, err := Run(cmd)
|
||||
|
||||
if err != nil {
|
||||
// ignore errors for now
|
||||
return []Parsed{}
|
||||
}
|
||||
|
||||
return parser(out)
|
||||
}
|
||||
|
||||
func Status() []Parsed {
|
||||
return RunAndParse("status", parseStatus)
|
||||
}
|
||||
|
||||
func Protocols() []Parsed {
|
||||
return RunAndParse("protocols all", parseProtocols)
|
||||
}
|
||||
|
||||
func Symbols() []Parsed {
|
||||
return RunAndParse("symbols", parseSymbols)
|
||||
}
|
||||
|
||||
func RoutesProto(protocol string) []Parsed {
|
||||
return RunAndParse("route protocol " + protocol + " all",
|
||||
parseRoutes)
|
||||
}
|
||||
|
||||
func RoutesProtoCount(protocol string) []Parsed {
|
||||
return RunAndParse("route protocol " + protocol + " count",
|
||||
parseRoutesCount)
|
||||
}
|
||||
|
||||
func RoutesExport(protocol string) []Parsed {
|
||||
return RunAndParse("route export " + protocol + " all",
|
||||
parseRoutes)
|
||||
}
|
||||
|
||||
func RoutesExportCount(protocol string) []Parsed {
|
||||
return RunAndParse("route export " + protocol + " count",
|
||||
parseRoutesCount)
|
||||
}
|
||||
|
||||
func RoutesTable(table string) []Parsed {
|
||||
return RunAndParse("route table " + table + " all",
|
||||
parseRoutes)
|
||||
}
|
||||
|
||||
func RoutesTableCount(table string) []Parsed {
|
||||
return RunAndParse("route table " + table + " count",
|
||||
parseRoutesCount)
|
||||
}
|
||||
|
||||
func RoutesLookupTable(net string, table string) []Parsed {
|
||||
return RunAndParse("route for " + net + " table " + table + " all",
|
||||
parseRoutes)
|
||||
}
|
||||
|
||||
func RoutesLookupProtocol(net string, protocol string) []Parsed {
|
||||
return RunAndParse("route for " + net + " protocol " + protocol + " all",
|
||||
parseRoutes)
|
||||
}
|
23
bird/parser.go
Normal file
23
bird/parser.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package bird
|
||||
|
||||
type Parsed string
|
||||
|
||||
func parseStatus(input []byte) []Parsed {
|
||||
return []Parsed{}
|
||||
}
|
||||
|
||||
func parseProtocols(input []byte) []Parsed {
|
||||
return []Parsed{}
|
||||
}
|
||||
|
||||
func parseSymbols(input []byte) []Parsed {
|
||||
return []Parsed{}
|
||||
}
|
||||
|
||||
func parseRoutes(input []byte) []Parsed {
|
||||
return []Parsed{}
|
||||
}
|
||||
|
||||
func parseRoutesCount(input []byte) []Parsed {
|
||||
return []Parsed{}
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"net/http"
|
||||
"github.com/mchackorg/birdwatcher/bird"
|
||||
)
|
||||
|
||||
func Status(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
|
@ -11,6 +12,8 @@ func Status(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
|
||||
res["api"] = GetApiInfo()
|
||||
|
||||
_ = bird.Status()
|
||||
|
||||
js, _ := json.Marshal(res)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
Loading…
Add table
Reference in a new issue