-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
61 lines (51 loc) · 1.59 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"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"github.com/tcassaert/bmwcd_exporter/bmwcd"
)
var (
help = flag.Bool("help", false, "Print help message")
logLevel = flag.String("log.level", "INFO", "Amount of logs displayed")
password = flag.String("password", "", "BMW Connected Drive password")
port = flag.String("port", "9744", "Exporter port")
region = flag.String("region", "rest_of_world", "Region of the Connected Drive account (cn, rest_of_world, us)")
username = flag.String("username", "", "BMW Connected Drive username")
)
func main() {
flag.Parse()
if *help == true {
flag.Usage()
os.Exit(0)
}
log.Base().SetLevel(*logLevel)
log.Infoln("Starting BMW Connected Drive exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
if *username == "" {
log.Errorln("Please provide a username")
os.Exit(1)
}
if *password == "" {
log.Errorln("Please provide a password")
os.Exit(1)
}
collector := bmwcd.NewCollector(*username, *password, *region)
prometheus.MustRegister(collector)
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>BMW Connected Drive Exporter</title></head>
<body>
<h1>BMW Connected Drive Exporter</h1>
<p><a href='/metrics'>Metrics</a></p>
</body>
</html>`))
})
http.ListenAndServe(fmt.Sprintf(":%s", *port), nil)
}