forked from leominov/prometheus-actions
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
59 lines (49 loc) · 1.1 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
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/prometheus/common/version"
"github.com/sirupsen/logrus"
)
var (
configFlag = flag.String("config", "/opt/prometheus-actions/prometheus-actions.yaml", "Path to configuration file")
logLevelFlag = flag.String("log-level", "debug", "Logging level")
versionFlag = flag.Bool("version", false, "Prints version and exit")
)
func realMain() int {
flag.Parse()
if *versionFlag {
fmt.Println(version.Print("prometheus-actions"))
return 0
}
log := logrus.New()
if level, err := logrus.ParseLevel(*logLevelFlag); err == nil {
log.SetLevel(level)
}
log.Formatter = &logrus.JSONFormatter{}
log.Infof("Starting prometheus-actions %s...", version.Version)
config, err := LoadConfig(*configFlag)
if err != nil {
log.Error(err)
return 1
}
if err := config.Validate(); err != nil {
log.Error(err)
return 1
}
executor, err := NewExecutor(log, config)
if err != nil {
log.Error(err)
return 1
}
if err := executor.Run(context.Background()); err != nil {
log.Error(err)
return 1
}
return 0
}
func main() {
os.Exit(realMain())
}