-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (55 loc) · 1.72 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
package main
import (
"bcfmonitor/pkg/config"
"bcfmonitor/pkg/log"
"bcfmonitor/pkg/mail"
"bcfmonitor/pkg/monitor"
"bcfmonitor/pkg/monitor/mongo"
"bcfmonitor/pkg/monitor/ping"
"bcfmonitor/pkg/monitor/redis"
"bcfmonitor/pkg/monitor/web"
"os"
"github.com/alecthomas/kong"
)
var version = "undefined"
var buildNumber = "undefined"
var buildDate = "undefined"
func main() {
var CLI struct {
ConfigFile string `default:"conf/dev.yaml" short:"c" aliases:"conf" help:"path to yaml config file"`
}
// command line flags and params
_ = kong.Parse(&CLI)
log.Infof("start", "Version %s, Build #%s@%s", version, buildNumber, buildDate)
log.Infof("start", "Running on PID: %d", os.Getpid())
log.Info("config/load", CLI.ConfigFile)
cfg, err := config.Load(CLI.ConfigFile)
if err != nil {
log.Fatalf("config/parse", "ERROR: %s", err)
os.Exit(1)
}
mailSvc := mail.NewService(cfg.SMTP.Host, cfg.SMTP.Port, cfg.SMTP.User, cfg.SMTP.Pass, cfg.SMTP.Admins)
monitorSvc := monitor.NewService(mailSvc)
// add databases
for _, d := range cfg.Databases {
dbMon := mongo.NewService(d.Name, d.Host, d.Port, d.SSL, d.Timeout, d.Every)
monitorSvc.AddMonitorizable(dbMon)
}
// add caches
for _, c := range cfg.Caches {
cacheMon := redis.NewService(c.Name, c.Host, c.Port, c.Password, c.Timeout, c.Every)
monitorSvc.AddMonitorizable(cacheMon)
}
// add webs
for _, w := range cfg.Webs {
webMon := web.NewService(w.Name, w.URL, w.Needle, w.HeaderMap(), w.Timeout, w.Every)
monitorSvc.AddMonitorizable(webMon)
}
for _, p := range cfg.Pings {
pingMon := ping.NewService(p.Name, p.Host, p.Timeout, p.Every)
monitorSvc.AddMonitorizable(pingMon)
}
// start the monitor runner
defer log.Info("runner", "Exiting")
monitorSvc.Run()
}