-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (57 loc) · 1.54 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
package main
import (
"embed"
"flag"
"fmt"
"os"
"gobana-agent/agent"
"gobana-agent/core"
)
const AppName = "Gobana Agent"
var (
version = "?"
commit = "-"
)
// Filesystem which contains templates
//
//go:embed templates/**/*
var templateFs embed.FS
func main() {
var configFile string
var checkConfig bool
var showVersion bool
flag.StringVar(&configFile, "config", "config.yaml", "Path to config file")
flag.BoolVar(&checkConfig, "check-config", false, "Check config file is valid")
flag.BoolVar(&showVersion, "version", false, "Show Version number")
flag.Parse()
// Version
if showVersion {
fmt.Printf("%s version %s, build %s\n", AppName, version, commit)
os.Exit(0)
}
core.Logger.Infof("app", "Start %s version %s", AppName, version)
defer core.Logger.Infof("app", "Exit %s", AppName)
//
// check config special case
if checkConfig {
agent.CheckConfig(configFile)
}
// parse config
core.Logger.Infof("config", "load config from %s", configFile)
if err := core.ReadConfig(configFile, agent.AppConfig); err != nil {
core.Logger.Criticalf("config", "unable to load agent config : %s", err)
}
// setup embedded fs to core
core.TemplateFs = templateFs
// setup vars
core.Logger.DebugEnabled = agent.AppConfig.Debug
agent.AppVersion = version
// start processes
agent.Alerter = &agent.AlerterProcess{}
agent.Watcher = &agent.WatcherProcess{}
processes := []core.ProcessInterface{
&core.ProcessStruct{RunningProcess: agent.Watcher},
&core.ProcessStruct{RunningProcess: agent.Alerter},
}
core.RunProcesses(processes)
}