diff --git a/.travis.yml b/.travis.yml index a67dd35..93dabdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ services: matrix: include: - - go: 1.11.x + - go: 1.14.x env: - LATEST=true - go: tip diff --git a/collector.go b/collector.go index a8c0102..95c4fcb 100644 --- a/collector.go +++ b/collector.go @@ -70,7 +70,7 @@ func (fc *fritzCollector) Collect(ch chan<- prometheus.Metric) { dev.Name, ) - if dev.CanMeasureTemp() { + if dev.Present == 1 && dev.CanMeasureTemp() { err = stringToFloatMetric( ch, fc.TemperatureDesc, dev.Temperature.FmtCelsius(), dev.Identifier, dev.Productname, dev.Name, @@ -89,7 +89,7 @@ func (fc *fritzCollector) Collect(ch chan<- prometheus.Metric) { } - if dev.CanMeasurePower() { + if dev.Present == 1 && dev.CanMeasurePower() { err = stringToFloatMetric( ch, fc.EnergyWhDesc, dev.Powermeter.FmtEnergyWh(), dev.Identifier, dev.Productname, dev.Name, diff --git a/collector_test.go b/collector_test.go new file mode 100644 index 0000000..34c9b8d --- /dev/null +++ b/collector_test.go @@ -0,0 +1,40 @@ +package main + +import ( + "net/url" + "os" + "path" + "sync" + "testing" + + "github.com/bpicode/fritzctl/fritz" + "github.com/bpicode/fritzctl/mock" + "github.com/prometheus/client_golang/prometheus/testutil" +) + +func TestCollector(t *testing.T) { + m := mock.New() + m.DeviceList = "test/devicelist.xml" + m.Start() + defer m.Close() + + fbURL, err := url.Parse(m.Server.URL) + if err != nil { + t.Fatalf("Failed to parse mock server url: %v", err) + } + + fritzClient = client{ + HomeAuto: fritz.NewHomeAuto(fritz.URL(fbURL)), + Mutex: &sync.Mutex{}, + } + fc := NewFritzCollector() + + fixture := "test.metrics" + exp, err := os.Open(path.Join("test", fixture)) + if err != nil { + t.Fatalf("Error opening fixture file: %q: %v", fixture, err) + } + if err := testutil.CollectAndCompare(fc, exp); err != nil { + t.Fatal("Unexpected metrics returned:", err) + } +} diff --git a/go.mod b/go.mod index 25006ab..1a1be80 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,12 @@ module github.com/jayme-github/fritzbox_smarthome_exporter +go 1.14 + require ( - github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect github.com/bpicode/fritzctl v1.4.23 github.com/fatih/color v1.7.0 // indirect - github.com/golang/protobuf v1.1.0 // indirect - github.com/julienschmidt/httprouter v1.2.0 // indirect github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.3 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/namsral/flag v1.7.4-pre - github.com/prometheus/client_golang v0.8.0 - github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect - github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 // indirect - github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f // indirect - github.com/stretchr/testify v1.3.0 // indirect - golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 // indirect - golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect - golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290 // indirect - gopkg.in/yaml.v2 v2.2.1 // indirect + github.com/prometheus/client_golang v1.6.0 ) diff --git a/go.sum b/go.sum index a74e837..ad59b25 100644 --- a/go.sum +++ b/go.sum @@ -1,43 +1,128 @@ +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bpicode/fritzctl v1.4.23 h1:iDdhY/8jJGsKgBTvyJQNQ/6WU/0rQAy+3zILX/RX9Qw= github.com/bpicode/fritzctl v1.4.23/go.mod h1:53hmhSv8nwB1X9JxA4rXPrp4zqCEncNRK8auEfdWECE= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namsral/flag v1.7.4-pre h1:b2ScHhoCUkbsq0d2C15Mv+VU8bl8hAXV8arnWiOHNZs= github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7MsceFUpB5yDo= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= -github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.6.0 h1:YVPodQOcK15POxhgARIvnDRVpLcuK8mglnMrWfyrw6A= +github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 h1:osmNoEW2SCW3L7EX0km2LYM8HKpNWRiouxjE3XHkyGc= -github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f h1:c9M4CCa6g8WURSsbrl3lb/w/G1Z5xZpYvhhjdcVDOkE= -github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.11 h1:DhHlBtkHWPYi8O2y31JkK0TF+DGM+51OopZjH/Ia5qI= +github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 h1:h7zdf0RiEvWbYBKIx4b+q41xoUVnMmvsGZnIVE5syG8= -golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290 h1:lPmtvIvpa5gZbfK5Ms5fXR7KNpdSKkKE0W15ED+0p/U= -golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/test/devicelist.xml b/test/devicelist.xml new file mode 100644 index 0000000..d35864d --- /dev/null +++ b/test/devicelist.xml @@ -0,0 +1,219 @@ + + + + 1 + SWITCH_1 + + 0 + manuell + 0 + 0 + + + 0 + 4012 + + + 210 + 0 + + + + + 1 + SWITCH_2 + + 1 + manuell + 0 + 0 + + + 7000 + 4012 + + + 195 + 10 + + + + + 1 + SWITCH_3 + + 0 + manuell + 0 + 0 + + + 0 + 8012 + + + 225 + 0 + + + + + 0 + SWITCH_4_FAILING + + 0 + manuell + 1 + 1 + + + + + + + + + + + + + 1 + HKR_1 + + 200 + 0 + + + 40 + 253 + 36 + 40 + 1 + 1 + 0 + 0 + + 1506805200 + 40 + + + + + + 1 + HKR_2 + + 200 + 0 + + + 40 + 253 + 36 + 40 + 1 + 1 + 1 + 0 + + 1506805200 + 40 + + + + + + 1 + HKR_3 + + 210 + 2 + + + 42 + 40 + 34 + 46 + 0 + 0 + 0 + 1 + + + + + 1 + SEC_1 + + 1 + + + + + 1 + SEC_2 + + 0 + + + + + + 1 + BTN_1 + + + + + 1 + G2 + + 12 + 15,12 + + + 40 + 253 + 36 + 40 + 1 + 1 + 1 + 0 + + 1506805200 + 40 + + + + + + 1 + G1 + + 1 + auto + + + + + 0 + 20,208 + + + + diff --git a/test/test.metrics b/test/test.metrics new file mode 100644 index 0000000..412a2e7 --- /dev/null +++ b/test/test.metrics @@ -0,0 +1,74 @@ +# HELP fritzbox_device_info Device information +# TYPE fritzbox_device_info gauge +fritzbox_device_info{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200",functionbitmask="2944",fw_version="03.83",internal_id="11",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200",functionbitmask="2944",fw_version="03.83",internal_id="20",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200",functionbitmask="2944",fw_version="03.83",internal_id="208",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="214124 34625478542353",device_name="BTN_1",device_type="Motion Detector",functionbitmask="8193",fw_version="03.54",internal_id="19",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="32623646 23523626",device_name="SEC_2",device_type="Motion Detector",functionbitmask="16",fw_version="03.54",internal_id="18",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="44363 2777777",device_name="HKR_1",device_type="Comet DECT",functionbitmask="320",fw_version="03.54",internal_id="12",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="55555 2777777",device_name="HKR_2",device_type="Comet DECT",functionbitmask="320",fw_version="03.54",internal_id="15",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="55555 2777777",device_name="HKR_3",device_type="Comet DECT",functionbitmask="320",fw_version="03.54",internal_id="16",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="8888 23523626",device_name="SEC_1",device_type="Motion Detector",functionbitmask="16",fw_version="03.54",internal_id="17",manufacturer="AVM"} 1 +fritzbox_device_info{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200",functionbitmask="2944",fw_version="03.83",internal_id="666",manufacturer="AVM"} 1 +# HELP fritzbox_device_present Device connected (1) or not (0) +# TYPE fritzbox_device_present gauge +fritzbox_device_present{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 1 +fritzbox_device_present{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 1 +fritzbox_device_present{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 1 +fritzbox_device_present{device_id="214124 34625478542353",device_name="BTN_1",device_type="Motion Detector"} 1 +fritzbox_device_present{device_id="32623646 23523626",device_name="SEC_2",device_type="Motion Detector"} 1 +fritzbox_device_present{device_id="44363 2777777",device_name="HKR_1",device_type="Comet DECT"} 1 +fritzbox_device_present{device_id="55555 2777777",device_name="HKR_2",device_type="Comet DECT"} 1 +fritzbox_device_present{device_id="55555 2777777",device_name="HKR_3",device_type="Comet DECT"} 1 +fritzbox_device_present{device_id="8888 23523626",device_name="SEC_1",device_type="Motion Detector"} 1 +fritzbox_device_present{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200"} 0 +# HELP fritzbox_energy Absolute energy consumption (in Wh) since the device started operating +# TYPE fritzbox_energy gauge +fritzbox_energy{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 4012 +fritzbox_energy{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 4012 +fritzbox_energy{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 8012 +# HELP fritzbox_power Current power (in W), refreshed approx every 2 minutes +# TYPE fritzbox_power gauge +fritzbox_power{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 0 +fritzbox_power{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 7 +fritzbox_power{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 0 +# HELP fritzbox_switch_boxlock Switching via FRITZ!Box disabled? 1/0, -1 if not known or error +# TYPE fritzbox_switch_boxlock gauge +fritzbox_switch_boxlock{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_boxlock{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_boxlock{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_boxlock{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200"} 1 +# HELP fritzbox_switch_devicelock Switching via device disabled 1/0, -1 if not known or error +# TYPE fritzbox_switch_devicelock gauge +fritzbox_switch_devicelock{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_devicelock{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_devicelock{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_devicelock{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200"} 1 +# HELP fritzbox_switch_mode Switch mode 1/0 (manual/automatic), -1 if not known or error +# TYPE fritzbox_switch_mode gauge +fritzbox_switch_mode{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 1 +fritzbox_switch_mode{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 1 +fritzbox_switch_mode{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 1 +fritzbox_switch_mode{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200"} 1 +# HELP fritzbox_switch_state Switch state 1/0 (on/off), -1 if not known or error +# TYPE fritzbox_switch_state gauge +fritzbox_switch_state{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_state{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 1 +fritzbox_switch_state{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 0 +fritzbox_switch_state{device_id="ALWAYS FAILZ",device_name="SWITCH_4_FAILING",device_type="FRITZ!DECT 200"} 0 +# HELP fritzbox_temperature Temperature measured at the device sensor in units of 0.1 °C +# TYPE fritzbox_temperature gauge +fritzbox_temperature{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 21 +fritzbox_temperature{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 19.5 +fritzbox_temperature{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 22.5 +fritzbox_temperature{device_id="44363 2777777",device_name="HKR_1",device_type="Comet DECT"} 20 +fritzbox_temperature{device_id="55555 2777777",device_name="HKR_2",device_type="Comet DECT"} 20 +fritzbox_temperature{device_id="55555 2777777",device_name="HKR_3",device_type="Comet DECT"} 21 +# HELP fritzbox_temperature_offset Temperature offset (set by the user) in units of 0.1 °C +# TYPE fritzbox_temperature_offset gauge +fritzbox_temperature_offset{device_id="12324 2131421",device_name="SWITCH_1",device_type="FRITZ!DECT 200"} 0 +fritzbox_temperature_offset{device_id="12324 2211244",device_name="SWITCH_2",device_type="FRITZ!DECT 200"} 1 +fritzbox_temperature_offset{device_id="12524 2211244",device_name="SWITCH_3",device_type="FRITZ!DECT 200"} 0 +fritzbox_temperature_offset{device_id="44363 2777777",device_name="HKR_1",device_type="Comet DECT"} 0 +fritzbox_temperature_offset{device_id="55555 2777777",device_name="HKR_2",device_type="Comet DECT"} 0 +fritzbox_temperature_offset{device_id="55555 2777777",device_name="HKR_3",device_type="Comet DECT"} 0.2