blob: c8b8a76eecc9d974ac91875b95fbb0e7af76d964 [file] [log] [blame]
package main
//go:generate packr
import (
"context"
"flag"
"io/ioutil"
"github.com/digitalocean/go-netbox/netbox"
"github.com/digitalocean/go-netbox/netbox/client"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"code.hackerspace.pl/q3k/topo/graph"
confpb "code.hackerspace.pl/q3k/topo/proto/config"
)
var (
flagConfigPath string
flagNetboxHost string
flagNetboxAPIKey string
flagDebugListen string
)
func init() {
flag.Set("logtostderr", "true")
}
func main() {
flag.StringVar(&flagConfigPath, "config_path", "./topo.pb.text", "Text proto configuration of Topo (per config.proto)")
flag.StringVar(&flagNetboxHost, "netbox_host", "netbox.bgp.wtf", "Netbox host")
flag.StringVar(&flagNetboxAPIKey, "netbox_api_key", "", "Netbox API key")
flag.StringVar(&flagDebugListen, "debug_listen", "127.0.0.1:42001", "Debug HTTP listen address")
flag.Parse()
ctx := context.Background()
data, err := ioutil.ReadFile(flagConfigPath)
if err != nil {
glog.Exitf("Could not read config: %v", err)
}
config := confpb.Config{}
proto.UnmarshalText(string(data), &config)
gr := graph.New()
err = gr.LoadConfig(&config)
if err != nil {
glog.Exitf("Initial config load failed: %v", err)
}
client.DefaultSchemes = []string{"https"}
nb := netbox.NewNetboxWithAPIKey(flagNetboxHost, flagNetboxAPIKey)
err = gr.FeedFromNetbox(ctx, nb)
if err != nil {
glog.Exitf("Initial netbox feed failed: %v", err)
}
sconf := ServiceConfig{
DebugListen: flagDebugListen,
}
srv := NewService(gr, sconf)
srv.Run()
}