ADd consul support , multiple monitors, config file

This commit is contained in:
Mayuresh Gaitonde
2018-10-25 22:23:04 -07:00
parent e20f691de5
commit 6fafdbbd16
11 changed files with 441 additions and 85 deletions

39
config/config.go Normal file
View File

@@ -0,0 +1,39 @@
package config
import (
"github.com/golang/glog"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
"time"
)
type Config struct {
Agent struct {
ListenAddr string `yaml:"listen_addr"`
MonitorInterval time.Duration `yaml:"monitor_interval"`
CleanupTimer time.Duration `yaml:"cleanup_timer"`
ConsulAddr string `yaml:"consul_addr"`
ConsulQueryInterval time.Duration `yaml:"consul_query_interval"`
}
Bgp struct {
LocalAS int `yaml:"local_as"`
PeerAS int `yaml:"peer_as"`
PeerIP string `yaml:"peer_ip"`
Communities []string
Origin string
}
}
func GetConfig(file string) *Config {
absPath, _ := filepath.Abs(file)
data, err := ioutil.ReadFile(absPath)
if err != nil {
glog.Exitf("FATAL: Unable to read config file: %v", err)
}
config := &Config{}
if err := yaml.Unmarshal(data, config); err != nil {
glog.Exitf("FATAL: Unable to decode yaml: %v", err)
}
return config
}