Merge branch 'master' into v2-authentication

This commit is contained in:
sberk42
2023-10-15 09:45:13 +02:00
committed by GitHub
7 changed files with 4114 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1
# Build Image
FROM golang:1.19-alpine3.17 AS builder
FROM golang:1.21-alpine3.18 AS builder
RUN go install github.com/sberk42/fritzbox_exporter@latest \
&& mkdir /app \
&& mv /go/bin/fritzbox_exporter /app
@@ -11,7 +11,7 @@ WORKDIR /app
COPY metrics.json metrics-lua.json /app/
# Runtime Image
FROM alpine:3.17 as runtime-image
FROM alpine:3.18 as runtime-image
ARG REPO=sberk42/fritzbox_exporter

File diff suppressed because it is too large Load Diff

View File

@@ -24,7 +24,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
@@ -83,9 +83,9 @@ type LabelRename struct {
Name string
}
// regex to remove leading/training characters from numbers
// regex to remove leading/trailing characters from numbers
var (
regexNonNumberEnd = regexp.MustCompile("\\D+$")
regexNonNumberEnd = regexp.MustCompile(`\D+$`)
)
func (lua *LuaSession) v2Login(response string) error {
@@ -124,11 +124,11 @@ func (lua *LuaSession) doLogin(req *http.Request) error {
err = dec.Decode(&lua.SessionInfo)
if err != nil {
return fmt.Errorf("Error decoding SessionInfo: %s", err.Error())
return fmt.Errorf("error decoding SessionInfo: %s", err.Error())
}
if lua.SessionInfo.BlockTime > 0 {
return fmt.Errorf("To many failed logins, login blocked for %d seconds", lua.SessionInfo.BlockTime)
return fmt.Errorf("too many failed logins, login blocked for %d seconds", lua.SessionInfo.BlockTime)
}
return nil
}
@@ -269,7 +269,7 @@ func (lua *LuaSession) LoadData(page LuaPage) ([]byte, error) {
retries++
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err

14
go.mod
View File

@@ -1,11 +1,11 @@
module github.com/sberk42/fritzbox_exporter
go 1.19
go 1.21
require (
github.com/namsral/flag v1.7.4-pre
github.com/prometheus/client_golang v1.15.1
github.com/sirupsen/logrus v1.9.2
github.com/prometheus/client_golang v1.17.0
github.com/sirupsen/logrus v1.9.3
golang.org/x/crypto v0.14.0
golang.org/x/text v0.13.0
)
@@ -15,9 +15,9 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.43.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

27
go.sum
View File

@@ -11,22 +11,23 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
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/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 v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.43.0 h1:iq+BVjvYLei5f27wiuNiB1DN6DYQkp1c8Bx0Vykh5us=
github.com/prometheus/common v0.43.0/go.mod h1:NCvr5cQIh3Y/gy73/RdVtC9r8xxrxwJnB+2lB3BxrFc=
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -41,8 +42,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

21
main.go
View File

@@ -19,10 +19,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"regexp"
"sort"
"strconv"
@@ -456,7 +455,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
result, err := fc.getActionResult(m, m.Action, actArg)
if err != nil {
logrus.Error("Can not get result for %s: %s", m.Action, err)
logrus.Errorf("can not get result for %s: %s", m.Action, err)
collectErrors.Inc()
continue
}
@@ -656,7 +655,7 @@ func test() {
json.WriteString("\n]")
if *flagJSONOut != "" {
err := ioutil.WriteFile(*flagJSONOut, json.Bytes(), 0644)
err := os.WriteFile(*flagJSONOut, json.Bytes(), 0644)
if err != nil {
logrus.Warnf("Failed writing JSON file '%s': %s\n", *flagJSONOut, err.Error())
}
@@ -665,7 +664,7 @@ func test() {
func testLua() {
jsonData, err := ioutil.ReadFile("luaTest.json")
jsonData, err := os.ReadFile("luaTest.json")
if err != nil {
logrus.Error("Can not read luaTest.json: ", err)
return
@@ -688,7 +687,7 @@ func testLua() {
if err != nil {
logrus.Errorf("Testing %s (%s) failed: %s", test.Path, test.Params, err.Error())
} else {
logrus.Infof("Testing %s(%s) successful: %s", test.Path, test.Params, string(pageData))
logrus.Infof("Testing %s (%s) successful: %s", test.Path, test.Params, string(pageData))
}
}
}
@@ -717,7 +716,7 @@ func main() {
u, err := url.Parse(*flagGatewayURL)
if err != nil {
logrus.Errorf("invalid URL:", err)
logrus.Errorf("invalid URL: %s", err.Error())
return
}
@@ -758,15 +757,15 @@ func main() {
}
// read metrics
jsonData, err := ioutil.ReadFile(*flagMetricsFile)
jsonData, err := os.ReadFile(*flagMetricsFile)
if err != nil {
logrus.Errorf("error reading metric file:", err)
logrus.Errorf("error reading metric file: %s", err.Error())
return
}
err = json.Unmarshal(jsonData, &metrics)
if err != nil {
logrus.Errorf("error parsing JSON:", err)
logrus.Errorf("error parsing JSON: %s", err.Error())
return
}
@@ -776,7 +775,7 @@ func main() {
var luaSession *lua.LuaSession
var luaLabelRenames *[]lua.LabelRename
if !*flagDisableLua {
jsonData, err := ioutil.ReadFile(*flagLuaMetricsFile)
jsonData, err := os.ReadFile(*flagLuaMetricsFile)
if err != nil {
logrus.Error("error reading lua metric file:", err)
return

View File

@@ -8,6 +8,14 @@
"matchRegex": "16QAM",
"renameLabel": "16"
},
{
"matchRegex": "4096QAM",
"renameLabel": "4096"
},
{
"matchRegex": "256QAM",
"renameLabel": "256"
},
{
"matchRegex": "(?i)prozessor",
"renameLabel": "CPU"
@@ -19,7 +27,7 @@
{
"matchRegex": "(?i)DSL",
"renameLabel": "DSL"
},
},
{
"matchRegex": "(?i)FON",
"renameLabel": "Phone"
@@ -35,7 +43,7 @@
{
"matchRegex": "(?i)Speicher.*FRITZ",
"renameLabel": "Internal eStorage"
}
}
],
"metrics": [
{
@@ -47,27 +55,29 @@
"fqName": "gateway_cable_power_upstream",
"help": "docsis 3.0 power upstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
"resultPath": "data.channelUs.docsis30.*",
"resultKey": "type",
"resultKey": "modulation",
"promDesc": {
"fqName": "gateway_cable_modulation_upstream",
"help": "docsis 3.0 modulation upstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -77,12 +87,13 @@
"fqName": "gateway_cable_power_upstream31",
"help": "docsis 3.1 power upstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -92,12 +103,13 @@
"fqName": "gateway_cable_correctables_downstream",
"help": "docsis 3.0 correctable errors dpwnstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -107,12 +119,13 @@
"fqName": "gateway_cable_uncorrectables_downstream",
"help": "docsis 3.0 uncorrectable errors downstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -122,12 +135,13 @@
"fqName": "gateway_cable_mse_downstream",
"help": "docsis 3.0 mse downstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -137,12 +151,13 @@
"fqName": "gateway_cable_power_downstream",
"help": "docsis 3.0 powerlevel downstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=docInfo",
@@ -152,12 +167,13 @@
"fqName": "gateway_cable_power_downstream31",
"help": "docsis 3.1 powerlevel downstream from data.lua?page=docInfo",
"varLabels": [
"gateway", "frequency"
"gateway",
"frequency"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=energy",
@@ -167,12 +183,13 @@
"fqName": "gateway_data_energy_consumption",
"help": "percentage of energy consumed from data.lua?page=energy",
"varLabels": [
"gateway", "name"
"gateway",
"name"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=energy",
@@ -183,7 +200,8 @@
"fqName": "gateway_data_energy_lan_status",
"help": "status of LAN connection from data.lua?page=energy (1 = up)",
"varLabels": [
"gateway", "name"
"gateway",
"name"
]
},
"promType": "GaugeValue",
@@ -218,7 +236,7 @@
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=ecoStat",
@@ -231,7 +249,7 @@
"gateway"
],
"fixedLabels": {
"ram_type" : "Fixed"
"ram_type": "Fixed"
}
},
"promType": "GaugeValue",
@@ -249,7 +267,7 @@
"gateway"
],
"fixedLabels": {
"ram_type" : "Dynamic"
"ram_type": "Dynamic"
}
},
"promType": "GaugeValue",
@@ -267,12 +285,12 @@
"gateway"
],
"fixedLabels": {
"ram_type" : "Free"
"ram_type": "Free"
}
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
},
},
{
"path": "data.lua",
"params": "page=usbOv",
@@ -282,7 +300,9 @@
"fqName": "gateway_data_usb_storage_total",
"help": "total storage in bytes from data.lua?page=usbOv",
"varLabels": [
"gateway", "deviceType", "deviceName"
"gateway",
"deviceType",
"deviceName"
]
},
"promType": "GaugeValue",
@@ -297,12 +317,13 @@
"fqName": "gateway_data_usb_storage_used",
"help": "used storage in bytes from data.lua?page=usbOv",
"varLabels": [
"gateway", "deviceType", "deviceName"
"gateway",
"deviceType",
"deviceName"
]
},
"promType": "GaugeValue",
"cacheEntryTTL": 300
}
}
]
}
}