1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

use config in bird

This commit is contained in:
Matthias Hannig 2016-11-30 13:40:34 +01:00
parent 7758148d3a
commit 3508a2298b
4 changed files with 27 additions and 20 deletions

View file

@ -7,7 +7,7 @@ import (
"time"
)
var BirdCmd string
var Conf BirdConfig
var Cache = struct {
sync.RWMutex
@ -31,7 +31,7 @@ func toCache(key string, val Parsed) {
func Run(args string) ([]byte, error) {
args = "show " + args
argsList := strings.Split(args, " ")
return exec.Command(BirdCmd, argsList...).Output()
return exec.Command(Conf.BirdCmd, argsList...).Output()
}
func RunAndParse(cmd string, parser func([]byte) Parsed) (Parsed, bool) {

16
bird/config.go Normal file
View file

@ -0,0 +1,16 @@
package bird
// Birdwatcher Birdc Configuration
type StatusConfig struct {
ReconfigTimestampSource string `toml:"reconfig_timestamp_source"`
ReconfigTimestampMatch string `toml:"reconfig_timestamp_match"`
FilteredFields []string `toml:"filtered_fields"`
}
type BirdConfig struct {
Listen string
ConfigFilename string `toml:"config"`
BirdCmd string `toml:"birdc"`
}

View file

@ -7,6 +7,7 @@ import (
"github.com/ecix/birdwatcher/bird"
"github.com/ecix/birdwatcher/endpoints"
"github.com/julienschmidt/httprouter"
)
@ -29,7 +30,7 @@ func makeRouter() *httprouter.Router {
// Print service information like, listen address,
// access restrictions and configuration flags
func PrintServiceInfo(conf *Config, birdConf BirdConfig) {
func PrintServiceInfo(conf *Config, birdConf bird.BirdConfig) {
// General Info
log.Println("Starting Birdwatcher")
log.Println(" Using:", birdConf.BirdCmd)
@ -60,7 +61,7 @@ func main() {
PrintServiceInfo(conf, birdConf)
// Configure client
bird.BirdCmd = birdConf.BirdCmd
bird.Conf = birdConf
// Make server
r := makeRouter()

View file

@ -6,32 +6,22 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/imdario/mergo"
"github.com/ecix/birdwatcher/bird"
)
type Config struct {
Server ServerConfig
Status StatusConfig
Bird BirdConfig
Bird6 BirdConfig
Status bird.StatusConfig
Bird bird.BirdConfig
Bird6 bird.BirdConfig
}
type ServerConfig struct {
AllowFrom []string `toml:"allow_from"`
}
type StatusConfig struct {
ReconfigTimestampSource string `toml:"reconfig_timestamp_source"`
ReconfigTimestampMatch string `toml:"reconfig_timestamp_match"`
FilteredFields []string `toml:"filtered_fields"`
}
type BirdConfig struct {
Listen string
ConfigFilename string `toml:"config"`
BirdCmd string `toml:"birdc"`
}
// Try to load configfiles as specified in the files
// list. For example:
//