This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.66 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
package main
import (
"flag"
"fmt"
"net/http"
"os"
conf "github.com/deepnetworkgmbh/security-monitor-core/pkg/config"
"github.com/deepnetworkgmbh/security-monitor-core/pkg/dashboard"
"github.com/sirupsen/logrus"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Required for other auth providers like GKE.
)
const (
// Version represents the current release version of Security Monitor
Version = "0.1.0"
)
func main() {
// Load CLI Flags
dashboardPort := flag.Int("dashboard-port", 8080, "Port for the dashboard webserver")
dashboardBasePath := flag.String("dashboard-base-path", "/", "Path on which the dashboard is served")
configPath := flag.String("config", "", "Location of dashboard configuration file")
logLevel := flag.String("log-level", logrus.InfoLevel.String(), "Logrus log level")
version := flag.Bool("version", false, "Prints the version of Security Monitor")
flag.Parse()
if *version {
fmt.Printf("Security Monitor version %s\n", Version)
os.Exit(0)
}
parsedLevel, err := logrus.ParseLevel(*logLevel)
if err != nil {
logrus.Errorf("log-level flag has invalid value %s", *logLevel)
} else {
logrus.SetLevel(parsedLevel)
}
c, err := conf.ParseFile(*configPath)
if err != nil {
logrus.Errorf("Error parsing config at %s: %v", *configPath, err)
os.Exit(1)
}
startDashboardServer(c, *dashboardPort, *dashboardBasePath)
}
func startDashboardServer(c conf.Configuration, port int, basePath string) {
router := dashboard.GetRouter(c, port, basePath)
srv := &http.Server{
Handler: router,
Addr: fmt.Sprintf(":%d", port),
}
logrus.Infof("Starting Security Monitor dashboard on port %d", port)
logrus.Fatal(srv.ListenAndServe())
}