forked from maesoser/tplink_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 1.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
package main
import (
"flag"
"log"
"net/http"
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"tplink_exporter/macdb"
"tplink_exporter/tplink"
)
func main() {
Address := flag.String("a", "192.168.0.1", "Router's address")
Pass := flag.String("w", "admin", "Router's password")
User := flag.String("u", "admin", "Router's username")
Port := flag.Int("p", 9300, "Prometheus port")
Verbose := flag.Bool("v", false, "Verbose output")
Filename := flag.String("f", "/etc/known_macs", "MAC Database")
flag.Parse()
macs, vendors, err := macdb.Load(*Filename)
if err != nil {
log.Println("Unable to load MAC database:", err)
} else {
log.Printf("%d custom MACs loaded\n%d vendor MACs loaded\n",
len(macs), len(vendors))
}
router := tplink.NewRouter(*Address, *User, *Pass)
router.Verbose = *Verbose
c := newRouterCollector(router, macs, vendors)
prometheus.MustRegister(c)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*Port), nil))
}