-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (64 loc) · 1.62 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"net"
"os"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
const version = "0.2.0"
func main() {
version := flag.Bool("version", false, "Shows version info")
configFile := flag.String("config-file", "config.yml", "Path to config file")
debug := flag.Bool("debug", false, "Enables debug output")
metricsEndpoint := flag.String("metrics-endpoint", ":10080", "Endopint for scraping metrics")
flag.Parse()
if *version {
printVersion()
os.Exit(0)
}
if *debug {
logrus.SetLevel(logrus.DebugLevel)
}
pipes, err := loadPipesFromConfig(*configFile)
if err != nil {
logrus.Fatal(err)
}
if len(pipes) == 0 {
logrus.Info("No pipes defined.")
os.Exit(0)
}
err = startMetricEndpoint(*metricsEndpoint)
if err != nil {
logrus.Fatal(err)
}
m := newMonitor(pipes)
err = m.start()
if err != nil {
logrus.Fatal(err)
}
}
func printVersion() {
fmt.Println("piper")
fmt.Printf("Version: %s\n", version)
fmt.Println("Author(s): Daniel Czerwonk")
fmt.Println("Copyright: 2020, Mauve Mailorder Software GmbH & Co. KG, Licensed under MIT license")
fmt.Println("Piping routing information learned in a routing table to another one")
}
func loadPipesFromConfig(path string) ([]*pipe, error) {
pipes := []*pipe{}
cfg, err := loadConfig(path)
if err != nil {
return nil, err
}
for _, p := range cfg.Pipes {
_, pfx, err := net.ParseCIDR(p.Prefix)
if err != nil {
return nil, errors.Wrapf(err, "could not parse %s", p.Prefix)
}
logrus.Infof("Configure pipe: %v", p)
pipes = append(pipes, newPipe(p.Name, *pfx, p.Source, p.Target, cfg.Proto))
}
return pipes, nil
}