-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
70 lines (60 loc) · 1.43 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 (
"flag"
gs1200 "gs1200-exporter/internal"
"os"
log "github.com/sirupsen/logrus"
)
var (
Version = "development"
listenPort = flag.String("port", "9934",
"Port on which to expose metrics.")
gs1200Address = flag.String("address", "192.168.1.3",
"IP address or hostname of the GS1200")
gs1200Password = flag.String("password", "********",
"Password to log on to the GS1200")
versionFlag = flag.Bool("version", false,
"Show gs1200-exporter version")
jsonLogging = flag.Bool("json", false,
"Enable JSON logging")
verboseLogging = flag.Bool("verbose", false,
"Enable verbose logging")
debugLogging = flag.Bool("debug", false,
"Enable debug logging")
)
func main() {
flag.Parse()
if *jsonLogging {
log.SetFormatter(&log.JSONFormatter{})
} else {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
}
if *verboseLogging {
log.SetLevel(log.DebugLevel)
}
if *debugLogging {
log.SetLevel(log.TraceLevel)
}
if *versionFlag {
log.Info("gs1200-exporter ", Version)
os.Exit(0)
}
collector, err := gs1200.GS1200Collector(
getEnv("GS1200_ADDRESS", *gs1200Address),
getEnv("GS1200_PASSWORD", *gs1200Password),
)
if err != nil {
log.Error("Cannot start collector: ", err)
return
}
exporter := gs1200.GS1200Exporter(*collector, *listenPort)
exporter.Run()
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}