forked from billykwooten/ecobee-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 2.05 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
// Copyright 2020 Billy Wooten
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"net/http"
"os"
log "github.com/sirupsen/logrus"
"github.com/billykwooten/ecobee-exporter/collector"
"github.com/billykwooten/go-ecobee/ecobee"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
app = kingpin.New("ecobee-exporter", "Ecobee Exporter utilizing Ecobee API").Author("Billy Wooten")
addr = app.Flag("listen-address", "HTTP port to listen on").Envar("ECOBEE_LISTEN_ADDRESS").Default(":9098").String()
applicationKey = app.Flag("appkey", "Application API Key").Envar("ECOBEE_APPKEY").Default("p3NbLx6iSYTjXDFHIMtM77SWWPLRuEZ0").String()
cacheFile = app.Flag("cachefile", "Cache file so the exporter can store and sync authorization tokens").Envar("ECOBEE_CACHEFILE").Default("/db/auth.cache").String()
)
func main() {
// Parse Kingpin Variables
kingpin.MustParse(app.Parse(os.Args[1:]))
// Setup Scopes for API Requests
ecobee.Scopes = []string{"smartRead"}
//Create a new instance of the ecobeeCollector and
//register it with the prometheus client.
ecobeeCollector := collector.NewEcobeeCollector(ecobee.NewClient(*applicationKey, *cacheFile), "ecobee")
prometheus.MustRegister(ecobeeCollector)
//This section will start the HTTP server and expose
//any metrics on the /metrics endpoint.
http.Handle("/metrics", promhttp.Handler())
log.Info("Beginning to serve on port " + *addr)
log.Fatal(http.ListenAndServe(*addr, nil))
}