-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (47 loc) · 1.15 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
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"net/http"
hue "github.com/collinux/gohue"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
var config = flag.String("c", "huepro.conf", "The config file to use")
/*
func register() {
locators, _ := hue.DiscoverBridges(false)
locator := locators[0] // find the first locator
deviceType := "huepro"
// remember to push the button on your hue first
bridge, _ := locator.CreateUser(deviceType)
fmt.Printf("registered new device => %+v\n", bridge)
}
*/
type Config struct {
IpAddr string
Token string
}
func main() {
flag.Parse()
raw, err := ioutil.ReadFile(*config)
if err != nil {
panic(err)
}
var cfg Config
json.Unmarshal(raw, &cfg)
bridge, err := hue.NewBridge(cfg.IpAddr)
if err != nil {
panic(err)
}
err = bridge.Login(cfg.Token)
if err != nil {
panic(err)
}
prometheus.MustRegister(NewHueCollector("", bridge))
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*addr, nil))
}