From 429aae863cbc6ff4664fd4afad0adc86e4c36c3b Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 10 Jan 2025 19:08:21 +0100 Subject: [PATCH 01/12] feat(inputs.fritzbox): Initial implementation --- EXTERNAL_PLUGINS.md | 1 - docs/LICENSE_OF_DEPENDENCIES.md | 1 + go.mod | 1 + go.sum | 14 + plugins/inputs/all/fritzbox.go | 5 + plugins/inputs/fritzbox/README.md | 177 +++ plugins/inputs/fritzbox/fritzbox.go | 471 +++++++ plugins/inputs/fritzbox/fritzbox_test.go | 204 +++ plugins/inputs/fritzbox/sample.conf | 39 + .../inputs/fritzbox/testdata/DeviceInfo.xml | 19 + plugins/inputs/fritzbox/testdata/Hosts.xml | 8 + .../testdata/WANCommonInterfaceConfig1.xml | 15 + .../testdata/WANCommonInterfaceConfig2.xml | 24 + .../testdata/WANDSLInterfaceConfig.xml | 39 + .../fritzbox/testdata/WANPPPConnection.xml | 38 + .../fritzbox/testdata/WLANConfiguration.xml | 30 + .../inputs/fritzbox/testdata/dummySCPD.xml | 4 + .../inputs/fritzbox/testdata/fritzbox.conf | 38 + plugins/inputs/fritzbox/testdata/igddesc.xml | 13 + .../inputs/fritzbox/testdata/meshlist.json | 1177 +++++++++++++++++ plugins/inputs/fritzbox/testdata/tr64desc.xml | 43 + 21 files changed, 2360 insertions(+), 1 deletion(-) create mode 100644 plugins/inputs/all/fritzbox.go create mode 100644 plugins/inputs/fritzbox/README.md create mode 100644 plugins/inputs/fritzbox/fritzbox.go create mode 100644 plugins/inputs/fritzbox/fritzbox_test.go create mode 100644 plugins/inputs/fritzbox/sample.conf create mode 100644 plugins/inputs/fritzbox/testdata/DeviceInfo.xml create mode 100644 plugins/inputs/fritzbox/testdata/Hosts.xml create mode 100644 plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml create mode 100644 plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml create mode 100644 plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml create mode 100644 plugins/inputs/fritzbox/testdata/WANPPPConnection.xml create mode 100644 plugins/inputs/fritzbox/testdata/WLANConfiguration.xml create mode 100644 plugins/inputs/fritzbox/testdata/dummySCPD.xml create mode 100644 plugins/inputs/fritzbox/testdata/fritzbox.conf create mode 100644 plugins/inputs/fritzbox/testdata/igddesc.xml create mode 100644 plugins/inputs/fritzbox/testdata/meshlist.json create mode 100644 plugins/inputs/fritzbox/testdata/tr64desc.xml diff --git a/EXTERNAL_PLUGINS.md b/EXTERNAL_PLUGINS.md index 5463ef9201c79..778fc0691b724 100644 --- a/EXTERNAL_PLUGINS.md +++ b/EXTERNAL_PLUGINS.md @@ -28,7 +28,6 @@ Pull requests welcome. - [db2](https://github.com/bonitoo-io/telegraf-input-db2) - Gather the statistic data from DB2 RDBMS - [apt](https://github.com/x70b1/telegraf-apt) - Check Debian for package updates. - [knot](https://github.com/x70b1/telegraf-knot) - Collect stats from Knot DNS. -- [fritzbox](https://github.com/hdecarne-github/fritzbox-telegraf-plugin) - Gather statistics from [FRITZ!Box](https://avm.de/produkte/fritzbox/) router and repeater - [linux-psi-telegraf-plugin](https://github.com/gridscale/linux-psi-telegraf-plugin) - Gather pressure stall information ([PSI](https://facebookmicrosites.github.io/psi/)) from the Linux Kernel - [huebridge](https://github.com/hdecarne-github/huebridge-telegraf-plugin) - Gather smart home statistics from [Hue Bridge](https://www.philips-hue.com/) devices - [nsdp](https://github.com/hdecarne-github/nsdp-telegraf-plugin) - Gather switch network statistics via [Netgear Switch Discovery Protocol](https://en.wikipedia.org/wiki/Netgear_Switch_Discovery_Protocol) diff --git a/docs/LICENSE_OF_DEPENDENCIES.md b/docs/LICENSE_OF_DEPENDENCIES.md index b8994365b6154..88befb1c8760f 100644 --- a/docs/LICENSE_OF_DEPENDENCIES.md +++ b/docs/LICENSE_OF_DEPENDENCIES.md @@ -362,6 +362,7 @@ following works: - github.com/stoewer/go-strcase [MIT License](https://github.com/stoewer/go-strcase/blob/master/LICENSE) - github.com/stretchr/objx [MIT License](https://github.com/stretchr/objx/blob/master/LICENSE) - github.com/stretchr/testify [MIT License](https://github.com/stretchr/testify/blob/master/LICENSE) +- github.com/tdrn-org/go-tr064 [Apache License 2.0](https://github.com/tdrn-org/go-tr064/blob/main/LICENSE) - github.com/testcontainers/testcontainers-go [MIT License](https://github.com/testcontainers/testcontainers-go/blob/main/LICENSE) - github.com/thomasklein94/packer-plugin-libvirt [Mozilla Public License 2.0](https://github.com/thomasklein94/packer-plugin-libvirt/blob/main/LICENSE) - github.com/tidwall/gjson [MIT License](https://github.com/tidwall/gjson/blob/master/LICENSE) diff --git a/go.mod b/go.mod index 27e54af0c7586..e9e644f7a434e 100644 --- a/go.mod +++ b/go.mod @@ -471,6 +471,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/tdrn-org/go-tr064 v0.2.0 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/tinylru v1.2.1 // indirect diff --git a/go.sum b/go.sum index ba6c4e2b06eeb..e687bba59837e 100644 --- a/go.sum +++ b/go.sum @@ -2321,6 +2321,20 @@ github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7 h1:Jtcrb09q0AVWe3 github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7/go.mod h1:suDIky6yrK07NnaBadCB4sS0CqFOvUK91lH7CR+JlDA= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw= +github.com/tdrn-org/go-tr064 v0.1.6 h1:5Y/1/VzkQws8LAxWeKW8bH6FcAMToQQTBsqkItR+zY0= +github.com/tdrn-org/go-tr064 v0.1.6/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.1.7 h1:YdKRg9OG4aAppIiWfDqOC5g/6LCOXWMIkdOz5y9tts4= +github.com/tdrn-org/go-tr064 v0.1.7/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.1.8 h1:9bvf85Pa30pcrlYHsgZUZ54aGu0UCj+U7K9jroGSLsU= +github.com/tdrn-org/go-tr064 v0.1.8/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.1.9 h1:HGRiBsgvmSlFxcnlVVllMRewrHKpQFq0O13bEvwfaSQ= +github.com/tdrn-org/go-tr064 v0.1.9/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.1.10 h1:TIU7P+KoxBpjyQ6B7H9Yf4DxDK/6td6tc4lZNasYQwc= +github.com/tdrn-org/go-tr064 v0.1.10/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.1.11 h1:LFjJjfU7NdGXnqrNZ+dxaxCt4EndJISknTL1VGNcGBY= +github.com/tdrn-org/go-tr064 v0.1.11/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.2.0 h1:n2Dz8UdUlZm8jS0coiXl6eRVB4qSz8fcbrHJhPyNVfk= +github.com/tdrn-org/go-tr064 v0.2.0/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0= github.com/testcontainers/testcontainers-go v0.34.0 h1:5fbgF0vIN5u+nD3IWabQwRybuB4GY8G2HHgCkbMzMHo= github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNulFGdFHTD8HB2vLq/231xY2iPQ= diff --git a/plugins/inputs/all/fritzbox.go b/plugins/inputs/all/fritzbox.go new file mode 100644 index 0000000000000..56a4af0209c2c --- /dev/null +++ b/plugins/inputs/all/fritzbox.go @@ -0,0 +1,5 @@ +//go:build !custom || inputs || inputs.fritzbox + +package all + +import _ "github.com/influxdata/telegraf/plugins/inputs/fritzbox" // register plugin diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md new file mode 100644 index 0000000000000..481f2492e3287 --- /dev/null +++ b/plugins/inputs/fritzbox/README.md @@ -0,0 +1,177 @@ +# Fritzbox Input Plugin + +This input plugin gathers status from [AVM][1] devices (routers, repeaters, +...). It uses the device's [TR-064][2] interfaces to retrieve the status. + +[1]: https://avm.de/ +[2]: https://avm.de/service/schnittstellen/ + +Retrieved status are: + +- Device info (model, HW/SW version, uptime, ...) +- WAN info (bit rates, transferred bytes, ...) +- PPP info (bit rates, connection uptime, ...) +- DSL info (bit rates, DSL statistics, ...) +- WLAN info (numbrer of clients per network, ...) +- Hosts info (mesh nodes, bit rates, ...) + +## Global configuration options + +In addition to the plugin-specific configuration settings, plugins support +additional global and plugin configuration settings. These settings are used to +modify metrics, tags, and field or create aliases and configure ordering, etc. +See the [CONFIGURATION.md][CONFIGURATION.md] for more details. + +[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins + +## Configuration + +```toml @sample.conf +# Gather fritzbox status +[[inputs.fritzbox]] + ## The devices to query. For each device the corresponding URL including the + ## user and passwort needed to login must be set. + ## E.g. + ## devices = [ + ## "http://boxuser:boxpassword@fritz.box:49000/", + ## "http://:repeaterpassword@fritz.repeater:49000/", + ## ] + devices = [ + ] + + ## The information to query (see README for further details). + ## Hosts info is disabled by default, as it generates an extensive amount + ## of data. + # device_info = true + # wan_info = true + # ppp_info = true + # dsl_info = true + # wlan_info = true + # hosts_info = false + + ## Some metric queries are time-consuming and not collected on every query + ## cycle. This counter defines how often these low-traffic queries + ## are excuted. The default value 30 means, on every 30th query corresponding + ## to every 5 minutes (assuming the standard query interval of 10s). + ## If this option is set to 1 or below, all metrics are collected on every + ## query cycle. + # full_query_cycle = 30 + + ## The http timeout to use. + # timeout = "10s" + + ## Skip TLS verification. Is needed to query devices with the default + ## self-signed certificate. + # tls_skip_verify = false + + ## Enable debug output + # debug = false +``` + +## Metrics + +By default field names are directly derived from the corresponding [interface +specification][1]. + +- `fritzbox_device` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - fields + - `uptime` (uint) - Device's uptime in seconds. + - `model_name` (string) - Device's model name. + - `serial_number` (string) - Device's serial number. + - `hardware_version` (string) - Device's hardware version. + - `software_version` (string) - Device's software version. +- `fritzbox_wan` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - fields + - `layer1_upstream_max_bit_rate` (uint) - The WAN interface's maximum upstream bit rate (bits/sec) + - `layer1_downstream_max_bit_rate` (uint) - The WAN interface's maximum downstream bit rate (bits/sec) + - `upstream_current_max_speed` (uint) - The WAN interface's current maximum upstream transfer rate (bytes/sec) + - `downstream_current_max_speed` (uint) - The WAN interface's current maximum downstream data rate (bytes/sec) + - `total_bytes_sent` (uint) - The total number of bytes sent via the WAN interface (bytes) + - `total_bytes_received` (uint) - The total number of bytes received via the WAN interface (bytes) +- `fritzbox_ppp` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - fields + - `uptime` (uint) - The current uptime of the PPP connection in seconds + - `upstream_max_bit_rate` (uint) - The current maximum upstream bit rate negotiated for the PPP connection (bits/sec) + - `downstream_max_bit_rate` (uint) - The current maximum downstream bit rate negotiated for the PPP connection (bits/sec) +- `fritzbox_dsl` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - fields + - `upstream_curr_rate` (uint) - Current DSL upstream rate (kilobits/sec) + - `downstream_curr_rate` (uint) - Current DSL downstream rate (kilobits/sec) + - `upstream_max_rate` (uint) - Maximum DSL upstream rate (kilobits/sec) + - `downstream_max_rate` (uint) - Maximum DSL downstream rate (kilobits/sec) + - `upstream_noise_margin` (uint) - Upstream noise margin (db) + - `downstream_noise_margin` (uint) - Downstream noise margin (db) + - `upstream_attenuation` (uint) - Upstream attenuation (db) + - `downstream_attenuation` (uint) - Downstream attenuation (db) + - `upstream_power` (uint) - Upstream power + - `downstream_power` (uint) - Downstream power + - `receive_blocks` (uint) - Received blocks + - `transmit_blocks` (uint) - Transmitted blocks + - `cell_delin` (uint) - Cell delineation count + - `link_retrain` (uint) - Link retrains + - `init_errors` (uint) - Initialization errors + - `init_timeouts` (uint) - Initialization timeouts + - `loss_of_framing` (uint) - Loss of frame errors + - `errored_secs` (uint) - Continuous seconds with errors + - `severly_errored_secs` (uint) - Continuous seconds with severe errors + - `fec_errors` (uint) - Local (Modem) FEC (Forward Error Correction) errors + - `atuc_fec_errors` (uint) - Remote (DSLAM) FEC (Forward Error Correction) errors + - `hec_errors` (uint) - Local (Modem) HEC (Header Error Control) errors + - `atuc_hec_errors` (uint) - Remote (DSLAM) HEC (Header Error Control) errors + - `crc_errors` (uint) - Local (Modem) CRC (Cyclic Redundancy Check) error + - `atuc_crc_errors` (uint) - Remote (DSLAM) CRC (Cyclic Redundancy Check) errors +- `fritzbox_wlan` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - `fritz_wlan` - The WLAN SSID (name) + - `fritz_wlan_channel` - The channel used by this WLAN + - `fritz_wlan_band` - The band (in MHz) used by this WLAN + - fields + - `total_associations` (uint) - The number of devices connected to this WLAN. +- `fritzbox_host` + - tags + - `fritz_device` - The device name (this metric has been queried from) + - `fritz_service` - The service id used to query this metric + - `fritz_host` - The host connected to the network + - `fritz_host_role` - The host's role ("master" = mesh master, "slave" = mesh slave, "client") in the network + - `fritz_host_peer` - The name of the peer this host is connected to + - `fritz_host_peer_role` - The peer's role ("master" = mesh master, "slave" = mesh slave, never "client") in the network + - `fritz_link_type` - The link type ("WLAN" or "LAN") of the peer connection + - `fritz_link_name` - The link name of the connection + - fields + - `max_data_rate_tx` (uint) - The connection's maximum transmit rate (kilobits/sec) + - `max_data_rate_rx` (uint) - The connection's maximum receive rate (kilobits/sec) + - `cur_data_rate_tx` (uint) - The connection's maximum transmit rate (kilobits/sec) + - `cur_data_rate_rx` (uint) - The connection's current receive rate (kilobits/sec) + +## Example Output + + +```text +fritzbox_device,fritz_device=127.0.0.1,fritz_service=DeviceInfo1 model_name=Mock 1234,serial_number=123456789,hardware_version=Mock 1234,software_version=1.02.03,uptime=2058438 1736529975 + +fritzbox_wan,fritz_device=127.0.0.1,fritz_service=WANCommonInterfaceConfig1 total_bytes_received=554484531337,layer1_upstream_max_bit_rate=48816000,layer1_downstream_max_bit_rate=253247000,upstream_current_max_speed=511831,downstream_current_max_speed=1304268,total_bytes_sent=129497283207 1736530024 + +fritzbox_ppp,fritz_device=127.0.0.1,fritz_service=WANPPPConnection1 uptime=369434,upstream_max_bit_rate=44213433,downstream_max_bit_rate=68038668 1736530058 + +fritzbox_dsl,fritz_device=127.0.0.1,fritz_service=WANDSLInterfaceConfig1 downstream_noise_margin=60,upstream_power=498,downstream_power=513,upstream_curr_rate=46719,downstream_curr_rate=249065,upstream_max_rate=48873,downstream_max_rate=249065,upstream_noise_margin=80,severly_errored_secs=0,upstream_attenuation=80,transmit_blocks=254577751,init_timeouts=0,atuc_crc_errors=13,receive_blocks=490282831,errored_secs=25,fec_errors=0,atuc_hec_errors=0,atuc_fec_errors=0,hec_errors=0,crc_errors=53,downstream_attenuation=140,cell_delin=0,link_retrain=2,init_errors=0,loss_of_framing=0 1736530092 + +fritzbox_wlan,fritz_device=127.0.0.1,fritz_service=WLANConfiguration1,fritz_wlan=MOCK1234,fritz_wlan_channel=13,fritz_wlan_band=2400 total_associations=11 1736530130 + +fritzbox_host,fritz_host_peer_role=master,fritz_link_type=WLAN,fritz_link_name=AP:2G:0,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#17,fritz_host_role=slave,fritz_host_peer=device#1 max_data_rate_tx=216000,max_data_rate_rx=216000,cur_data_rate_tx=216000,cur_data_rate_rx=216000 1736530165 +fritzbox_host,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#24,fritz_host_role=client,fritz_host_peer=device#17,fritz_host_peer_role=slave,fritz_link_type=LAN,fritz_link_name=LAN:1 cur_data_rate_tx=0,cur_data_rate_rx=0,max_data_rate_tx=1000000,max_data_rate_rx=1000000 1736530165 +``` +. diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go new file mode 100644 index 0000000000000..7b92334a39dd9 --- /dev/null +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -0,0 +1,471 @@ +//go:generate ../../../tools/readme_config_includer/generator +package fritzbox + +import ( + _ "embed" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strconv" + "strings" + "time" + + "github.com/google/uuid" + "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/config" + "github.com/influxdata/telegraf/logger" + "github.com/influxdata/telegraf/plugins/inputs" + "github.com/tdrn-org/go-tr064" + "github.com/tdrn-org/go-tr064/mesh" + "github.com/tdrn-org/go-tr064/services/igddesc/igdicfg" + "github.com/tdrn-org/go-tr064/services/tr64desc/deviceinfo" + "github.com/tdrn-org/go-tr064/services/tr64desc/hosts" + "github.com/tdrn-org/go-tr064/services/tr64desc/wancommonifconfig" + "github.com/tdrn-org/go-tr064/services/tr64desc/wandslifconfig" + "github.com/tdrn-org/go-tr064/services/tr64desc/wanpppconn" + "github.com/tdrn-org/go-tr064/services/tr64desc/wlanconfig" +) + +//go:embed sample.conf +var sampleConfig string + +const pluginName = "fritzbox" + +const defaultTimeout = config.Duration(10 * time.Second) + +type Fritzbox struct { + Devices []string `toml:"devices"` + DeviceInfo bool `toml:"device_info"` + WanInfo bool `toml:"wan_info"` + PppInfo bool `toml:"ppp_info"` + DslInfo bool `toml:"dsl_info"` + WlanInfo bool `toml:"wlan_info"` + HostsInfo bool `toml:"hosts_info"` + FullQueryCycle int `toml:"full_query_cycle"` + Timeout config.Duration `toml:"timeout"` + TlsSkipVerify bool `toml:"tls_skip_verify"` + Debug bool `toml:"debug"` + Log telegraf.Logger `toml:"-"` + deviceClients []*tr064.Client + serviceHandlers map[string]serviceHandlerFunc + queryCycleCounter int +} + +func defaultFritzbox() *Fritzbox { + return &Fritzbox{ + Devices: make([]string, 0), + DeviceInfo: true, + WanInfo: true, + PppInfo: true, + DslInfo: true, + WlanInfo: true, + HostsInfo: false, + FullQueryCycle: 30, + Timeout: defaultTimeout, + deviceClients: make([]*tr064.Client, 0), + serviceHandlers: make(map[string]serviceHandlerFunc), + queryCycleCounter: 0, + } +} + +func (*Fritzbox) SampleConfig() string { + return sampleConfig +} + +func (plugin *Fritzbox) Init() error { + if plugin.Log == nil { + plugin.Log = logger.New("inputs", pluginName, "") + } + err := plugin.initDeviceClients() + if err != nil { + return err + } + plugin.initServiceHandlers() + return nil +} + +func (plugin *Fritzbox) initDeviceClients() error { + for _, device := range plugin.Devices { + deviceUrl, err := url.Parse(device) + if err != nil { + return err + } + client := tr064.NewClient(deviceUrl) + client.Debug = plugin.Debug + client.Timeout = time.Duration(plugin.Timeout) + client.InsecureSkipVerify = plugin.TlsSkipVerify + plugin.deviceClients = append(plugin.deviceClients, client) + } + return nil +} + +func (plugin *Fritzbox) initServiceHandlers() { + if plugin.DeviceInfo { + plugin.serviceHandlers[deviceinfo.ServiceShortType] = plugin.gatherDeviceInfo + } + if plugin.WanInfo { + plugin.serviceHandlers[wancommonifconfig.ServiceShortType] = plugin.gatherWanInfo + } + if plugin.PppInfo { + plugin.serviceHandlers[wanpppconn.ServiceShortType] = plugin.gatherPppInfo + } + if plugin.DslInfo { + plugin.serviceHandlers[wandslifconfig.ServiceShortType] = plugin.gatherDslInfo + } + if plugin.WlanInfo { + plugin.serviceHandlers[wlanconfig.ServiceShortType] = plugin.gatherWlanInfo + } + if plugin.HostsInfo { + plugin.serviceHandlers[hosts.ServiceShortType] = plugin.gatherHostsInfo + } +} + +func (plugin *Fritzbox) Gather(acc telegraf.Accumulator) error { + start := time.Now() + for _, deviceClient := range plugin.deviceClients { + plugin.gatherDevice(acc, deviceClient) + } + if plugin.Debug { + elapsed := time.Since(start) + plugin.Log.Info("took: ", elapsed) + } + plugin.queryCycleCounter++ + if plugin.queryCycleCounter >= plugin.FullQueryCycle { + plugin.queryCycleCounter = 0 + } + return nil +} + +func (plugin *Fritzbox) gatherDevice(acc telegraf.Accumulator, deviceClient *tr064.Client) { + if plugin.Debug { + plugin.Log.Infof("Querying %s", deviceClient.DeviceUrl.Redacted()) + } + services, err := deviceClient.Services(tr064.DefaultServiceSpec) + if err != nil { + acc.AddError(err) + return + } + for _, service := range services { + serviceHandler := plugin.serviceHandlers[service.ShortType()] + if serviceHandler == nil { + continue + } + err := serviceHandler(acc, deviceClient, service) + if err != nil { + acc.AddError(err) + return + } + } +} + +type serviceHandlerFunc func(telegraf.Accumulator, *tr064.Client, tr064.ServiceDescriptor) error + +func (plugin *Fritzbox) gatherDeviceInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + serviceClient := deviceinfo.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + info := &deviceinfo.GetInfoResponse{} + err := serviceClient.GetInfo(info) + if err != nil { + return err + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + fields := make(map[string]interface{}) + fields["uptime"] = info.NewUpTime + fields["model_name"] = info.NewModelName + fields["serial_number"] = info.NewSerialNumber + fields["hardware_version"] = info.NewHardwareVersion + fields["software_version"] = info.NewSoftwareVersion + acc.AddFields("fritzbox_device", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_device", tags, fields) + } + return nil +} + +func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + serviceClient := wancommonifconfig.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + commonLinkProperties := &wancommonifconfig.GetCommonLinkPropertiesResponse{} + err := serviceClient.GetCommonLinkProperties(commonLinkProperties) + if err != nil { + return err + } + // Use public IGD service instead of the WANCommonInfo one for total bytes stats, because IGD supports uint64 counters + igdServices, err := deviceClient.ServicesByType(tr064.IgdServiceSpec, "WANCommonInterfaceConfig") + if err != nil { + return err + } + if len(igdServices) == 0 { + return fmt.Errorf("") + } + igdServiceClient := &igdicfg.ServiceClient{ + TR064Client: deviceClient, + Service: igdServices[0], + } + addonInfos := &igdicfg.GetAddonInfosResponse{} + err = igdServiceClient.GetAddonInfos(addonInfos) + if err != nil { + return err + } + strconv.ParseUint(addonInfos.NewX_AVM_DE_TotalBytesSent64, 10, 64) + totalBytesSent, err := strconv.ParseUint(addonInfos.NewX_AVM_DE_TotalBytesSent64, 10, 64) + if err != nil { + return err + } + totalBytesReceived, err := strconv.ParseUint(addonInfos.NewX_AVM_DE_TotalBytesReceived64, 10, 64) + if err != nil { + return err + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + fields := make(map[string]interface{}) + fields["layer1_upstream_max_bit_rate"] = commonLinkProperties.NewLayer1UpstreamMaxBitRate + fields["layer1_downstream_max_bit_rate"] = commonLinkProperties.NewLayer1DownstreamMaxBitRate + fields["upstream_current_max_speed"] = commonLinkProperties.NewX_AVM_DE_UpstreamCurrentMaxSpeed + fields["downstream_current_max_speed"] = commonLinkProperties.NewX_AVM_DE_DownstreamCurrentMaxSpeed + fields["total_bytes_sent"] = totalBytesSent + fields["total_bytes_received"] = totalBytesReceived + acc.AddFields("fritzbox_wan", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_wan", tags, fields) + } + return nil +} + +func (plugin *Fritzbox) gatherPppInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + serviceClient := wanpppconn.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + info := &wanpppconn.GetInfoResponse{} + err := serviceClient.GetInfo(info) + if err != nil { + return err + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + fields := make(map[string]interface{}) + fields["uptime"] = info.NewUptime + fields["upstream_max_bit_rate"] = info.NewUpstreamMaxBitRate + fields["downstream_max_bit_rate"] = info.NewDownstreamMaxBitRate + acc.AddFields("fritzbox_ppp", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_ppp", tags, fields) + } + return nil +} + +func (plugin *Fritzbox) gatherDslInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + serviceClient := wandslifconfig.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + info := &wandslifconfig.GetInfoResponse{} + err := serviceClient.GetInfo(info) + if err != nil { + return err + } + if info.NewStatus != "Up" { + return nil + } + statisticsTotal := &wandslifconfig.GetStatisticsTotalResponse{} + err = serviceClient.GetStatisticsTotal(statisticsTotal) + if err != nil { + return err + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + fields := make(map[string]interface{}) + fields["upstream_curr_rate"] = info.NewUpstreamCurrRate + fields["downstream_curr_rate"] = info.NewDownstreamCurrRate + fields["upstream_max_rate"] = info.NewUpstreamMaxRate + fields["downstream_max_rate"] = info.NewDownstreamMaxRate + fields["upstream_noise_margin"] = info.NewUpstreamNoiseMargin + fields["downstream_noise_margin"] = info.NewDownstreamNoiseMargin + fields["upstream_attenuation"] = info.NewUpstreamAttenuation + fields["downstream_attenuation"] = info.NewDownstreamAttenuation + fields["upstream_power"] = info.NewUpstreamPower + fields["downstream_power"] = info.NewDownstreamPower + fields["receive_blocks"] = statisticsTotal.NewReceiveBlocks + fields["transmit_blocks"] = statisticsTotal.NewTransmitBlocks + fields["cell_delin"] = statisticsTotal.NewCellDelin + fields["link_retrain"] = statisticsTotal.NewLinkRetrain + fields["init_errors"] = statisticsTotal.NewInitErrors + fields["init_timeouts"] = statisticsTotal.NewInitTimeouts + fields["loss_of_framing"] = statisticsTotal.NewLossOfFraming + fields["errored_secs"] = statisticsTotal.NewErroredSecs + fields["severly_errored_secs"] = statisticsTotal.NewSeverelyErroredSecs + fields["fec_errors"] = statisticsTotal.NewFECErrors + fields["atuc_fec_errors"] = statisticsTotal.NewATUCFECErrors + fields["hec_errors"] = statisticsTotal.NewHECErrors + fields["atuc_hec_errors"] = statisticsTotal.NewATUCHECErrors + fields["crc_errors"] = statisticsTotal.NewCRCErrors + fields["atuc_crc_errors"] = statisticsTotal.NewATUCCRCErrors + acc.AddFields("fritzbox_dsl", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_dsl", tags, fields) + } + return nil +} + +func (plugin *Fritzbox) gatherWlanInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + serviceClient := wlanconfig.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + info := &wlanconfig.GetInfoResponse{} + err := serviceClient.GetInfo(info) + if err != nil { + return err + } + if info.NewStatus != "Up" { + return nil + } + totalAssociations := &wlanconfig.GetTotalAssociationsResponse{} + err = serviceClient.GetTotalAssociations(totalAssociations) + if err != nil { + return err + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + tags["fritz_wlan"] = info.NewSSID + tags["fritz_wlan_channel"] = strconv.Itoa(int(info.NewChannel)) + tags["fritz_wlan_band"] = plugin.wlanBandFromInfo(info) + fields := make(map[string]interface{}) + fields["total_associations"] = totalAssociations.NewTotalAssociations + acc.AddGauge("fritzbox_wlan", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_wlan", tags, fields) + } + return nil +} + +func (plugin *Fritzbox) wlanBandFromInfo(info *wlanconfig.GetInfoResponse) string { + band := info.NewX_AVM_DE_FrequencyBand + if band != "" { + return band + } + if 1 <= info.NewChannel && info.NewChannel <= 14 { + return "2400" + } + return "5000" +} + +func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { + if plugin.queryCycleCounter != 0 { + return nil + } + serviceClient := hosts.ServiceClient{ + TR064Client: deviceClient, + Service: service, + } + connections, err := plugin.fetchHostsConnections(&serviceClient) + if err != nil { + return err + } + for _, connection := range connections { + _, err = uuid.Parse(connection.RightDeviceName) + if err == nil { + continue + } + tags := make(map[string]string) + tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["fritz_service"] = serviceClient.Service.ShortId() + tags["fritz_host"] = connection.RightDeviceName + tags["fritz_host_role"] = plugin.hostRole(connection.RightMeshRole) + tags["fritz_host_peer"] = connection.LeftDeviceName + tags["fritz_host_peer_role"] = plugin.hostRole(connection.LeftMeshRole) + tags["fritz_link_type"] = connection.InterfaceType + tags["fritz_link_name"] = connection.InterfaceName + fields := make(map[string]interface{}) + fields["max_data_rate_tx"] = connection.MaxDataRateTx + fields["max_data_rate_rx"] = connection.MaxDataRateRx + fields["cur_data_rate_tx"] = connection.CurDataRateTx + fields["cur_data_rate_rx"] = connection.CurDataRateRx + acc.AddGauge("fritzbox_host", fields, tags) + if plugin.Debug { + plugin.logMetric("fritzbox_host", tags, fields) + } + } + return nil +} + +func (plugin *Fritzbox) hostRole(role string) string { + if role == "unknown" { + return "client" + } + return role +} + +func (plugin *Fritzbox) fetchHostsConnections(serviceClient *hosts.ServiceClient) ([]*mesh.Connection, error) { + meshListPath := &hosts.X_AVM_DE_GetMeshListPathResponse{} + err := serviceClient.X_AVM_DE_GetMeshListPath(meshListPath) + if err != nil { + return nil, err + } + meshListResponse, err := serviceClient.TR064Client.Get(meshListPath.NewX_AVM_DE_MeshListPath) + if err != nil { + return nil, err + } + if meshListResponse.StatusCode == http.StatusNotFound { + return make([]*mesh.Connection, 0), nil + } + if meshListResponse.StatusCode != http.StatusOK { + return nil, fmt.Errorf("failed to fetch mesh list '%s' (status: %s)", meshListPath.NewX_AVM_DE_MeshListPath, meshListResponse.Status) + } + defer meshListResponse.Body.Close() + meshListBytes, err := io.ReadAll(meshListResponse.Body) + if err != nil { + return nil, err + } + meshList := &mesh.List{} + err = json.Unmarshal(meshListBytes, meshList) + if err != nil { + return nil, err + } + return meshList.Connections(), nil +} + +func (plugin *Fritzbox) logMetric(name string, tags map[string]string, fields map[string]interface{}) { + buffer := strings.Builder{} + buffer.WriteString(name) + for tagKey, tagValue := range tags { + buffer.WriteRune(',') + buffer.WriteString(tagKey) + buffer.WriteRune('=') + buffer.WriteString(fmt.Sprint(tagValue)) + } + writeSpace := true + for fieldKey, fieldValue := range fields { + if writeSpace { + buffer.WriteRune(' ') + writeSpace = false + } else { + buffer.WriteRune(',') + } + buffer.WriteString(fieldKey) + buffer.WriteRune('=') + buffer.WriteString(fmt.Sprint(fieldValue)) + } + buffer.WriteRune(' ') + buffer.WriteString(fmt.Sprint(time.Now().Unix())) + plugin.Log.Info(buffer.String()) +} + +func init() { + inputs.Add(pluginName, func() telegraf.Input { + return defaultFritzbox() + }) +} diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go new file mode 100644 index 0000000000000..ee839ea6dc186 --- /dev/null +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -0,0 +1,204 @@ +package fritzbox + +import ( + "os" + "testing" + "time" + + "github.com/BurntSushi/toml" + "github.com/influxdata/telegraf/config" + "github.com/influxdata/telegraf/testutil" + "github.com/stretchr/testify/require" + "github.com/tdrn-org/go-tr064/mock" +) + +func TestInitDefaults(t *testing.T) { + plugin := defaultFritzbox() + err := plugin.Init() + require.NoError(t, err) + require.Equal(t, 0, len(plugin.Devices)) + require.True(t, plugin.DeviceInfo) + require.True(t, plugin.WanInfo) + require.True(t, plugin.PppInfo) + require.True(t, plugin.DslInfo) + require.True(t, plugin.WlanInfo) + require.False(t, plugin.HostsInfo) + require.Equal(t, 30, plugin.FullQueryCycle) + require.Equal(t, defaultTimeout, plugin.Timeout) + require.False(t, plugin.TlsSkipVerify) + require.False(t, plugin.Debug) + require.NotNil(t, plugin.Log) +} + +func TestConfig(t *testing.T) { + conf, err := os.ReadFile("testdata/fritzbox.conf") + require.NoError(t, err) + var plugin = defaultFritzbox() + err = toml.Unmarshal(conf, plugin) + require.NoError(t, err) + err = plugin.Init() + require.NoError(t, err) + require.Equal(t, 2, len(plugin.Devices)) + require.False(t, plugin.DeviceInfo) + require.False(t, plugin.WanInfo) + require.False(t, plugin.PppInfo) + require.False(t, plugin.DslInfo) + require.False(t, plugin.WlanInfo) + require.True(t, plugin.HostsInfo) + require.Equal(t, 6, plugin.FullQueryCycle) + require.Equal(t, config.Duration(60*time.Second), plugin.Timeout) + require.True(t, plugin.TlsSkipVerify) + require.True(t, plugin.Debug) +} + +var testMocks = []*mock.ServiceMock{ + mock.ServiceMockFromFile("/deviceinfo", "testdata/DeviceInfo.xml"), + mock.ServiceMockFromFile("/wancommonifconfig", "testdata/WANCommonInterfaceConfig1.xml"), + mock.ServiceMockFromFile("/WANCommonIFC1", "testdata/WANCommonInterfaceConfig2.xml"), + mock.ServiceMockFromFile("/wanpppconn", "testdata/WANPPPConnection.xml"), + mock.ServiceMockFromFile("/wandslifconfig", "testdata/WANDSLInterfaceConfig.xml"), + mock.ServiceMockFromFile("/wlanconfig", "testdata/WLANConfiguration.xml"), + mock.ServiceMockFromFile("/hosts", "testdata/Hosts.xml"), +} + +func TestGatherDeviceInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = true + plugin.WanInfo = false + plugin.PppInfo = false + plugin.DslInfo = false + plugin.WlanInfo = false + plugin.HostsInfo = false + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_device", []string{"fritz_device", "fritz_service"}, []string{"uptime", "model_name", "serial_number", "hardware_version", "software_version"}) +} + +func TestGatherWanInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = false + plugin.WanInfo = true + plugin.PppInfo = false + plugin.DslInfo = false + plugin.WlanInfo = false + plugin.HostsInfo = false + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_wan", []string{"fritz_device", "fritz_service"}, []string{"layer1_upstream_max_bit_rate", "layer1_downstream_max_bit_rate", "upstream_current_max_speed", "downstream_current_max_speed", "total_bytes_sent", "total_bytes_received"}) +} + +func TestGatherPppInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = false + plugin.WanInfo = false + plugin.PppInfo = true + plugin.DslInfo = false + plugin.WlanInfo = false + plugin.HostsInfo = false + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_ppp", []string{"fritz_device", "fritz_service"}, []string{"uptime", "upstream_max_bit_rate", "downstream_max_bit_rate"}) +} + +func TestGatherDslInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = false + plugin.WanInfo = false + plugin.PppInfo = false + plugin.DslInfo = true + plugin.WlanInfo = false + plugin.HostsInfo = false + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_dsl", []string{"fritz_device", "fritz_service"}, []string{"upstream_curr_rate", "downstream_curr_rate", "upstream_max_rate", "downstream_max_rate", "upstream_noise_margin", "downstream_noise_margin", "upstream_attenuation", "downstream_attenuation", "upstream_power", "downstream_power", "receive_blocks", "transmit_blocks", "cell_delin", "link_retrain", "init_errors", "init_timeouts", "loss_of_framing", "errored_secs", "severly_errored_secs", "fec_errors", "atuc_fec_errors", "hec_errors", "atuc_hec_errors", "crc_errors", "atuc_crc_errors"}) +} + +func TestGatherWlanInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = false + plugin.WanInfo = false + plugin.PppInfo = false + plugin.DslInfo = false + plugin.WlanInfo = true + plugin.HostsInfo = false + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_wlan", []string{"fritz_device", "fritz_service", "fritz_wlan_channel", "fritz_wlan_band"}, []string{"total_associations"}) +} + +func TestGatherHostsInfo(t *testing.T) { + // Start mock server + tr064Server := mock.Start("testdata", testMocks...) + defer tr064Server.Shutdown() + // Actual test + plugin := defaultFritzbox() + plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.DeviceInfo = false + plugin.WanInfo = false + plugin.PppInfo = false + plugin.DslInfo = false + plugin.WlanInfo = false + plugin.HostsInfo = true + plugin.Debug = true + err := plugin.Init() + require.NoError(t, err) + acc := &testutil.Accumulator{} + err = acc.GatherError(plugin.Gather) + require.NoError(t, err) + testMeasurement(t, acc, "fritzbox_host", []string{"fritz_device", "fritz_service", "fritz_host", "fritz_host_role", "fritz_host_peer", "fritz_host_peer_role", "fritz_link_type", "fritz_link_name"}, []string{"max_data_rate_tx", "max_data_rate_rx", "cur_data_rate_tx", "cur_data_rate_rx"}) +} + +func testMeasurement(t *testing.T, acc *testutil.Accumulator, measurement string, tags []string, fields []string) { + require.Truef(t, acc.HasMeasurement(measurement), "measurement: %s", measurement) + for _, tag := range tags { + require.Truef(t, acc.HasTag(measurement, tag), "measurement: %s tag: %s", measurement, tag) + } + for _, field := range fields { + require.True(t, acc.HasField(measurement, field), "measurement: %s field: %s", measurement, field) + } +} diff --git a/plugins/inputs/fritzbox/sample.conf b/plugins/inputs/fritzbox/sample.conf new file mode 100644 index 0000000000000..7fc1d68810b72 --- /dev/null +++ b/plugins/inputs/fritzbox/sample.conf @@ -0,0 +1,39 @@ +# Gather fritzbox status +[[inputs.fritzbox]] + ## The devices to query. For each device the corresponding URL including the + ## user and passwort needed to login must be set. + ## E.g. + ## devices = [ + ## "http://boxuser:boxpassword@fritz.box:49000/", + ## "http://:repeaterpassword@fritz.repeater:49000/", + ## ] + devices = [ + ] + + ## The information to query (see README for further details). + ## Hosts info is disabled by default, as it generates an extensive amount + ## of data. + # device_info = true + # wan_info = true + # ppp_info = true + # dsl_info = true + # wlan_info = true + # hosts_info = false + + ## Some metric queries are time-consuming and not collected on every query + ## cycle. This counter defines how often these low-traffic queries + ## are excuted. The default value 30 means, on every 30th query corresponding + ## to every 5 minutes (assuming the standard query interval of 10s). + ## If this option is set to 1 or below, all metrics are collected on every + ## query cycle. + # full_query_cycle = 30 + + ## The http timeout to use. + # timeout = "10s" + + ## Skip TLS verification. Is needed to query devices with the default + ## self-signed certificate. + # tls_skip_verify = false + + ## Enable debug output + # debug = false diff --git a/plugins/inputs/fritzbox/testdata/DeviceInfo.xml b/plugins/inputs/fritzbox/testdata/DeviceInfo.xml new file mode 100644 index 0000000000000..3d3ad9dc74e02 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/DeviceInfo.xml @@ -0,0 +1,19 @@ + + + + +AVM +00000E +Mock 1234 +Mock 1234 Release 1.02.03 +MOCK1234 +123456789 +1.02.03 +Mock 1234 +1.0 +000.000.000.000 +2058438 + + + + diff --git a/plugins/inputs/fritzbox/testdata/Hosts.xml b/plugins/inputs/fritzbox/testdata/Hosts.xml new file mode 100644 index 0000000000000..cde36d58d3c4f --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/Hosts.xml @@ -0,0 +1,8 @@ + + + + +/meshlist.json?sid=123456789abcdef + + + diff --git a/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml b/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml new file mode 100644 index 0000000000000..3504187308da5 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml @@ -0,0 +1,15 @@ + + + + +DSL +48816000 +253247000 +Up +281672,1069998,122887,154143,335464,376641,201036,1046752,1304268,117397,42277,54058,41911,193162,372545,232857,661911,884903,35486,43050 +100417,76139,389328,217575,68110,49200,248209,122899,83175,466221,511831,491191,372128,192963,269890,222214,41261,56576,328630,388027 +1304268 +511831 + + + diff --git a/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml b/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml new file mode 100644 index 0000000000000..43538f62670bb --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml @@ -0,0 +1,24 @@ + + + + +178 +10893 +0 +0 +648264327 +433750153 +0 +1 +0.0.0.0 +0.0.0.0 +0.0.0.0 +0.0.0.0 +0 +1 +129497283207 +554484531337 +DSL + + + diff --git a/plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml b/plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml new file mode 100644 index 0000000000000..34ca377ceaf8c --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml @@ -0,0 +1,39 @@ + + + + +1 +Up +Fast +46719 +249065 +48873 +249065 +80 +60 +80 +140 +41564d00 +0400 +498 +513 + + +490282831 +254577751 +0 +2 +0 +0 +0 +25 +0 +0 +0 +0 +0 +53 +13 + + + diff --git a/plugins/inputs/fritzbox/testdata/WANPPPConnection.xml b/plugins/inputs/fritzbox/testdata/WANPPPConnection.xml new file mode 100644 index 0000000000000..3f8d8b2412d4a --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/WANPPPConnection.xml @@ -0,0 +1,38 @@ + + + + +1 +Connected +IP_Routed, IP_Bridged +IP_Routed +internet +369434 +44213433 +68038668 +ERROR_NONE +0 +0 +5511248654630001@setup.t-online.de +1 +217.238.141.33 +2003:180:2:7000::53, 2003:180:2:9000::53,217.237.151.115,217.237.148.102 +dc:39:6f:3a:bc:40 +AlwaysOn + +128 +3 +0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._@()#/%[]{}*+§$&=?!:;, +64 +3 +0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._@()#/%[]{}*+§$&=?!:;, +PPPoE +Off + + +MUNJ20 +1 +1 + + + diff --git a/plugins/inputs/fritzbox/testdata/WLANConfiguration.xml b/plugins/inputs/fritzbox/testdata/WLANConfiguration.xml new file mode 100644 index 0000000000000..332356618cb50 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/WLANConfiguration.xml @@ -0,0 +1,30 @@ + + + + +1 +Up +Auto +13 +MOCK1234 +11i +None,11i,WPAand11i,11iandWPA3 +0 +n +00:00:00:00:00:00 +None +None +32 +1 +0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +64 +64 +0123456789ABCDEFabcdef +2400 +1 + + +11 + + + diff --git a/plugins/inputs/fritzbox/testdata/dummySCPD.xml b/plugins/inputs/fritzbox/testdata/dummySCPD.xml new file mode 100644 index 0000000000000..5f4787762f0a3 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/dummySCPD.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/inputs/fritzbox/testdata/fritzbox.conf b/plugins/inputs/fritzbox/testdata/fritzbox.conf new file mode 100644 index 0000000000000..36cbb626cf7d5 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/fritzbox.conf @@ -0,0 +1,38 @@ + ## The devices to query. For each device the corresponding URL including the + ## user and passwort needed to login must be set. + ## E.g. + ## devices = [ + ## "http://boxuser:boxpassword@fritz.box:49000/", + ## "http://:repeaterpassword@fritz.repeater:49000/", + ## ] + devices = [ + "http://myuser:mypassword@fritz.box", + "http://myuser:mypassword@fritz.repeater", + ] + + ## The information to query (see README for further details). + ## Hosts info is disabled by default, as it generates an extensive amount + ## of data. + device_info = false + wan_info = false + ppp_info = false + dsl_info = false + wlan_info = false + hosts_info = true + + ## Some metric queries are time-consuming and not collected on every query + ## cycle. This counter defines how often these low-traffic queries + ## are excuted. The default value 30 means, on every 30th query corresponding + ## to every 5 minutes (assuming the standard query interval of 10s). + ## If this option is set to 1 or below, all metrics are collected on every + ## query cycle. + full_query_cycle = 6 + + ## The http timeout to use (in seconds). + timeout = "1m" + + ## Skip TLS verification (insecure) + tls_skip_verify = true + + ## Enable debug output + debug = true diff --git a/plugins/inputs/fritzbox/testdata/igddesc.xml b/plugins/inputs/fritzbox/testdata/igddesc.xml new file mode 100644 index 0000000000000..813ad273ac8b8 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/igddesc.xml @@ -0,0 +1,13 @@ + + + + + urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 + urn:upnp-org:serviceId:WANCommonIFC1 + /WANCommonIFC1 + /dummySCPD.xml + + + + + \ No newline at end of file diff --git a/plugins/inputs/fritzbox/testdata/meshlist.json b/plugins/inputs/fritzbox/testdata/meshlist.json new file mode 100644 index 0000000000000..87c29ccd29ad7 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/meshlist.json @@ -0,0 +1,1177 @@ +{ + "schema_version": "7.8", + "nodes": [ + { + "uid": "n-1", + "device_name": "device#1", + "is_meshed": true, + "mesh_role": "master", + "node_interfaces": [ + { + "uid": "ni-6", + "name": "LANBridge", + "type": "LAN", + "node_links": [] + }, + { + "uid": "ni-17", + "name": "LAN:2", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-286", + "node_interface_1_uid": "ni-17", + "node_interface_2_uid": "ni-287", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 1000000, + "cur_data_rate_tx": 1000000 + } + ] + }, + { + "uid": "ni-43", + "name": "LAN:1", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-54", + "node_interface_1_uid": "ni-43", + "node_interface_2_uid": "ni-55", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 1000000, + "cur_data_rate_tx": 1000000 + } + ] + }, + { + "uid": "ni-47", + "name": "LAN:3", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-50", + "node_interface_1_uid": "ni-47", + "node_interface_2_uid": "ni-51", + "max_data_rate_rx": 100000, + "max_data_rate_tx": 100000, + "cur_data_rate_rx": 100000, + "cur_data_rate_tx": 100000 + } + ] + }, + { + "uid": "ni-48", + "name": "LAN:4", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-52", + "node_interface_1_uid": "ni-48", + "node_interface_2_uid": "ni-53", + "max_data_rate_rx": 100000, + "max_data_rate_tx": 100000, + "cur_data_rate_rx": 100000, + "cur_data_rate_tx": 100000 + } + ] + }, + { + "uid": "ni-49", + "name": "WAN:1", + "type": "LAN", + "node_links": [] + }, + { + "uid": "ni-59", + "name": "AP:2G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-81", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-82", + "max_data_rate_rx": 72200, + "max_data_rate_tx": 72200, + "cur_data_rate_rx": 72000, + "cur_data_rate_tx": 72000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-110", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-252", + "max_data_rate_rx": 216000, + "max_data_rate_tx": 216000, + "cur_data_rate_rx": 216000, + "cur_data_rate_tx": 216000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-205", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-206", + "max_data_rate_rx": 72200, + "max_data_rate_tx": 72200, + "cur_data_rate_rx": 65000, + "cur_data_rate_tx": 72000 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + }, + { + "uid": "ni-60", + "name": "AP:5G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-217", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-218", + "max_data_rate_rx": 1733300, + "max_data_rate_tx": 1733300, + "cur_data_rate_rx": 650000, + "cur_data_rate_tx": 1170000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-106", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-107", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 780000, + "cur_data_rate_tx": 866000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-110", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-251", + "max_data_rate_rx": 1300000, + "max_data_rate_tx": 1300000, + "cur_data_rate_rx": 1300000, + "cur_data_rate_tx": 975000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-199", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-200", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 526000, + "cur_data_rate_tx": 780000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-100", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-101", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 585000, + "cur_data_rate_tx": 866000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-210", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-211", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-148", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-149", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 866000, + "cur_data_rate_tx": 866000 + } + ] + } + ] + }, + { + "uid": "n-50", + "device_name": "device#2", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-51", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-50", + "node_interface_1_uid": "ni-47", + "node_interface_2_uid": "ni-51", + "max_data_rate_rx": 100000, + "max_data_rate_tx": 100000, + "cur_data_rate_rx": 100000, + "cur_data_rate_tx": 100000 + } + ] + } + ] + }, + { + "uid": "n-52", + "device_name": "device#3", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-53", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-52", + "node_interface_1_uid": "ni-48", + "node_interface_2_uid": "ni-53", + "max_data_rate_rx": 100000, + "max_data_rate_tx": 100000, + "cur_data_rate_rx": 100000, + "cur_data_rate_tx": 100000 + } + ] + } + ] + }, + { + "uid": "n-54", + "device_name": "device#4", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-55", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-54", + "node_interface_1_uid": "ni-43", + "node_interface_2_uid": "ni-55", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 1000000, + "cur_data_rate_tx": 1000000 + } + ] + } + ] + }, + { + "uid": "n-81", + "device_name": "device#5", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-82", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-81", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-82", + "max_data_rate_rx": 72200, + "max_data_rate_tx": 72200, + "cur_data_rate_rx": 72000, + "cur_data_rate_tx": 72000 + } + ] + } + ] + }, + { + "uid": "n-92", + "device_name": "device#6", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-93", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-92", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-93", + "max_data_rate_rx": 72000, + "max_data_rate_tx": 72000, + "cur_data_rate_rx": 72200, + "cur_data_rate_tx": 72000 + } + ] + } + ] + }, + { + "uid": "n-106", + "device_name": "device#7", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-107", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-106", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-107", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 780000, + "cur_data_rate_tx": 866000 + } + ] + } + ] + }, + { + "uid": "n-148", + "device_name": "device#8", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-149", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-148", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-149", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + } + ] + } + ] + }, + { + "uid": "n-210", + "device_name": "device#9", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-211", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-210", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-211", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + } + ] + } + ] + }, + { + "uid": "n-44", + "device_name": "device#10", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-45", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-44", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-45", + "max_data_rate_rx": 866000, + "max_data_rate_tx": 866000, + "cur_data_rate_rx": 866700, + "cur_data_rate_tx": 866000 + } + ] + } + ] + }, + { + "uid": "n-100", + "device_name": "device#11", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-101", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-100", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-101", + "max_data_rate_rx": 433300, + "max_data_rate_tx": 433300, + "cur_data_rate_rx": 390000, + "cur_data_rate_tx": 433000 + } + ] + } + ] + }, + { + "uid": "n-122", + "device_name": "device#12", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-123", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-203", + "device_name": "device#13", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-204", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-203", + "node_interface_1_uid": "ni-89", + "node_interface_2_uid": "ni-204", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + } + ] + }, + { + "uid": "n-205", + "device_name": "device#14", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-206", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-205", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-206", + "max_data_rate_rx": 72200, + "max_data_rate_tx": 72200, + "cur_data_rate_rx": 65000, + "cur_data_rate_tx": 72000 + } + ] + } + ] + }, + { + "uid": "n-62", + "device_name": "device#15", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-67", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-178", + "device_name": "device#11", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-179", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 585000, + "cur_data_rate_tx": 866000 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + } + ] + }, + { + "uid": "n-102", + "device_name": "device#16", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-103", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-110", + "device_name": "device#17", + "is_meshed": true, + "mesh_role": "slave", + "node_interfaces": [ + { + "uid": "ni-89", + "name": "LAN:1", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-121", + "node_interface_1_uid": "ni-89", + "node_interface_2_uid": "ni-138", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-203", + "node_interface_1_uid": "ni-89", + "node_interface_2_uid": "ni-204", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + }, + { + "uid": "ni-250", + "name": "LANBridge", + "type": "LAN", + "node_links": [] + }, + { + "uid": "ni-251", + "name": "UPLINK:5G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-110", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-251", + "max_data_rate_rx": 1300000, + "max_data_rate_tx": 1300000, + "cur_data_rate_rx": 1300000, + "cur_data_rate_tx": 975000 + } + ] + }, + { + "uid": "ni-252", + "name": "UPLINK:2G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-110", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-252", + "max_data_rate_rx": 216000, + "max_data_rate_tx": 216000, + "cur_data_rate_rx": 216000, + "cur_data_rate_tx": 216000 + } + ] + }, + { + "uid": "ni-253", + "name": "AP:5G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-196", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-207", + "max_data_rate_rx": 866000, + "max_data_rate_tx": 866000, + "cur_data_rate_rx": 866700, + "cur_data_rate_tx": 866000 + }, + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-44", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-45", + "max_data_rate_rx": 866000, + "max_data_rate_tx": 866000, + "cur_data_rate_rx": 866700, + "cur_data_rate_tx": 866000 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + }, + { + "uid": "ni-254", + "name": "AP:2G:0", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-92", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-93", + "max_data_rate_rx": 72000, + "max_data_rate_tx": 72000, + "cur_data_rate_rx": 72200, + "cur_data_rate_tx": 72000 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-178", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-179", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + } + ] + }, + { + "uid": "n-199", + "device_name": "device#18", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-200", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-199", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-200", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 526000, + "cur_data_rate_tx": 780000 + } + ] + } + ] + }, + { + "uid": "n-217", + "device_name": "device#19", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-218", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-217", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-218", + "max_data_rate_rx": 1733300, + "max_data_rate_tx": 1733300, + "cur_data_rate_rx": 650000, + "cur_data_rate_tx": 1170000 + } + ] + } + ] + }, + { + "uid": "n-197", + "device_name": "device#20", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-202", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-180", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-182", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-196", + "device_name": "device#22", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-207", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-196", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-207", + "max_data_rate_rx": 866000, + "max_data_rate_tx": 866000, + "cur_data_rate_rx": 866700, + "cur_data_rate_tx": 866000 + } + ] + } + ] + }, + { + "uid": "n-284", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-285", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-166", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-186", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-225", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-227", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-244", + "device_name": "device#19", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-245", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-238", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-239", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-233", + "device_name": "device#23", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-234", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-121", + "device_name": "device#24", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-138", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-121", + "node_interface_1_uid": "ni-89", + "node_interface_2_uid": "ni-138", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + } + ] + }, + { + "uid": "n-247", + "device_name": "device#16", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-248", + "name": "", + "type": "WLAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-60", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 866700, + "max_data_rate_tx": 866700, + "cur_data_rate_rx": 866000, + "cur_data_rate_tx": 866000 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-253", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-110", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-254", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + }, + { + "state": "DISCONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-247", + "node_interface_1_uid": "ni-59", + "node_interface_2_uid": "ni-248", + "max_data_rate_rx": 0, + "max_data_rate_tx": 0, + "cur_data_rate_rx": 0, + "cur_data_rate_tx": 0 + } + ] + } + ] + }, + { + "uid": "n-191", + "device_name": "device#25", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-193", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-209", + "device_name": "device#21", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-212", + "name": "", + "type": "WLAN", + "node_links": [] + } + ] + }, + { + "uid": "n-286", + "device_name": "device#26", + "is_meshed": false, + "mesh_role": "unknown", + "node_interfaces": [ + { + "uid": "ni-287", + "name": "", + "type": "LAN", + "node_links": [ + { + "state": "CONNECTED", + "node_1_uid": "n-1", + "node_2_uid": "n-286", + "node_interface_1_uid": "ni-17", + "node_interface_2_uid": "ni-287", + "max_data_rate_rx": 1000000, + "max_data_rate_tx": 1000000, + "cur_data_rate_rx": 1000000, + "cur_data_rate_tx": 1000000 + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/plugins/inputs/fritzbox/testdata/tr64desc.xml b/plugins/inputs/fritzbox/testdata/tr64desc.xml new file mode 100644 index 0000000000000..f1ad3c7ea275d --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/tr64desc.xml @@ -0,0 +1,43 @@ + + + + + urn:dslforum-org:service:DeviceInfo:1 + urn:DeviceInfo-com:serviceId:DeviceInfo1 + /deviceinfo + /dummySCPD.xml + + + urn:dslforum-org:service:WLANConfiguration:1 + urn:WLANConfiguration-com:serviceId:WLANConfiguration1 + /wlanconfig + /dummySCPD.xml + + + urn:dslforum-org:service:WANCommonInterfaceConfig:1 + urn:WANCIfConfig-com:serviceId:WANCommonInterfaceConfig1 + /wancommonifconfig + /dummySCPD.xml + + + urn:dslforum-org:service:WANPPPConnection:1 + urn:WANPPPConnection-com:serviceId:WANPPPConnection1 + /wanpppconn + /dummySCPD.xml + + + urn:dslforum-org:service:WANDSLInterfaceConfig:1 + urn:WANDSLIfConfig-com:serviceId:WANDSLInterfaceConfig1 + /wandslifconfig + /dummySCPD.xml + + + urn:dslforum-org:service:Hosts:1 + urn:LanDeviceHosts-com:serviceId:Hosts1 + /hosts + /dummySCPD.xml + + + + + \ No newline at end of file From 7f5a3107b0e161d3d0a801f70edb945b8d3fbe2f Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 10 Jan 2025 20:09:31 +0100 Subject: [PATCH 02/12] feat(inputs.fritzbox): Fix linter issues --- plugins/inputs/fritzbox/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md index 481f2492e3287..008a32d1ed15f 100644 --- a/plugins/inputs/fritzbox/README.md +++ b/plugins/inputs/fritzbox/README.md @@ -88,7 +88,7 @@ specification][1]. - `fritz_device` - The device name (this metric has been queried from) - `fritz_service` - The service id used to query this metric - fields - - `layer1_upstream_max_bit_rate` (uint) - The WAN interface's maximum upstream bit rate (bits/sec) + - `layer1_upstream_max_bit_rate` (uint) - The WAN interface's maximum upstream bit rate (bits/sec) - `layer1_downstream_max_bit_rate` (uint) - The WAN interface's maximum downstream bit rate (bits/sec) - `upstream_current_max_speed` (uint) - The WAN interface's current maximum upstream transfer rate (bytes/sec) - `downstream_current_max_speed` (uint) - The WAN interface's current maximum downstream data rate (bytes/sec) @@ -160,6 +160,7 @@ specification][1]. ## Example Output + ```text fritzbox_device,fritz_device=127.0.0.1,fritz_service=DeviceInfo1 model_name=Mock 1234,serial_number=123456789,hardware_version=Mock 1234,software_version=1.02.03,uptime=2058438 1736529975 @@ -174,4 +175,5 @@ fritzbox_wlan,fritz_device=127.0.0.1,fritz_service=WLANConfiguration1,fritz_wlan fritzbox_host,fritz_host_peer_role=master,fritz_link_type=WLAN,fritz_link_name=AP:2G:0,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#17,fritz_host_role=slave,fritz_host_peer=device#1 max_data_rate_tx=216000,max_data_rate_rx=216000,cur_data_rate_tx=216000,cur_data_rate_rx=216000 1736530165 fritzbox_host,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#24,fritz_host_role=client,fritz_host_peer=device#17,fritz_host_peer_role=slave,fritz_link_type=LAN,fritz_link_name=LAN:1 cur_data_rate_tx=0,cur_data_rate_rx=0,max_data_rate_tx=1000000,max_data_rate_rx=1000000 1736530165 ``` + . From 956766ca069329ce108d2513ab3f4d970f249921 Mon Sep 17 00:00:00 2001 From: Holger Date: Wed, 15 Jan 2025 21:55:08 +0100 Subject: [PATCH 03/12] feat(inputs.fritzbox): Improve tag names --- plugins/inputs/fritzbox/fritzbox.go | 42 ++++++++++++------------ plugins/inputs/fritzbox/fritzbox_test.go | 12 +++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index 7b92334a39dd9..485671f9fc2cf 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -173,8 +173,8 @@ func (plugin *Fritzbox) gatherDeviceInfo(acc telegraf.Accumulator, deviceClient return err } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() fields := make(map[string]interface{}) fields["uptime"] = info.NewUpTime fields["model_name"] = info.NewModelName @@ -225,8 +225,8 @@ func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr return err } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() fields := make(map[string]interface{}) fields["layer1_upstream_max_bit_rate"] = commonLinkProperties.NewLayer1UpstreamMaxBitRate fields["layer1_downstream_max_bit_rate"] = commonLinkProperties.NewLayer1DownstreamMaxBitRate @@ -252,8 +252,8 @@ func (plugin *Fritzbox) gatherPppInfo(acc telegraf.Accumulator, deviceClient *tr return err } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() fields := make(map[string]interface{}) fields["uptime"] = info.NewUptime fields["upstream_max_bit_rate"] = info.NewUpstreamMaxBitRate @@ -284,8 +284,8 @@ func (plugin *Fritzbox) gatherDslInfo(acc telegraf.Accumulator, deviceClient *tr return err } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() fields := make(map[string]interface{}) fields["upstream_curr_rate"] = info.NewUpstreamCurrRate fields["downstream_curr_rate"] = info.NewDownstreamCurrRate @@ -338,11 +338,11 @@ func (plugin *Fritzbox) gatherWlanInfo(acc telegraf.Accumulator, deviceClient *t return err } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() - tags["fritz_wlan"] = info.NewSSID - tags["fritz_wlan_channel"] = strconv.Itoa(int(info.NewChannel)) - tags["fritz_wlan_band"] = plugin.wlanBandFromInfo(info) + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() + tags["ssid"] = info.NewSSID + tags["channel"] = strconv.Itoa(int(info.NewChannel)) + tags["band"] = plugin.wlanBandFromInfo(info) fields := make(map[string]interface{}) fields["total_associations"] = totalAssociations.NewTotalAssociations acc.AddGauge("fritzbox_wlan", fields, tags) @@ -381,14 +381,14 @@ func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient * continue } tags := make(map[string]string) - tags["fritz_device"] = serviceClient.TR064Client.DeviceUrl.Hostname() - tags["fritz_service"] = serviceClient.Service.ShortId() - tags["fritz_host"] = connection.RightDeviceName - tags["fritz_host_role"] = plugin.hostRole(connection.RightMeshRole) - tags["fritz_host_peer"] = connection.LeftDeviceName - tags["fritz_host_peer_role"] = plugin.hostRole(connection.LeftMeshRole) - tags["fritz_link_type"] = connection.InterfaceType - tags["fritz_link_name"] = connection.InterfaceName + tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() + tags["service"] = serviceClient.Service.ShortId() + tags["host"] = connection.RightDeviceName + tags["host_role"] = plugin.hostRole(connection.RightMeshRole) + tags["host_ap"] = connection.LeftDeviceName + tags["host_ap_role"] = plugin.hostRole(connection.LeftMeshRole) + tags["link_type"] = connection.InterfaceType + tags["link_name"] = connection.InterfaceName fields := make(map[string]interface{}) fields["max_data_rate_tx"] = connection.MaxDataRateTx fields["max_data_rate_rx"] = connection.MaxDataRateRx diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index ee839ea6dc186..3d10c0087681b 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -80,7 +80,7 @@ func TestGatherDeviceInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_device", []string{"fritz_device", "fritz_service"}, []string{"uptime", "model_name", "serial_number", "hardware_version", "software_version"}) + testMeasurement(t, acc, "fritzbox_device", []string{"source", "service"}, []string{"uptime", "model_name", "serial_number", "hardware_version", "software_version"}) } func TestGatherWanInfo(t *testing.T) { @@ -102,7 +102,7 @@ func TestGatherWanInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_wan", []string{"fritz_device", "fritz_service"}, []string{"layer1_upstream_max_bit_rate", "layer1_downstream_max_bit_rate", "upstream_current_max_speed", "downstream_current_max_speed", "total_bytes_sent", "total_bytes_received"}) + testMeasurement(t, acc, "fritzbox_wan", []string{"source", "service"}, []string{"layer1_upstream_max_bit_rate", "layer1_downstream_max_bit_rate", "upstream_current_max_speed", "downstream_current_max_speed", "total_bytes_sent", "total_bytes_received"}) } func TestGatherPppInfo(t *testing.T) { @@ -124,7 +124,7 @@ func TestGatherPppInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_ppp", []string{"fritz_device", "fritz_service"}, []string{"uptime", "upstream_max_bit_rate", "downstream_max_bit_rate"}) + testMeasurement(t, acc, "fritzbox_ppp", []string{"source", "service"}, []string{"uptime", "upstream_max_bit_rate", "downstream_max_bit_rate"}) } func TestGatherDslInfo(t *testing.T) { @@ -146,7 +146,7 @@ func TestGatherDslInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_dsl", []string{"fritz_device", "fritz_service"}, []string{"upstream_curr_rate", "downstream_curr_rate", "upstream_max_rate", "downstream_max_rate", "upstream_noise_margin", "downstream_noise_margin", "upstream_attenuation", "downstream_attenuation", "upstream_power", "downstream_power", "receive_blocks", "transmit_blocks", "cell_delin", "link_retrain", "init_errors", "init_timeouts", "loss_of_framing", "errored_secs", "severly_errored_secs", "fec_errors", "atuc_fec_errors", "hec_errors", "atuc_hec_errors", "crc_errors", "atuc_crc_errors"}) + testMeasurement(t, acc, "fritzbox_dsl", []string{"source", "service"}, []string{"upstream_curr_rate", "downstream_curr_rate", "upstream_max_rate", "downstream_max_rate", "upstream_noise_margin", "downstream_noise_margin", "upstream_attenuation", "downstream_attenuation", "upstream_power", "downstream_power", "receive_blocks", "transmit_blocks", "cell_delin", "link_retrain", "init_errors", "init_timeouts", "loss_of_framing", "errored_secs", "severly_errored_secs", "fec_errors", "atuc_fec_errors", "hec_errors", "atuc_hec_errors", "crc_errors", "atuc_crc_errors"}) } func TestGatherWlanInfo(t *testing.T) { @@ -168,7 +168,7 @@ func TestGatherWlanInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_wlan", []string{"fritz_device", "fritz_service", "fritz_wlan_channel", "fritz_wlan_band"}, []string{"total_associations"}) + testMeasurement(t, acc, "fritzbox_wlan", []string{"source", "service", "ssid", "channel", "band"}, []string{"total_associations"}) } func TestGatherHostsInfo(t *testing.T) { @@ -190,7 +190,7 @@ func TestGatherHostsInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_host", []string{"fritz_device", "fritz_service", "fritz_host", "fritz_host_role", "fritz_host_peer", "fritz_host_peer_role", "fritz_link_type", "fritz_link_name"}, []string{"max_data_rate_tx", "max_data_rate_rx", "cur_data_rate_tx", "cur_data_rate_rx"}) + testMeasurement(t, acc, "fritzbox_host", []string{"source", "service", "host", "host_role", "host_ap", "host_ap_role", "link_type", "link_name"}, []string{"max_data_rate_tx", "max_data_rate_rx", "cur_data_rate_tx", "cur_data_rate_rx"}) } func testMeasurement(t *testing.T, acc *testutil.Accumulator, measurement string, tags []string, fields []string) { From ccd459aee13ea59a56e50afcc9f0e590f6967638 Mon Sep 17 00:00:00 2001 From: Holger Date: Wed, 15 Jan 2025 22:06:16 +0100 Subject: [PATCH 04/12] feat(inputs.fritzbox): Remove plugin Debug flag and use log level instead --- plugins/inputs/fritzbox/README.md | 3 --- plugins/inputs/fritzbox/fritzbox.go | 24 +++++++------------ plugins/inputs/fritzbox/fritzbox_test.go | 8 ------- plugins/inputs/fritzbox/sample.conf | 3 --- .../inputs/fritzbox/testdata/fritzbox.conf | 3 --- 5 files changed, 8 insertions(+), 33 deletions(-) diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md index 008a32d1ed15f..df12777a40576 100644 --- a/plugins/inputs/fritzbox/README.md +++ b/plugins/inputs/fritzbox/README.md @@ -63,9 +63,6 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. ## Skip TLS verification. Is needed to query devices with the default ## self-signed certificate. # tls_skip_verify = false - - ## Enable debug output - # debug = false ``` ## Metrics diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index 485671f9fc2cf..b5c6aa7ce1396 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -46,7 +46,6 @@ type Fritzbox struct { FullQueryCycle int `toml:"full_query_cycle"` Timeout config.Duration `toml:"timeout"` TlsSkipVerify bool `toml:"tls_skip_verify"` - Debug bool `toml:"debug"` Log telegraf.Logger `toml:"-"` deviceClients []*tr064.Client serviceHandlers map[string]serviceHandlerFunc @@ -93,7 +92,7 @@ func (plugin *Fritzbox) initDeviceClients() error { return err } client := tr064.NewClient(deviceUrl) - client.Debug = plugin.Debug + client.Debug = plugin.Log.Level().Includes(telegraf.Debug) client.Timeout = time.Duration(plugin.Timeout) client.InsecureSkipVerify = plugin.TlsSkipVerify plugin.deviceClients = append(plugin.deviceClients, client) @@ -123,14 +122,9 @@ func (plugin *Fritzbox) initServiceHandlers() { } func (plugin *Fritzbox) Gather(acc telegraf.Accumulator) error { - start := time.Now() for _, deviceClient := range plugin.deviceClients { plugin.gatherDevice(acc, deviceClient) } - if plugin.Debug { - elapsed := time.Since(start) - plugin.Log.Info("took: ", elapsed) - } plugin.queryCycleCounter++ if plugin.queryCycleCounter >= plugin.FullQueryCycle { plugin.queryCycleCounter = 0 @@ -139,9 +133,7 @@ func (plugin *Fritzbox) Gather(acc telegraf.Accumulator) error { } func (plugin *Fritzbox) gatherDevice(acc telegraf.Accumulator, deviceClient *tr064.Client) { - if plugin.Debug { - plugin.Log.Infof("Querying %s", deviceClient.DeviceUrl.Redacted()) - } + plugin.Log.Debugf("Querying %s", deviceClient.DeviceUrl.Redacted()) services, err := deviceClient.Services(tr064.DefaultServiceSpec) if err != nil { acc.AddError(err) @@ -182,7 +174,7 @@ func (plugin *Fritzbox) gatherDeviceInfo(acc telegraf.Accumulator, deviceClient fields["hardware_version"] = info.NewHardwareVersion fields["software_version"] = info.NewSoftwareVersion acc.AddFields("fritzbox_device", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_device", tags, fields) } return nil @@ -235,7 +227,7 @@ func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr fields["total_bytes_sent"] = totalBytesSent fields["total_bytes_received"] = totalBytesReceived acc.AddFields("fritzbox_wan", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_wan", tags, fields) } return nil @@ -259,7 +251,7 @@ func (plugin *Fritzbox) gatherPppInfo(acc telegraf.Accumulator, deviceClient *tr fields["upstream_max_bit_rate"] = info.NewUpstreamMaxBitRate fields["downstream_max_bit_rate"] = info.NewDownstreamMaxBitRate acc.AddFields("fritzbox_ppp", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_ppp", tags, fields) } return nil @@ -313,7 +305,7 @@ func (plugin *Fritzbox) gatherDslInfo(acc telegraf.Accumulator, deviceClient *tr fields["crc_errors"] = statisticsTotal.NewCRCErrors fields["atuc_crc_errors"] = statisticsTotal.NewATUCCRCErrors acc.AddFields("fritzbox_dsl", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_dsl", tags, fields) } return nil @@ -346,7 +338,7 @@ func (plugin *Fritzbox) gatherWlanInfo(acc telegraf.Accumulator, deviceClient *t fields := make(map[string]interface{}) fields["total_associations"] = totalAssociations.NewTotalAssociations acc.AddGauge("fritzbox_wlan", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_wlan", tags, fields) } return nil @@ -395,7 +387,7 @@ func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient * fields["cur_data_rate_tx"] = connection.CurDataRateTx fields["cur_data_rate_rx"] = connection.CurDataRateRx acc.AddGauge("fritzbox_host", fields, tags) - if plugin.Debug { + if plugin.Log.Level().Includes(telegraf.Debug) { plugin.logMetric("fritzbox_host", tags, fields) } } diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index 3d10c0087681b..e0203a426bc40 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -26,7 +26,6 @@ func TestInitDefaults(t *testing.T) { require.Equal(t, 30, plugin.FullQueryCycle) require.Equal(t, defaultTimeout, plugin.Timeout) require.False(t, plugin.TlsSkipVerify) - require.False(t, plugin.Debug) require.NotNil(t, plugin.Log) } @@ -48,7 +47,6 @@ func TestConfig(t *testing.T) { require.Equal(t, 6, plugin.FullQueryCycle) require.Equal(t, config.Duration(60*time.Second), plugin.Timeout) require.True(t, plugin.TlsSkipVerify) - require.True(t, plugin.Debug) } var testMocks = []*mock.ServiceMock{ @@ -74,7 +72,6 @@ func TestGatherDeviceInfo(t *testing.T) { plugin.DslInfo = false plugin.WlanInfo = false plugin.HostsInfo = false - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -96,7 +93,6 @@ func TestGatherWanInfo(t *testing.T) { plugin.DslInfo = false plugin.WlanInfo = false plugin.HostsInfo = false - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -118,7 +114,6 @@ func TestGatherPppInfo(t *testing.T) { plugin.DslInfo = false plugin.WlanInfo = false plugin.HostsInfo = false - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -140,7 +135,6 @@ func TestGatherDslInfo(t *testing.T) { plugin.DslInfo = true plugin.WlanInfo = false plugin.HostsInfo = false - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -162,7 +156,6 @@ func TestGatherWlanInfo(t *testing.T) { plugin.DslInfo = false plugin.WlanInfo = true plugin.HostsInfo = false - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -184,7 +177,6 @@ func TestGatherHostsInfo(t *testing.T) { plugin.DslInfo = false plugin.WlanInfo = false plugin.HostsInfo = true - plugin.Debug = true err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} diff --git a/plugins/inputs/fritzbox/sample.conf b/plugins/inputs/fritzbox/sample.conf index 7fc1d68810b72..8b930629bd15e 100644 --- a/plugins/inputs/fritzbox/sample.conf +++ b/plugins/inputs/fritzbox/sample.conf @@ -34,6 +34,3 @@ ## Skip TLS verification. Is needed to query devices with the default ## self-signed certificate. # tls_skip_verify = false - - ## Enable debug output - # debug = false diff --git a/plugins/inputs/fritzbox/testdata/fritzbox.conf b/plugins/inputs/fritzbox/testdata/fritzbox.conf index 36cbb626cf7d5..ae46531cc5704 100644 --- a/plugins/inputs/fritzbox/testdata/fritzbox.conf +++ b/plugins/inputs/fritzbox/testdata/fritzbox.conf @@ -33,6 +33,3 @@ ## Skip TLS verification (insecure) tls_skip_verify = true - - ## Enable debug output - debug = true From fd007fccfb4d6a2e9825ed61f5b702dc2346c2ca Mon Sep 17 00:00:00 2001 From: Holger Date: Thu, 16 Jan 2025 06:18:02 +0100 Subject: [PATCH 05/12] feat(inputs.fritzbox): Rework plugin log output to emit proper line protocol --- plugins/inputs/fritzbox/README.md | 16 +++++----- plugins/inputs/fritzbox/fritzbox.go | 37 +++++++++--------------- plugins/inputs/fritzbox/fritzbox_test.go | 13 +++++++++ 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md index df12777a40576..3cfcbdc529b78 100644 --- a/plugins/inputs/fritzbox/README.md +++ b/plugins/inputs/fritzbox/README.md @@ -3,7 +3,7 @@ This input plugin gathers status from [AVM][1] devices (routers, repeaters, ...). It uses the device's [TR-064][2] interfaces to retrieve the status. -[1]: https://avm.de/ +[1]: https://en.avm.de/ [2]: https://avm.de/service/schnittstellen/ Retrieved status are: @@ -159,18 +159,18 @@ specification][1]. ```text -fritzbox_device,fritz_device=127.0.0.1,fritz_service=DeviceInfo1 model_name=Mock 1234,serial_number=123456789,hardware_version=Mock 1234,software_version=1.02.03,uptime=2058438 1736529975 +fritzbox_device,service=DeviceInfo1,source=fritz.box uptime=2058438i,model_name="Mock 1234",serial_number="123456789",hardware_version="Mock 1234",software_version="1.02.03" 1737003520174438000 -fritzbox_wan,fritz_device=127.0.0.1,fritz_service=WANCommonInterfaceConfig1 total_bytes_received=554484531337,layer1_upstream_max_bit_rate=48816000,layer1_downstream_max_bit_rate=253247000,upstream_current_max_speed=511831,downstream_current_max_speed=1304268,total_bytes_sent=129497283207 1736530024 +fritzbox_wan,service=WANCommonInterfaceConfig1,source=fritz.box layer1_upstream_max_bit_rate=48816000i,layer1_downstream_max_bit_rate=253247000i,upstream_current_max_speed=511831i,downstream_current_max_speed=1304268i,total_bytes_sent=129497283207i,total_bytes_received=554484531337i 1737003587690504000 -fritzbox_ppp,fritz_device=127.0.0.1,fritz_service=WANPPPConnection1 uptime=369434,upstream_max_bit_rate=44213433,downstream_max_bit_rate=68038668 1736530058 +fritzbox_ppp,service=WANPPPConnection1,source=fritz.box uptime=369434i,upstream_max_bit_rate=44213433i,downstream_max_bit_rate=68038668i 1737003622308149000 -fritzbox_dsl,fritz_device=127.0.0.1,fritz_service=WANDSLInterfaceConfig1 downstream_noise_margin=60,upstream_power=498,downstream_power=513,upstream_curr_rate=46719,downstream_curr_rate=249065,upstream_max_rate=48873,downstream_max_rate=249065,upstream_noise_margin=80,severly_errored_secs=0,upstream_attenuation=80,transmit_blocks=254577751,init_timeouts=0,atuc_crc_errors=13,receive_blocks=490282831,errored_secs=25,fec_errors=0,atuc_hec_errors=0,atuc_fec_errors=0,hec_errors=0,crc_errors=53,downstream_attenuation=140,cell_delin=0,link_retrain=2,init_errors=0,loss_of_framing=0 1736530092 +fritzbox_dsl,service=WANDSLInterfaceConfig1,source=fritz.box downstream_curr_rate=249065i,downstream_max_rate=249065i,downstream_power=513i,init_timeouts=0i,atuc_crc_errors=13i,errored_secs=25i,atuc_hec_errors=0i,upstream_noise_margin=80i,downstream_noise_margin=60i,downstream_attenuation=140i,receive_blocks=490282831i,transmit_blocks=254577751i,init_errors=0i,crc_errors=53i,fec_errors=0i,hec_errors=0i,upstream_max_rate=48873i,upstream_attenuation=80i,upstream_power=498i,cell_delin=0i,link_retrain=2i,loss_of_framing=0i,upstream_curr_rate=46719i,severly_errored_secs=0i,atuc_fec_errors=0i 1737003645769642000 -fritzbox_wlan,fritz_device=127.0.0.1,fritz_service=WLANConfiguration1,fritz_wlan=MOCK1234,fritz_wlan_channel=13,fritz_wlan_band=2400 total_associations=11 1736530130 +fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=fritz.box,ssid=MOCK1234 total_associations=11i 1737003673561198000 -fritzbox_host,fritz_host_peer_role=master,fritz_link_type=WLAN,fritz_link_name=AP:2G:0,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#17,fritz_host_role=slave,fritz_host_peer=device#1 max_data_rate_tx=216000,max_data_rate_rx=216000,cur_data_rate_tx=216000,cur_data_rate_rx=216000 1736530165 -fritzbox_host,fritz_device=127.0.0.1,fritz_service=Hosts1,fritz_host=device#24,fritz_host_role=client,fritz_host_peer=device#17,fritz_host_peer_role=slave,fritz_link_type=LAN,fritz_link_name=LAN:1 cur_data_rate_tx=0,cur_data_rate_rx=0,max_data_rate_tx=1000000,max_data_rate_rx=1000000 1736530165 +fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=fritz.box cur_data_rate_tx=216000i,cur_data_rate_rx=216000i,max_data_rate_tx=216000i,max_data_rate_rx=216000i 1737003707257394000 +fritzbox_host,host=device#24,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=fritz.box max_data_rate_tx=1000000i,max_data_rate_rx=1000000i,cur_data_rate_tx=0i,cur_data_rate_rx=0i 1737003707257248000 ``` . diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index b5c6aa7ce1396..9e79c7a363472 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -9,14 +9,15 @@ import ( "net/http" "net/url" "strconv" - "strings" "time" "github.com/google/uuid" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/logger" + "github.com/influxdata/telegraf/metric" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/serializers/influx" "github.com/tdrn-org/go-tr064" "github.com/tdrn-org/go-tr064/mesh" "github.com/tdrn-org/go-tr064/services/igddesc/igdicfg" @@ -431,29 +432,19 @@ func (plugin *Fritzbox) fetchHostsConnections(serviceClient *hosts.ServiceClient } func (plugin *Fritzbox) logMetric(name string, tags map[string]string, fields map[string]interface{}) { - buffer := strings.Builder{} - buffer.WriteString(name) - for tagKey, tagValue := range tags { - buffer.WriteRune(',') - buffer.WriteString(tagKey) - buffer.WriteRune('=') - buffer.WriteString(fmt.Sprint(tagValue)) - } - writeSpace := true - for fieldKey, fieldValue := range fields { - if writeSpace { - buffer.WriteRune(' ') - writeSpace = false - } else { - buffer.WriteRune(',') - } - buffer.WriteString(fieldKey) - buffer.WriteRune('=') - buffer.WriteString(fmt.Sprint(fieldValue)) + serializer := &influx.Serializer{} + err := serializer.Init() + if err != nil { + plugin.Log.Error("Failed to initialize Serializer: ", err) + return + } + metric := metric.New(name, tags, fields, time.Now().Round(time.Nanosecond)) + message, err := serializer.Serialize(metric) + if err != nil { + plugin.Log.Error("Failed to serialize metric: ", err) + return } - buffer.WriteRune(' ') - buffer.WriteString(fmt.Sprint(time.Now().Unix())) - plugin.Log.Info(buffer.String()) + plugin.Log.Debug(string(message)) } func init() { diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index e0203a426bc40..3ea4fd0c31cb3 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -7,6 +7,7 @@ import ( "github.com/BurntSushi/toml" "github.com/influxdata/telegraf/config" + "github.com/influxdata/telegraf/logger" "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" "github.com/tdrn-org/go-tr064/mock" @@ -63,6 +64,8 @@ func TestGatherDeviceInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) @@ -84,6 +87,8 @@ func TestGatherWanInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) @@ -105,6 +110,8 @@ func TestGatherPppInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) @@ -126,6 +133,8 @@ func TestGatherDslInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) @@ -147,6 +156,8 @@ func TestGatherWlanInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) @@ -168,6 +179,8 @@ func TestGatherHostsInfo(t *testing.T) { // Start mock server tr064Server := mock.Start("testdata", testMocks...) defer tr064Server.Shutdown() + // Enable debug logging + logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) From bdc7789f8cf8f35070b24de6031f8919789574d3 Mon Sep 17 00:00:00 2001 From: Holger Date: Thu, 16 Jan 2025 21:39:59 +0100 Subject: [PATCH 06/12] feat(inputs.fritzbox): go mod tidy --- go.sum | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/go.sum b/go.sum index e687bba59837e..a4aa46377cfd0 100644 --- a/go.sum +++ b/go.sum @@ -2321,18 +2321,6 @@ github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7 h1:Jtcrb09q0AVWe3 github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7/go.mod h1:suDIky6yrK07NnaBadCB4sS0CqFOvUK91lH7CR+JlDA= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw= -github.com/tdrn-org/go-tr064 v0.1.6 h1:5Y/1/VzkQws8LAxWeKW8bH6FcAMToQQTBsqkItR+zY0= -github.com/tdrn-org/go-tr064 v0.1.6/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= -github.com/tdrn-org/go-tr064 v0.1.7 h1:YdKRg9OG4aAppIiWfDqOC5g/6LCOXWMIkdOz5y9tts4= -github.com/tdrn-org/go-tr064 v0.1.7/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= -github.com/tdrn-org/go-tr064 v0.1.8 h1:9bvf85Pa30pcrlYHsgZUZ54aGu0UCj+U7K9jroGSLsU= -github.com/tdrn-org/go-tr064 v0.1.8/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= -github.com/tdrn-org/go-tr064 v0.1.9 h1:HGRiBsgvmSlFxcnlVVllMRewrHKpQFq0O13bEvwfaSQ= -github.com/tdrn-org/go-tr064 v0.1.9/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= -github.com/tdrn-org/go-tr064 v0.1.10 h1:TIU7P+KoxBpjyQ6B7H9Yf4DxDK/6td6tc4lZNasYQwc= -github.com/tdrn-org/go-tr064 v0.1.10/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= -github.com/tdrn-org/go-tr064 v0.1.11 h1:LFjJjfU7NdGXnqrNZ+dxaxCt4EndJISknTL1VGNcGBY= -github.com/tdrn-org/go-tr064 v0.1.11/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= github.com/tdrn-org/go-tr064 v0.2.0 h1:n2Dz8UdUlZm8jS0coiXl6eRVB4qSz8fcbrHJhPyNVfk= github.com/tdrn-org/go-tr064 v0.2.0/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0= From 8777e74357c25c2d276d469fc9942c1c25f3242b Mon Sep 17 00:00:00 2001 From: Holger Date: Thu, 16 Jan 2025 21:52:32 +0100 Subject: [PATCH 07/12] feat(inputs.fritzbox): Rename plugin option devices to URLs --- plugins/inputs/fritzbox/README.md | 8 ++++---- plugins/inputs/fritzbox/fritzbox.go | 10 +++++----- plugins/inputs/fritzbox/fritzbox_test.go | 16 ++++++++-------- plugins/inputs/fritzbox/sample.conf | 8 ++++---- plugins/inputs/fritzbox/testdata/fritzbox.conf | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md index 3cfcbdc529b78..c3aafd93739e0 100644 --- a/plugins/inputs/fritzbox/README.md +++ b/plugins/inputs/fritzbox/README.md @@ -29,14 +29,14 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. ```toml @sample.conf # Gather fritzbox status [[inputs.fritzbox]] - ## The devices to query. For each device the corresponding URL including the - ## user and passwort needed to login must be set. + ## The URLs of the devices to query. For each device the corresponding URL + ## including the login credentials must be set. ## E.g. - ## devices = [ + ## URLs = [ ## "http://boxuser:boxpassword@fritz.box:49000/", ## "http://:repeaterpassword@fritz.repeater:49000/", ## ] - devices = [ + URLs = [ ] ## The information to query (see README for further details). diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index 9e79c7a363472..adfba87cac921 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -37,7 +37,7 @@ const pluginName = "fritzbox" const defaultTimeout = config.Duration(10 * time.Second) type Fritzbox struct { - Devices []string `toml:"devices"` + URLs []string `toml:"urls"` DeviceInfo bool `toml:"device_info"` WanInfo bool `toml:"wan_info"` PppInfo bool `toml:"ppp_info"` @@ -55,7 +55,7 @@ type Fritzbox struct { func defaultFritzbox() *Fritzbox { return &Fritzbox{ - Devices: make([]string, 0), + URLs: make([]string, 0), DeviceInfo: true, WanInfo: true, PppInfo: true, @@ -87,12 +87,12 @@ func (plugin *Fritzbox) Init() error { } func (plugin *Fritzbox) initDeviceClients() error { - for _, device := range plugin.Devices { - deviceUrl, err := url.Parse(device) + for _, rawUrl := range plugin.URLs { + parsedUrl, err := url.Parse(rawUrl) if err != nil { return err } - client := tr064.NewClient(deviceUrl) + client := tr064.NewClient(parsedUrl) client.Debug = plugin.Log.Level().Includes(telegraf.Debug) client.Timeout = time.Duration(plugin.Timeout) client.InsecureSkipVerify = plugin.TlsSkipVerify diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index 3ea4fd0c31cb3..56102d12a50da 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -17,7 +17,7 @@ func TestInitDefaults(t *testing.T) { plugin := defaultFritzbox() err := plugin.Init() require.NoError(t, err) - require.Equal(t, 0, len(plugin.Devices)) + require.Equal(t, 0, len(plugin.URLs)) require.True(t, plugin.DeviceInfo) require.True(t, plugin.WanInfo) require.True(t, plugin.PppInfo) @@ -38,7 +38,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) err = plugin.Init() require.NoError(t, err) - require.Equal(t, 2, len(plugin.Devices)) + require.Equal(t, 2, len(plugin.URLs)) require.False(t, plugin.DeviceInfo) require.False(t, plugin.WanInfo) require.False(t, plugin.PppInfo) @@ -68,7 +68,7 @@ func TestGatherDeviceInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = true plugin.WanInfo = false plugin.PppInfo = false @@ -91,7 +91,7 @@ func TestGatherWanInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = false plugin.WanInfo = true plugin.PppInfo = false @@ -114,7 +114,7 @@ func TestGatherPppInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = false plugin.WanInfo = false plugin.PppInfo = true @@ -137,7 +137,7 @@ func TestGatherDslInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = false plugin.WanInfo = false plugin.PppInfo = false @@ -160,7 +160,7 @@ func TestGatherWlanInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = false plugin.WanInfo = false plugin.PppInfo = false @@ -183,7 +183,7 @@ func TestGatherHostsInfo(t *testing.T) { logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() - plugin.Devices = append(plugin.Devices, tr064Server.Server().String()) + plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) plugin.DeviceInfo = false plugin.WanInfo = false plugin.PppInfo = false diff --git a/plugins/inputs/fritzbox/sample.conf b/plugins/inputs/fritzbox/sample.conf index 8b930629bd15e..56f28481c1b08 100644 --- a/plugins/inputs/fritzbox/sample.conf +++ b/plugins/inputs/fritzbox/sample.conf @@ -1,13 +1,13 @@ # Gather fritzbox status [[inputs.fritzbox]] - ## The devices to query. For each device the corresponding URL including the - ## user and passwort needed to login must be set. + ## The URLs of the devices to query. For each device the corresponding URL + ## including the login credentials must be set. ## E.g. - ## devices = [ + ## URLs = [ ## "http://boxuser:boxpassword@fritz.box:49000/", ## "http://:repeaterpassword@fritz.repeater:49000/", ## ] - devices = [ + URLs = [ ] ## The information to query (see README for further details). diff --git a/plugins/inputs/fritzbox/testdata/fritzbox.conf b/plugins/inputs/fritzbox/testdata/fritzbox.conf index ae46531cc5704..5670e67b5380c 100644 --- a/plugins/inputs/fritzbox/testdata/fritzbox.conf +++ b/plugins/inputs/fritzbox/testdata/fritzbox.conf @@ -1,11 +1,11 @@ - ## The devices to query. For each device the corresponding URL including the - ## user and passwort needed to login must be set. + ## The URLs of the devices to query. For each device the corresponding URL + ## including the login credentials must be set. ## E.g. - ## devices = [ + ## URLs = [ ## "http://boxuser:boxpassword@fritz.box:49000/", ## "http://:repeaterpassword@fritz.repeater:49000/", ## ] - devices = [ + URLs = [ "http://myuser:mypassword@fritz.box", "http://myuser:mypassword@fritz.repeater", ] From 49211795c0c1ff7267b078fa36a3f16d154dd858 Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 17 Jan 2025 05:42:47 +0100 Subject: [PATCH 08/12] feat(inputs.fritzbox): Rework testing code --- go.mod | 2 +- go.sum | 4 +-- plugins/inputs/fritzbox/fritzbox_test.go | 35 +++++++++++-------- .../testdata/metrics/fritzbox_device.txt | 1 + .../testdata/metrics/fritzbox_dsl.txt | 1 + .../testdata/metrics/fritzbox_host.txt | 21 +++++++++++ .../testdata/metrics/fritzbox_ppp.txt | 1 + .../testdata/metrics/fritzbox_wan.txt | 1 + .../testdata/metrics/fritzbox_wlan.txt | 1 + 9 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_device.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_ppp.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_wan.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt diff --git a/go.mod b/go.mod index e9e644f7a434e..b469807461b5e 100644 --- a/go.mod +++ b/go.mod @@ -471,7 +471,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/tdrn-org/go-tr064 v0.2.0 + github.com/tdrn-org/go-tr064 v0.2.1 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/tinylru v1.2.1 // indirect diff --git a/go.sum b/go.sum index a4aa46377cfd0..4d8dc54ac30a6 100644 --- a/go.sum +++ b/go.sum @@ -2321,8 +2321,8 @@ github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7 h1:Jtcrb09q0AVWe3 github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7/go.mod h1:suDIky6yrK07NnaBadCB4sS0CqFOvUK91lH7CR+JlDA= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw= -github.com/tdrn-org/go-tr064 v0.2.0 h1:n2Dz8UdUlZm8jS0coiXl6eRVB4qSz8fcbrHJhPyNVfk= -github.com/tdrn-org/go-tr064 v0.2.0/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.2.1 h1:aYiwDyA/dt5SeP+QhHIdP0E6H+OQTLKrnaD8rXCj/j4= +github.com/tdrn-org/go-tr064 v0.2.1/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0= github.com/testcontainers/testcontainers-go v0.34.0 h1:5fbgF0vIN5u+nD3IWabQwRybuB4GY8G2HHgCkbMzMHo= github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNulFGdFHTD8HB2vLq/231xY2iPQ= diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index 56102d12a50da..d5823bcbd200d 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -6,8 +6,10 @@ import ( "time" "github.com/BurntSushi/toml" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/logger" + "github.com/influxdata/telegraf/plugins/parsers/influx" "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" "github.com/tdrn-org/go-tr064/mock" @@ -17,7 +19,7 @@ func TestInitDefaults(t *testing.T) { plugin := defaultFritzbox() err := plugin.Init() require.NoError(t, err) - require.Equal(t, 0, len(plugin.URLs)) + require.Len(t, plugin.URLs, 0) require.True(t, plugin.DeviceInfo) require.True(t, plugin.WanInfo) require.True(t, plugin.PppInfo) @@ -38,7 +40,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) err = plugin.Init() require.NoError(t, err) - require.Equal(t, 2, len(plugin.URLs)) + require.Len(t, plugin.URLs, 2) require.False(t, plugin.DeviceInfo) require.False(t, plugin.WanInfo) require.False(t, plugin.PppInfo) @@ -80,7 +82,7 @@ func TestGatherDeviceInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_device", []string{"source", "service"}, []string{"uptime", "model_name", "serial_number", "hardware_version", "software_version"}) + testMetric(t, acc, "testdata/metrics/fritzbox_device.txt", telegraf.Untyped) } func TestGatherWanInfo(t *testing.T) { @@ -103,7 +105,7 @@ func TestGatherWanInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_wan", []string{"source", "service"}, []string{"layer1_upstream_max_bit_rate", "layer1_downstream_max_bit_rate", "upstream_current_max_speed", "downstream_current_max_speed", "total_bytes_sent", "total_bytes_received"}) + testMetric(t, acc, "testdata/metrics/fritzbox_wan.txt", telegraf.Untyped) } func TestGatherPppInfo(t *testing.T) { @@ -126,7 +128,7 @@ func TestGatherPppInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_ppp", []string{"source", "service"}, []string{"uptime", "upstream_max_bit_rate", "downstream_max_bit_rate"}) + testMetric(t, acc, "testdata/metrics/fritzbox_ppp.txt", telegraf.Untyped) } func TestGatherDslInfo(t *testing.T) { @@ -149,7 +151,7 @@ func TestGatherDslInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_dsl", []string{"source", "service"}, []string{"upstream_curr_rate", "downstream_curr_rate", "upstream_max_rate", "downstream_max_rate", "upstream_noise_margin", "downstream_noise_margin", "upstream_attenuation", "downstream_attenuation", "upstream_power", "downstream_power", "receive_blocks", "transmit_blocks", "cell_delin", "link_retrain", "init_errors", "init_timeouts", "loss_of_framing", "errored_secs", "severly_errored_secs", "fec_errors", "atuc_fec_errors", "hec_errors", "atuc_hec_errors", "crc_errors", "atuc_crc_errors"}) + testMetric(t, acc, "testdata/metrics/fritzbox_dsl.txt", telegraf.Untyped) } func TestGatherWlanInfo(t *testing.T) { @@ -172,7 +174,7 @@ func TestGatherWlanInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_wlan", []string{"source", "service", "ssid", "channel", "band"}, []string{"total_associations"}) + testMetric(t, acc, "testdata/metrics/fritzbox_wlan.txt", telegraf.Gauge) } func TestGatherHostsInfo(t *testing.T) { @@ -195,15 +197,18 @@ func TestGatherHostsInfo(t *testing.T) { acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMeasurement(t, acc, "fritzbox_host", []string{"source", "service", "host", "host_role", "host_ap", "host_ap_role", "link_type", "link_name"}, []string{"max_data_rate_tx", "max_data_rate_rx", "cur_data_rate_tx", "cur_data_rate_rx"}) + testMetric(t, acc, "testdata/metrics/fritzbox_host.txt", telegraf.Gauge) } -func testMeasurement(t *testing.T, acc *testutil.Accumulator, measurement string, tags []string, fields []string) { - require.Truef(t, acc.HasMeasurement(measurement), "measurement: %s", measurement) - for _, tag := range tags { - require.Truef(t, acc.HasTag(measurement, tag), "measurement: %s tag: %s", measurement, tag) - } - for _, field := range fields { - require.True(t, acc.HasField(measurement, field), "measurement: %s field: %s", measurement, field) +func testMetric(t *testing.T, acc *testutil.Accumulator, file string, vt telegraf.ValueType) { + testutil.PrintMetrics(acc.GetTelegrafMetrics()) + parser := &influx.Parser{} + err := parser.Init() + require.NoError(t, err) + expectedMetrics, err := testutil.ParseMetricsFromFile(file, parser) + for index := range expectedMetrics { + expectedMetrics[index].SetType(vt) } + require.NoError(t, err) + testutil.RequireMetricsEqual(t, expectedMetrics, acc.GetTelegrafMetrics(), testutil.IgnoreTime()) } diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_device.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_device.txt new file mode 100644 index 0000000000000..7c723f0e96f72 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_device.txt @@ -0,0 +1 @@ +fritzbox_device,service=DeviceInfo1,source=127.0.0.1 hardware_version="Mock 1234",model_name="Mock 1234",serial_number="123456789",software_version="1.02.03",uptime=2058438u 1737088489284767000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt new file mode 100644 index 0000000000000..da56124882d89 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt @@ -0,0 +1 @@ +fritzbox_dsl,service=WANDSLInterfaceConfig1,source=127.0.0.1 atuc_crc_errors=13u,atuc_fec_errors=0u,atuc_hec_errors=0u,cell_delin=0u,crc_errors=53u,downstream_attenuation=140u,downstream_curr_rate=249065u,downstream_max_rate=249065u,downstream_noise_margin=60u,downstream_power=513u,errored_secs=25u,fec_errors=0u,hec_errors=0u,init_errors=0u,init_timeouts=0u,link_retrain=2u,loss_of_framing=0u,receive_blocks=490282831u,severly_errored_secs=0u,transmit_blocks=254577751u,upstream_attenuation=80u,upstream_curr_rate=46719i,upstream_max_rate=48873u,upstream_noise_margin=80u,upstream_power=498u 1737088741855188000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt new file mode 100644 index 0000000000000..629b19d1ac806 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt @@ -0,0 +1,21 @@ +fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=216000i,cur_data_rate_tx=216000i,max_data_rate_rx=216000i,max_data_rate_tx=216000i 1737063884317915000 +fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1300000i,cur_data_rate_tx=975000i,max_data_rate_rx=1300000i,max_data_rate_tx=1300000i 1737063884317962000 +fritzbox_host,host=device#4,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317976000 +fritzbox_host,host=device#26,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:2,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317992000 +fritzbox_host,host=device#2,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:3,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318005000 +fritzbox_host,host=device#3,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:4,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318018000 +fritzbox_host,host=device#14,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=65000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318031000 +fritzbox_host,host=device#5,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318043000 +fritzbox_host,host=device#11,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318065000 +fritzbox_host,host=device#11,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=585000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318082000 +fritzbox_host,host=device#16,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318118000 +fritzbox_host,host=device#18,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=526000i,cur_data_rate_tx=780000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318140000 +fritzbox_host,host=device#19,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=650000i,cur_data_rate_tx=1170000i,max_data_rate_rx=1733300i,max_data_rate_tx=1733300i 1737063884318153000 +fritzbox_host,host=device#7,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=780000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318166000 +fritzbox_host,host=device#8,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318179000 +fritzbox_host,host=device#9,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318192000 +fritzbox_host,host=device#13,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318215000 +fritzbox_host,host=device#24,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318233000 +fritzbox_host,host=device#6,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72200i,cur_data_rate_tx=72000i,max_data_rate_rx=72000i,max_data_rate_tx=72000i 1737063884318251000 +fritzbox_host,host=device#10,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318263000 +fritzbox_host,host=device#22,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318275000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_ppp.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_ppp.txt new file mode 100644 index 0000000000000..20730e543e4d0 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_ppp.txt @@ -0,0 +1 @@ +fritzbox_ppp,service=WANPPPConnection1,source=127.0.0.1 downstream_max_bit_rate=68038668u,upstream_max_bit_rate=44213433u,uptime=369434u 1737088658570388000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wan.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wan.txt new file mode 100644 index 0000000000000..c5c13231f6109 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wan.txt @@ -0,0 +1 @@ +fritzbox_wan,service=WANCommonInterfaceConfig1,source=127.0.0.1 downstream_current_max_speed=1304268u,layer1_downstream_max_bit_rate=253247000u,layer1_upstream_max_bit_rate=48816000u,total_bytes_received=554484531337u,total_bytes_sent=129497283207u,upstream_current_max_speed=511831u 1737088572669757000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt new file mode 100644 index 0000000000000..549b4c6a141fe --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt @@ -0,0 +1 @@ +fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=127.0.0.1,ssid=MOCK1234 total_associations=11u 1737063660847310000 From ac19a13ae83232457c5458827462e0157fcd4a5f Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 17 Jan 2025 05:47:52 +0100 Subject: [PATCH 09/12] feat(inputs.fritzbox): Remove unnecessary logging --- plugins/inputs/fritzbox/fritzbox.go | 36 ----------------------------- 1 file changed, 36 deletions(-) diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index adfba87cac921..ad96449959854 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -15,9 +15,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/logger" - "github.com/influxdata/telegraf/metric" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/influxdata/telegraf/plugins/serializers/influx" "github.com/tdrn-org/go-tr064" "github.com/tdrn-org/go-tr064/mesh" "github.com/tdrn-org/go-tr064/services/igddesc/igdicfg" @@ -175,9 +173,6 @@ func (plugin *Fritzbox) gatherDeviceInfo(acc telegraf.Accumulator, deviceClient fields["hardware_version"] = info.NewHardwareVersion fields["software_version"] = info.NewSoftwareVersion acc.AddFields("fritzbox_device", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_device", tags, fields) - } return nil } @@ -228,9 +223,6 @@ func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr fields["total_bytes_sent"] = totalBytesSent fields["total_bytes_received"] = totalBytesReceived acc.AddFields("fritzbox_wan", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_wan", tags, fields) - } return nil } @@ -252,9 +244,6 @@ func (plugin *Fritzbox) gatherPppInfo(acc telegraf.Accumulator, deviceClient *tr fields["upstream_max_bit_rate"] = info.NewUpstreamMaxBitRate fields["downstream_max_bit_rate"] = info.NewDownstreamMaxBitRate acc.AddFields("fritzbox_ppp", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_ppp", tags, fields) - } return nil } @@ -306,9 +295,6 @@ func (plugin *Fritzbox) gatherDslInfo(acc telegraf.Accumulator, deviceClient *tr fields["crc_errors"] = statisticsTotal.NewCRCErrors fields["atuc_crc_errors"] = statisticsTotal.NewATUCCRCErrors acc.AddFields("fritzbox_dsl", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_dsl", tags, fields) - } return nil } @@ -339,9 +325,6 @@ func (plugin *Fritzbox) gatherWlanInfo(acc telegraf.Accumulator, deviceClient *t fields := make(map[string]interface{}) fields["total_associations"] = totalAssociations.NewTotalAssociations acc.AddGauge("fritzbox_wlan", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_wlan", tags, fields) - } return nil } @@ -388,9 +371,6 @@ func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient * fields["cur_data_rate_tx"] = connection.CurDataRateTx fields["cur_data_rate_rx"] = connection.CurDataRateRx acc.AddGauge("fritzbox_host", fields, tags) - if plugin.Log.Level().Includes(telegraf.Debug) { - plugin.logMetric("fritzbox_host", tags, fields) - } } return nil } @@ -431,22 +411,6 @@ func (plugin *Fritzbox) fetchHostsConnections(serviceClient *hosts.ServiceClient return meshList.Connections(), nil } -func (plugin *Fritzbox) logMetric(name string, tags map[string]string, fields map[string]interface{}) { - serializer := &influx.Serializer{} - err := serializer.Init() - if err != nil { - plugin.Log.Error("Failed to initialize Serializer: ", err) - return - } - metric := metric.New(name, tags, fields, time.Now().Round(time.Nanosecond)) - message, err := serializer.Serialize(metric) - if err != nil { - plugin.Log.Error("Failed to serialize metric: ", err) - return - } - plugin.Log.Debug(string(message)) -} - func init() { inputs.Add(pluginName, func() telegraf.Input { return defaultFritzbox() From 9ffdb5365d6efaa15f21609dc796ce850ba0b8cb Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 17 Jan 2025 22:56:24 +0100 Subject: [PATCH 10/12] feat(inputs.fritzbox): Reworked plugin configuration --- go.mod | 2 +- go.sum | 4 +- plugins/inputs/fritzbox/README.md | 138 +++++++++++------- plugins/inputs/fritzbox/fritzbox.go | 101 ++++++------- plugins/inputs/fritzbox/fritzbox_test.go | 100 ++++--------- plugins/inputs/fritzbox/sample.conf | 42 +++--- .../fritzbox/testdata/conf/fritzbox.conf | 31 ++++ .../inputs/fritzbox/testdata/fritzbox.conf | 35 ----- .../testdata/metrics/fritzbox_dsl.txt | 2 +- .../testdata/metrics/fritzbox_host.txt | 21 --- .../testdata/metrics/fritzbox_hosts.txt | 21 +++ .../testdata/metrics/fritzbox_wlan.txt | 2 +- .../testdata/{ => mock}/DeviceInfo.xml | 0 .../fritzbox/testdata/{ => mock}/Hosts.xml | 0 .../{ => mock}/WANCommonInterfaceConfig1.xml | 0 .../{ => mock}/WANCommonInterfaceConfig2.xml | 0 .../{ => mock}/WANDSLInterfaceConfig.xml | 0 .../testdata/{ => mock}/WANPPPConnection.xml | 0 .../testdata/{ => mock}/WLANConfiguration.xml | 0 .../testdata/{ => mock}/dummySCPD.xml | 0 .../fritzbox/testdata/{ => mock}/igddesc.xml | 0 .../testdata/{ => mock}/meshlist.json | 0 .../fritzbox/testdata/{ => mock}/tr64desc.xml | 0 23 files changed, 236 insertions(+), 263 deletions(-) create mode 100644 plugins/inputs/fritzbox/testdata/conf/fritzbox.conf delete mode 100644 plugins/inputs/fritzbox/testdata/fritzbox.conf delete mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt create mode 100644 plugins/inputs/fritzbox/testdata/metrics/fritzbox_hosts.txt rename plugins/inputs/fritzbox/testdata/{ => mock}/DeviceInfo.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/Hosts.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/WANCommonInterfaceConfig1.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/WANCommonInterfaceConfig2.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/WANDSLInterfaceConfig.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/WANPPPConnection.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/WLANConfiguration.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/dummySCPD.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/igddesc.xml (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/meshlist.json (100%) rename plugins/inputs/fritzbox/testdata/{ => mock}/tr64desc.xml (100%) diff --git a/go.mod b/go.mod index b469807461b5e..2e98ffa05fcfb 100644 --- a/go.mod +++ b/go.mod @@ -471,7 +471,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/tdrn-org/go-tr064 v0.2.1 + github.com/tdrn-org/go-tr064 v0.2.2 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/tinylru v1.2.1 // indirect diff --git a/go.sum b/go.sum index 4d8dc54ac30a6..2c51e8d14bacd 100644 --- a/go.sum +++ b/go.sum @@ -2321,8 +2321,8 @@ github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7 h1:Jtcrb09q0AVWe3 github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7/go.mod h1:suDIky6yrK07NnaBadCB4sS0CqFOvUK91lH7CR+JlDA= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o= github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw= -github.com/tdrn-org/go-tr064 v0.2.1 h1:aYiwDyA/dt5SeP+QhHIdP0E6H+OQTLKrnaD8rXCj/j4= -github.com/tdrn-org/go-tr064 v0.2.1/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= +github.com/tdrn-org/go-tr064 v0.2.2 h1:rDybEK1m2xfV5QPWHtnIJOt+xG4GFSkQSwA6FS2bQC4= +github.com/tdrn-org/go-tr064 v0.2.2/go.mod h1:P2WWUiBcXDGOo+sqJ4hWn4YXYH9kWaYjZo74EdFDSS0= github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0= github.com/testcontainers/testcontainers-go v0.34.0 h1:5fbgF0vIN5u+nD3IWabQwRybuB4GY8G2HHgCkbMzMHo= github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNulFGdFHTD8HB2vLq/231xY2iPQ= diff --git a/plugins/inputs/fritzbox/README.md b/plugins/inputs/fritzbox/README.md index c3aafd93739e0..aaa081284a161 100644 --- a/plugins/inputs/fritzbox/README.md +++ b/plugins/inputs/fritzbox/README.md @@ -12,7 +12,7 @@ Retrieved status are: - WAN info (bit rates, transferred bytes, ...) - PPP info (bit rates, connection uptime, ...) - DSL info (bit rates, DSL statistics, ...) -- WLAN info (numbrer of clients per network, ...) +- WLAN info (number of clients per network, ...) - Hosts info (mesh nodes, bit rates, ...) ## Global configuration options @@ -30,39 +30,71 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. # Gather fritzbox status [[inputs.fritzbox]] ## The URLs of the devices to query. For each device the corresponding URL - ## including the login credentials must be set. - ## E.g. - ## URLs = [ + ## including the login credentials must be set. E.g. + ## urls = [ ## "http://boxuser:boxpassword@fritz.box:49000/", ## "http://:repeaterpassword@fritz.repeater:49000/", ## ] - URLs = [ + urls = [ ] - ## The information to query (see README for further details). - ## Hosts info is disabled by default, as it generates an extensive amount - ## of data. - # device_info = true - # wan_info = true - # ppp_info = true - # dsl_info = true - # wlan_info = true - # hosts_info = false - - ## Some metric queries are time-consuming and not collected on every query - ## cycle. This counter defines how often these low-traffic queries - ## are excuted. The default value 30 means, on every 30th query corresponding - ## to every 5 minutes (assuming the standard query interval of 10s). - ## If this option is set to 1 or below, all metrics are collected on every - ## query cycle. - # full_query_cycle = 30 + ## The information to collect (see README for further details). + collect = [ + "device", + "wan", + "ppp", + "dsl", + "wlan", + ] ## The http timeout to use. # timeout = "10s" - ## Skip TLS verification. Is needed to query devices with the default - ## self-signed certificate. - # tls_skip_verify = false + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false +``` + +### Collect options + +The following collect options are available: + +`device` metric: fritzbox_device - Collect device infos like model name, +SW version, uptime for the configured devices. + +`wan` metric: fritzbox_wan - Collect generic WAN connection status like +bit rates, transferred bytes. + +`ppp` metric: fritzbox_ppp - Collect PPP connection parameters like bit +rates, uptime. + +`dsl` metric: fritzbox_dsl - Collect DSL line status and statistics. + +`wlan` metric: fritzbox_wlan - Collect status and number of associated +devices for all WLANs. + +`hosts` metric: fritzbox_hosts - Collect detailed information of the mesh +network including connected nodes, there role in the network as well as +their connection bandwidth. + +**Note**: Collecting this metric is time consuming and it generates +very detailed data. If you activate this option, consider increasing +the plugin's query interval to avoid interval overruns and to minimize +the amount of collected data. You can adapt the interval per collect +otpion as follows: + +```toml +[[inputs.fritzbox]] + collect = [ "device", "wan", "ppp", "dsl", "wlan" ] + ... + +[[inputs.fritzbox]] + interval = "5m" + collect = [ "hosts" ] + ... ``` ## Metrics @@ -72,8 +104,8 @@ specification][1]. - `fritzbox_device` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric - fields - `uptime` (uint) - Device's uptime in seconds. - `model_name` (string) - Device's model name. @@ -82,8 +114,8 @@ specification][1]. - `software_version` (string) - Device's software version. - `fritzbox_wan` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric - fields - `layer1_upstream_max_bit_rate` (uint) - The WAN interface's maximum upstream bit rate (bits/sec) - `layer1_downstream_max_bit_rate` (uint) - The WAN interface's maximum downstream bit rate (bits/sec) @@ -93,16 +125,17 @@ specification][1]. - `total_bytes_received` (uint) - The total number of bytes received via the WAN interface (bytes) - `fritzbox_ppp` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric - fields - `uptime` (uint) - The current uptime of the PPP connection in seconds - `upstream_max_bit_rate` (uint) - The current maximum upstream bit rate negotiated for the PPP connection (bits/sec) - `downstream_max_bit_rate` (uint) - The current maximum downstream bit rate negotiated for the PPP connection (bits/sec) - `fritzbox_dsl` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric + - `status` - The status of the DLS line (Up or Down) - fields - `upstream_curr_rate` (uint) - Current DSL upstream rate (kilobits/sec) - `downstream_curr_rate` (uint) - Current DSL downstream rate (kilobits/sec) @@ -131,23 +164,24 @@ specification][1]. - `atuc_crc_errors` (uint) - Remote (DSLAM) CRC (Cyclic Redundancy Check) errors - `fritzbox_wlan` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric - - `fritz_wlan` - The WLAN SSID (name) - - `fritz_wlan_channel` - The channel used by this WLAN - - `fritz_wlan_band` - The band (in MHz) used by this WLAN + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric + - `wlan` - The WLAN SSID (name) + - `channel` - The channel used by this WLAN + - `band` - The band (in MHz) used by this WLAN + - `status` - The status of the WLAN line (Up or Down) - fields - `total_associations` (uint) - The number of devices connected to this WLAN. -- `fritzbox_host` +- `fritzbox_hosts` - tags - - `fritz_device` - The device name (this metric has been queried from) - - `fritz_service` - The service id used to query this metric - - `fritz_host` - The host connected to the network - - `fritz_host_role` - The host's role ("master" = mesh master, "slave" = mesh slave, "client") in the network - - `fritz_host_peer` - The name of the peer this host is connected to - - `fritz_host_peer_role` - The peer's role ("master" = mesh master, "slave" = mesh slave, never "client") in the network - - `fritz_link_type` - The link type ("WLAN" or "LAN") of the peer connection - - `fritz_link_name` - The link name of the connection + - `source` - The name of the device (this metric has been queried from) + - `service` - The service id used to query this metric + - `node` - The name of the node connected to the mesh network + - `node_role` - The node's role ("master" = mesh master, "slave" = mesh slave, "client") in the network + - `node_ap` - The name of the access point this node is connected to + - `node_ap_role` - The access point's role ("master" = mesh master, "slave" = mesh slave, never "client") in the network + - `link_type` - The link type ("WLAN" or "LAN") of the peer connection + - `link_name` - The link name of the connection - fields - `max_data_rate_tx` (uint) - The connection's maximum transmit rate (kilobits/sec) - `max_data_rate_rx` (uint) - The connection's maximum receive rate (kilobits/sec) @@ -165,12 +199,12 @@ fritzbox_wan,service=WANCommonInterfaceConfig1,source=fritz.box layer1_upstream_ fritzbox_ppp,service=WANPPPConnection1,source=fritz.box uptime=369434i,upstream_max_bit_rate=44213433i,downstream_max_bit_rate=68038668i 1737003622308149000 -fritzbox_dsl,service=WANDSLInterfaceConfig1,source=fritz.box downstream_curr_rate=249065i,downstream_max_rate=249065i,downstream_power=513i,init_timeouts=0i,atuc_crc_errors=13i,errored_secs=25i,atuc_hec_errors=0i,upstream_noise_margin=80i,downstream_noise_margin=60i,downstream_attenuation=140i,receive_blocks=490282831i,transmit_blocks=254577751i,init_errors=0i,crc_errors=53i,fec_errors=0i,hec_errors=0i,upstream_max_rate=48873i,upstream_attenuation=80i,upstream_power=498i,cell_delin=0i,link_retrain=2i,loss_of_framing=0i,upstream_curr_rate=46719i,severly_errored_secs=0i,atuc_fec_errors=0i 1737003645769642000 +fritzbox_dsl,service=WANDSLInterfaceConfig1,source=fritz.box,status=Up downstream_curr_rate=249065i,downstream_max_rate=249065i,downstream_power=513i,init_timeouts=0i,atuc_crc_errors=13i,errored_secs=25i,atuc_hec_errors=0i,upstream_noise_margin=80i,downstream_noise_margin=60i,downstream_attenuation=140i,receive_blocks=490282831i,transmit_blocks=254577751i,init_errors=0i,crc_errors=53i,fec_errors=0i,hec_errors=0i,upstream_max_rate=48873i,upstream_attenuation=80i,upstream_power=498i,cell_delin=0i,link_retrain=2i,loss_of_framing=0i,upstream_curr_rate=46719i,severly_errored_secs=0i,atuc_fec_errors=0i 1737003645769642000 -fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=fritz.box,ssid=MOCK1234 total_associations=11i 1737003673561198000 +fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=fritz.box,ssid=MOCK1234,status=Up total_associations=11i 1737003673561198000 -fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=fritz.box cur_data_rate_tx=216000i,cur_data_rate_rx=216000i,max_data_rate_tx=216000i,max_data_rate_rx=216000i 1737003707257394000 -fritzbox_host,host=device#24,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=fritz.box max_data_rate_tx=1000000i,max_data_rate_rx=1000000i,cur_data_rate_tx=0i,cur_data_rate_rx=0i 1737003707257248000 +fritzbox_hosts,node=device#17,node_ap=device#1,node_ap_role=master,node_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=fritz.box cur_data_rate_tx=216000i,cur_data_rate_rx=216000i,max_data_rate_tx=216000i,max_data_rate_rx=216000i 1737003707257394000 +fritzbox_hosts,node=device#24,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=fritz.box max_data_rate_tx=1000000i,max_data_rate_rx=1000000i,cur_data_rate_tx=0i,cur_data_rate_rx=0i 1737003707257248000 ``` -. + diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index ad96449959854..3400789b57ccd 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -14,7 +14,9 @@ import ( "github.com/google/uuid" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" + "github.com/influxdata/telegraf/internal/choice" "github.com/influxdata/telegraf/logger" + "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/inputs" "github.com/tdrn-org/go-tr064" "github.com/tdrn-org/go-tr064/mesh" @@ -35,36 +37,22 @@ const pluginName = "fritzbox" const defaultTimeout = config.Duration(10 * time.Second) type Fritzbox struct { - URLs []string `toml:"urls"` - DeviceInfo bool `toml:"device_info"` - WanInfo bool `toml:"wan_info"` - PppInfo bool `toml:"ppp_info"` - DslInfo bool `toml:"dsl_info"` - WlanInfo bool `toml:"wlan_info"` - HostsInfo bool `toml:"hosts_info"` - FullQueryCycle int `toml:"full_query_cycle"` - Timeout config.Duration `toml:"timeout"` - TlsSkipVerify bool `toml:"tls_skip_verify"` - Log telegraf.Logger `toml:"-"` - deviceClients []*tr064.Client - serviceHandlers map[string]serviceHandlerFunc - queryCycleCounter int + URLs []string `toml:"urls"` + Collect []string `toml:"collect"` + Timeout config.Duration `toml:"timeout"` + tls.ClientConfig + Log telegraf.Logger `toml:"-"` + deviceClients []*tr064.Client + serviceHandlers map[string]serviceHandlerFunc } func defaultFritzbox() *Fritzbox { return &Fritzbox{ - URLs: make([]string, 0), - DeviceInfo: true, - WanInfo: true, - PppInfo: true, - DslInfo: true, - WlanInfo: true, - HostsInfo: false, - FullQueryCycle: 30, - Timeout: defaultTimeout, - deviceClients: make([]*tr064.Client, 0), - serviceHandlers: make(map[string]serviceHandlerFunc), - queryCycleCounter: 0, + URLs: make([]string, 0), + Collect: []string{"device", "wan", "ppp", "dsl", "wlan"}, + Timeout: defaultTimeout, + deviceClients: make([]*tr064.Client, 0), + serviceHandlers: make(map[string]serviceHandlerFunc), } } @@ -93,29 +81,33 @@ func (plugin *Fritzbox) initDeviceClients() error { client := tr064.NewClient(parsedUrl) client.Debug = plugin.Log.Level().Includes(telegraf.Debug) client.Timeout = time.Duration(plugin.Timeout) - client.InsecureSkipVerify = plugin.TlsSkipVerify + tlsConfig, err := plugin.TLSConfig() + if err != nil { + return err + } + client.TlsConfig = tlsConfig plugin.deviceClients = append(plugin.deviceClients, client) } return nil } func (plugin *Fritzbox) initServiceHandlers() { - if plugin.DeviceInfo { + if choice.Contains("device", plugin.Collect) { plugin.serviceHandlers[deviceinfo.ServiceShortType] = plugin.gatherDeviceInfo } - if plugin.WanInfo { + if choice.Contains("wan", plugin.Collect) { plugin.serviceHandlers[wancommonifconfig.ServiceShortType] = plugin.gatherWanInfo } - if plugin.PppInfo { + if choice.Contains("ppp", plugin.Collect) { plugin.serviceHandlers[wanpppconn.ServiceShortType] = plugin.gatherPppInfo } - if plugin.DslInfo { + if choice.Contains("dsl", plugin.Collect) { plugin.serviceHandlers[wandslifconfig.ServiceShortType] = plugin.gatherDslInfo } - if plugin.WlanInfo { + if choice.Contains("wlan", plugin.Collect) { plugin.serviceHandlers[wlanconfig.ServiceShortType] = plugin.gatherWlanInfo } - if plugin.HostsInfo { + if choice.Contains("hosts", plugin.Collect) { plugin.serviceHandlers[hosts.ServiceShortType] = plugin.gatherHostsInfo } } @@ -124,10 +116,6 @@ func (plugin *Fritzbox) Gather(acc telegraf.Accumulator) error { for _, deviceClient := range plugin.deviceClients { plugin.gatherDevice(acc, deviceClient) } - plugin.queryCycleCounter++ - if plugin.queryCycleCounter >= plugin.FullQueryCycle { - plugin.queryCycleCounter = 0 - } return nil } @@ -192,7 +180,7 @@ func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr return err } if len(igdServices) == 0 { - return fmt.Errorf("") + return fmt.Errorf("IGD service not available") } igdServiceClient := &igdicfg.ServiceClient{ TR064Client: deviceClient, @@ -257,17 +245,17 @@ func (plugin *Fritzbox) gatherDslInfo(acc telegraf.Accumulator, deviceClient *tr if err != nil { return err } - if info.NewStatus != "Up" { - return nil - } statisticsTotal := &wandslifconfig.GetStatisticsTotalResponse{} - err = serviceClient.GetStatisticsTotal(statisticsTotal) - if err != nil { - return err + if info.NewStatus == "Up" { + err = serviceClient.GetStatisticsTotal(statisticsTotal) + if err != nil { + return err + } } tags := make(map[string]string) tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() tags["service"] = serviceClient.Service.ShortId() + tags["status"] = info.NewStatus fields := make(map[string]interface{}) fields["upstream_curr_rate"] = info.NewUpstreamCurrRate fields["downstream_curr_rate"] = info.NewDownstreamCurrRate @@ -308,17 +296,17 @@ func (plugin *Fritzbox) gatherWlanInfo(acc telegraf.Accumulator, deviceClient *t if err != nil { return err } - if info.NewStatus != "Up" { - return nil - } totalAssociations := &wlanconfig.GetTotalAssociationsResponse{} - err = serviceClient.GetTotalAssociations(totalAssociations) - if err != nil { - return err + if info.NewStatus == "Up" { + err = serviceClient.GetTotalAssociations(totalAssociations) + if err != nil { + return err + } } tags := make(map[string]string) tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() tags["service"] = serviceClient.Service.ShortId() + tags["status"] = info.NewStatus tags["ssid"] = info.NewSSID tags["channel"] = strconv.Itoa(int(info.NewChannel)) tags["band"] = plugin.wlanBandFromInfo(info) @@ -340,9 +328,6 @@ func (plugin *Fritzbox) wlanBandFromInfo(info *wlanconfig.GetInfoResponse) strin } func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient *tr064.Client, service tr064.ServiceDescriptor) error { - if plugin.queryCycleCounter != 0 { - return nil - } serviceClient := hosts.ServiceClient{ TR064Client: deviceClient, Service: service, @@ -359,10 +344,10 @@ func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient * tags := make(map[string]string) tags["source"] = serviceClient.TR064Client.DeviceUrl.Hostname() tags["service"] = serviceClient.Service.ShortId() - tags["host"] = connection.RightDeviceName - tags["host_role"] = plugin.hostRole(connection.RightMeshRole) - tags["host_ap"] = connection.LeftDeviceName - tags["host_ap_role"] = plugin.hostRole(connection.LeftMeshRole) + tags["node"] = connection.RightDeviceName + tags["node_role"] = plugin.hostRole(connection.RightMeshRole) + tags["node_ap"] = connection.LeftDeviceName + tags["node_ap_role"] = plugin.hostRole(connection.LeftMeshRole) tags["link_type"] = connection.InterfaceType tags["link_name"] = connection.InterfaceName fields := make(map[string]interface{}) @@ -370,7 +355,7 @@ func (plugin *Fritzbox) gatherHostsInfo(acc telegraf.Accumulator, deviceClient * fields["max_data_rate_rx"] = connection.MaxDataRateRx fields["cur_data_rate_tx"] = connection.CurDataRateTx fields["cur_data_rate_rx"] = connection.CurDataRateRx - acc.AddGauge("fritzbox_host", fields, tags) + acc.AddGauge("fritzbox_hosts", fields, tags) } return nil } diff --git a/plugins/inputs/fritzbox/fritzbox_test.go b/plugins/inputs/fritzbox/fritzbox_test.go index d5823bcbd200d..87c8b97d99848 100644 --- a/plugins/inputs/fritzbox/fritzbox_test.go +++ b/plugins/inputs/fritzbox/fritzbox_test.go @@ -20,20 +20,18 @@ func TestInitDefaults(t *testing.T) { err := plugin.Init() require.NoError(t, err) require.Len(t, plugin.URLs, 0) - require.True(t, plugin.DeviceInfo) - require.True(t, plugin.WanInfo) - require.True(t, plugin.PppInfo) - require.True(t, plugin.DslInfo) - require.True(t, plugin.WlanInfo) - require.False(t, plugin.HostsInfo) - require.Equal(t, 30, plugin.FullQueryCycle) + require.Equal(t, []string{"device", "wan", "ppp", "dsl", "wlan"}, plugin.Collect) require.Equal(t, defaultTimeout, plugin.Timeout) - require.False(t, plugin.TlsSkipVerify) + require.Empty(t, plugin.TLSCA) + require.Empty(t, plugin.TLSCert) + require.Empty(t, plugin.TLSKey) + require.Empty(t, plugin.TLSKeyPwd) + require.False(t, plugin.InsecureSkipVerify) require.NotNil(t, plugin.Log) } func TestConfig(t *testing.T) { - conf, err := os.ReadFile("testdata/fritzbox.conf") + conf, err := os.ReadFile("testdata/conf/fritzbox.conf") require.NoError(t, err) var plugin = defaultFritzbox() err = toml.Unmarshal(conf, plugin) @@ -41,42 +39,34 @@ func TestConfig(t *testing.T) { err = plugin.Init() require.NoError(t, err) require.Len(t, plugin.URLs, 2) - require.False(t, plugin.DeviceInfo) - require.False(t, plugin.WanInfo) - require.False(t, plugin.PppInfo) - require.False(t, plugin.DslInfo) - require.False(t, plugin.WlanInfo) - require.True(t, plugin.HostsInfo) - require.Equal(t, 6, plugin.FullQueryCycle) + require.Equal(t, []string{"device", "wan", "ppp", "dsl", "wlan", "hosts"}, plugin.Collect) require.Equal(t, config.Duration(60*time.Second), plugin.Timeout) - require.True(t, plugin.TlsSkipVerify) + require.Equal(t, "secret", plugin.TLSKeyPwd) + require.True(t, plugin.InsecureSkipVerify) } +const mockDocsDir = "testdata/mock" + var testMocks = []*mock.ServiceMock{ - mock.ServiceMockFromFile("/deviceinfo", "testdata/DeviceInfo.xml"), - mock.ServiceMockFromFile("/wancommonifconfig", "testdata/WANCommonInterfaceConfig1.xml"), - mock.ServiceMockFromFile("/WANCommonIFC1", "testdata/WANCommonInterfaceConfig2.xml"), - mock.ServiceMockFromFile("/wanpppconn", "testdata/WANPPPConnection.xml"), - mock.ServiceMockFromFile("/wandslifconfig", "testdata/WANDSLInterfaceConfig.xml"), - mock.ServiceMockFromFile("/wlanconfig", "testdata/WLANConfiguration.xml"), - mock.ServiceMockFromFile("/hosts", "testdata/Hosts.xml"), + mock.ServiceMockFromFile("/deviceinfo", "testdata/mock/DeviceInfo.xml"), + mock.ServiceMockFromFile("/wancommonifconfig", "testdata/mock/WANCommonInterfaceConfig1.xml"), + mock.ServiceMockFromFile("/WANCommonIFC1", "testdata/mock/WANCommonInterfaceConfig2.xml"), + mock.ServiceMockFromFile("/wanpppconn", "testdata/mock/WANPPPConnection.xml"), + mock.ServiceMockFromFile("/wandslifconfig", "testdata/mock/WANDSLInterfaceConfig.xml"), + mock.ServiceMockFromFile("/wlanconfig", "testdata/mock/WLANConfiguration.xml"), + mock.ServiceMockFromFile("/hosts", "testdata/mock/Hosts.xml"), } func TestGatherDeviceInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = true - plugin.WanInfo = false - plugin.PppInfo = false - plugin.DslInfo = false - plugin.WlanInfo = false - plugin.HostsInfo = false + plugin.Collect = []string{"device"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -87,19 +77,14 @@ func TestGatherDeviceInfo(t *testing.T) { func TestGatherWanInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = false - plugin.WanInfo = true - plugin.PppInfo = false - plugin.DslInfo = false - plugin.WlanInfo = false - plugin.HostsInfo = false + plugin.Collect = []string{"wan"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -110,19 +95,14 @@ func TestGatherWanInfo(t *testing.T) { func TestGatherPppInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = false - plugin.WanInfo = false - plugin.PppInfo = true - plugin.DslInfo = false - plugin.WlanInfo = false - plugin.HostsInfo = false + plugin.Collect = []string{"ppp"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -133,19 +113,14 @@ func TestGatherPppInfo(t *testing.T) { func TestGatherDslInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = false - plugin.WanInfo = false - plugin.PppInfo = false - plugin.DslInfo = true - plugin.WlanInfo = false - plugin.HostsInfo = false + plugin.Collect = []string{"dsl"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -156,19 +131,14 @@ func TestGatherDslInfo(t *testing.T) { func TestGatherWlanInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = false - plugin.WanInfo = false - plugin.PppInfo = false - plugin.DslInfo = false - plugin.WlanInfo = true - plugin.HostsInfo = false + plugin.Collect = []string{"wlan"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} @@ -179,29 +149,23 @@ func TestGatherWlanInfo(t *testing.T) { func TestGatherHostsInfo(t *testing.T) { // Start mock server - tr064Server := mock.Start("testdata", testMocks...) + tr064Server := mock.Start(mockDocsDir, testMocks...) defer tr064Server.Shutdown() // Enable debug logging logger.SetupLogging(&logger.Config{Debug: true}) // Actual test plugin := defaultFritzbox() plugin.URLs = append(plugin.URLs, tr064Server.Server().String()) - plugin.DeviceInfo = false - plugin.WanInfo = false - plugin.PppInfo = false - plugin.DslInfo = false - plugin.WlanInfo = false - plugin.HostsInfo = true + plugin.Collect = []string{"hosts"} err := plugin.Init() require.NoError(t, err) acc := &testutil.Accumulator{} err = acc.GatherError(plugin.Gather) require.NoError(t, err) - testMetric(t, acc, "testdata/metrics/fritzbox_host.txt", telegraf.Gauge) + testMetric(t, acc, "testdata/metrics/fritzbox_hosts.txt", telegraf.Gauge) } func testMetric(t *testing.T, acc *testutil.Accumulator, file string, vt telegraf.ValueType) { - testutil.PrintMetrics(acc.GetTelegrafMetrics()) parser := &influx.Parser{} err := parser.Init() require.NoError(t, err) diff --git a/plugins/inputs/fritzbox/sample.conf b/plugins/inputs/fritzbox/sample.conf index 56f28481c1b08..11f3168b2f506 100644 --- a/plugins/inputs/fritzbox/sample.conf +++ b/plugins/inputs/fritzbox/sample.conf @@ -1,36 +1,30 @@ # Gather fritzbox status [[inputs.fritzbox]] ## The URLs of the devices to query. For each device the corresponding URL - ## including the login credentials must be set. - ## E.g. - ## URLs = [ + ## including the login credentials must be set. E.g. + ## urls = [ ## "http://boxuser:boxpassword@fritz.box:49000/", ## "http://:repeaterpassword@fritz.repeater:49000/", ## ] - URLs = [ + urls = [ ] - ## The information to query (see README for further details). - ## Hosts info is disabled by default, as it generates an extensive amount - ## of data. - # device_info = true - # wan_info = true - # ppp_info = true - # dsl_info = true - # wlan_info = true - # hosts_info = false - - ## Some metric queries are time-consuming and not collected on every query - ## cycle. This counter defines how often these low-traffic queries - ## are excuted. The default value 30 means, on every 30th query corresponding - ## to every 5 minutes (assuming the standard query interval of 10s). - ## If this option is set to 1 or below, all metrics are collected on every - ## query cycle. - # full_query_cycle = 30 + ## The information to collect (see README for further details). + collect = [ + "device", + "wan", + "ppp", + "dsl", + "wlan", + ] ## The http timeout to use. # timeout = "10s" - ## Skip TLS verification. Is needed to query devices with the default - ## self-signed certificate. - # tls_skip_verify = false + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + # tls_key_pwd = "secret" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false diff --git a/plugins/inputs/fritzbox/testdata/conf/fritzbox.conf b/plugins/inputs/fritzbox/testdata/conf/fritzbox.conf new file mode 100644 index 0000000000000..d627e221c097a --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/conf/fritzbox.conf @@ -0,0 +1,31 @@ + ## The URLs of the devices to query. For each device the corresponding URL + ## including the login credentials must be set. E.g. + ## urls = [ + ## "http://boxuser:boxpassword@fritz.box:49000/", + ## "http://:repeaterpassword@fritz.repeater:49000/", + ## ] + urls = [ + "http://boxuser:boxpassword@fritz.box:49000/", + "http://:repeaterpassword@fritz.repeater:49000/", + ] + + ## The information to collect (see README for further details). + collect = [ + "device", + "wan", + "ppp", + "dsl", + "wlan", + "hosts", + ] + + ## The http timeout to use. + timeout = "1m" + + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + tls_key_pwd = "secret" + ## Use TLS but skip chain & host verification + insecure_skip_verify = true diff --git a/plugins/inputs/fritzbox/testdata/fritzbox.conf b/plugins/inputs/fritzbox/testdata/fritzbox.conf deleted file mode 100644 index 5670e67b5380c..0000000000000 --- a/plugins/inputs/fritzbox/testdata/fritzbox.conf +++ /dev/null @@ -1,35 +0,0 @@ - ## The URLs of the devices to query. For each device the corresponding URL - ## including the login credentials must be set. - ## E.g. - ## URLs = [ - ## "http://boxuser:boxpassword@fritz.box:49000/", - ## "http://:repeaterpassword@fritz.repeater:49000/", - ## ] - URLs = [ - "http://myuser:mypassword@fritz.box", - "http://myuser:mypassword@fritz.repeater", - ] - - ## The information to query (see README for further details). - ## Hosts info is disabled by default, as it generates an extensive amount - ## of data. - device_info = false - wan_info = false - ppp_info = false - dsl_info = false - wlan_info = false - hosts_info = true - - ## Some metric queries are time-consuming and not collected on every query - ## cycle. This counter defines how often these low-traffic queries - ## are excuted. The default value 30 means, on every 30th query corresponding - ## to every 5 minutes (assuming the standard query interval of 10s). - ## If this option is set to 1 or below, all metrics are collected on every - ## query cycle. - full_query_cycle = 6 - - ## The http timeout to use (in seconds). - timeout = "1m" - - ## Skip TLS verification (insecure) - tls_skip_verify = true diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt index da56124882d89..891f1bdcd82b8 100644 --- a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_dsl.txt @@ -1 +1 @@ -fritzbox_dsl,service=WANDSLInterfaceConfig1,source=127.0.0.1 atuc_crc_errors=13u,atuc_fec_errors=0u,atuc_hec_errors=0u,cell_delin=0u,crc_errors=53u,downstream_attenuation=140u,downstream_curr_rate=249065u,downstream_max_rate=249065u,downstream_noise_margin=60u,downstream_power=513u,errored_secs=25u,fec_errors=0u,hec_errors=0u,init_errors=0u,init_timeouts=0u,link_retrain=2u,loss_of_framing=0u,receive_blocks=490282831u,severly_errored_secs=0u,transmit_blocks=254577751u,upstream_attenuation=80u,upstream_curr_rate=46719i,upstream_max_rate=48873u,upstream_noise_margin=80u,upstream_power=498u 1737088741855188000 +fritzbox_dsl,service=WANDSLInterfaceConfig1,source=127.0.0.1,status=Up atuc_crc_errors=13u,atuc_fec_errors=0u,atuc_hec_errors=0u,cell_delin=0u,crc_errors=53u,downstream_attenuation=140u,downstream_curr_rate=249065u,downstream_max_rate=249065u,downstream_noise_margin=60u,downstream_power=513u,errored_secs=25u,fec_errors=0u,hec_errors=0u,init_errors=0u,init_timeouts=0u,link_retrain=2u,loss_of_framing=0u,receive_blocks=490282831u,severly_errored_secs=0u,transmit_blocks=254577751u,upstream_attenuation=80u,upstream_curr_rate=46719i,upstream_max_rate=48873u,upstream_noise_margin=80u,upstream_power=498u 1737088741855188000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt deleted file mode 100644 index 629b19d1ac806..0000000000000 --- a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_host.txt +++ /dev/null @@ -1,21 +0,0 @@ -fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=216000i,cur_data_rate_tx=216000i,max_data_rate_rx=216000i,max_data_rate_tx=216000i 1737063884317915000 -fritzbox_host,host=device#17,host_ap=device#1,host_ap_role=master,host_role=slave,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1300000i,cur_data_rate_tx=975000i,max_data_rate_rx=1300000i,max_data_rate_tx=1300000i 1737063884317962000 -fritzbox_host,host=device#4,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317976000 -fritzbox_host,host=device#26,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:2,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317992000 -fritzbox_host,host=device#2,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:3,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318005000 -fritzbox_host,host=device#3,host_ap=device#1,host_ap_role=master,host_role=client,link_name=LAN:4,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318018000 -fritzbox_host,host=device#14,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=65000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318031000 -fritzbox_host,host=device#5,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318043000 -fritzbox_host,host=device#11,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318065000 -fritzbox_host,host=device#11,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=585000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318082000 -fritzbox_host,host=device#16,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318118000 -fritzbox_host,host=device#18,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=526000i,cur_data_rate_tx=780000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318140000 -fritzbox_host,host=device#19,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=650000i,cur_data_rate_tx=1170000i,max_data_rate_rx=1733300i,max_data_rate_tx=1733300i 1737063884318153000 -fritzbox_host,host=device#7,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=780000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318166000 -fritzbox_host,host=device#8,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318179000 -fritzbox_host,host=device#9,host_ap=device#1,host_ap_role=master,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318192000 -fritzbox_host,host=device#13,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318215000 -fritzbox_host,host=device#24,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318233000 -fritzbox_host,host=device#6,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72200i,cur_data_rate_tx=72000i,max_data_rate_rx=72000i,max_data_rate_tx=72000i 1737063884318251000 -fritzbox_host,host=device#10,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318263000 -fritzbox_host,host=device#22,host_ap=device#17,host_ap_role=slave,host_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318275000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_hosts.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_hosts.txt new file mode 100644 index 0000000000000..7a5bc13dc73c0 --- /dev/null +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_hosts.txt @@ -0,0 +1,21 @@ +fritzbox_hosts,node=device#17,node_ap=device#1,node_ap_role=master,node_role=slave,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=216000i,cur_data_rate_tx=216000i,max_data_rate_rx=216000i,max_data_rate_tx=216000i 1737063884317915000 +fritzbox_hosts,node=device#17,node_ap=device#1,node_ap_role=master,node_role=slave,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1300000i,cur_data_rate_tx=975000i,max_data_rate_rx=1300000i,max_data_rate_tx=1300000i 1737063884317962000 +fritzbox_hosts,node=device#4,node_ap=device#1,node_ap_role=master,node_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317976000 +fritzbox_hosts,node=device#26,node_ap=device#1,node_ap_role=master,node_role=client,link_name=LAN:2,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=1000000i,cur_data_rate_tx=1000000i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884317992000 +fritzbox_hosts,node=device#2,node_ap=device#1,node_ap_role=master,node_role=client,link_name=LAN:3,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318005000 +fritzbox_hosts,node=device#3,node_ap=device#1,node_ap_role=master,node_role=client,link_name=LAN:4,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=100000i,cur_data_rate_tx=100000i,max_data_rate_rx=100000i,max_data_rate_tx=100000i 1737063884318018000 +fritzbox_hosts,node=device#14,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=65000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318031000 +fritzbox_hosts,node=device#5,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72000i,cur_data_rate_tx=72000i,max_data_rate_rx=72200i,max_data_rate_tx=72200i 1737063884318043000 +fritzbox_hosts,node=device#11,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318065000 +fritzbox_hosts,node=device#11,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=585000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318082000 +fritzbox_hosts,node=device#16,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318118000 +fritzbox_hosts,node=device#18,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=526000i,cur_data_rate_tx=780000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318140000 +fritzbox_hosts,node=device#19,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=650000i,cur_data_rate_tx=1170000i,max_data_rate_rx=1733300i,max_data_rate_tx=1733300i 1737063884318153000 +fritzbox_hosts,node=device#7,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=780000i,cur_data_rate_tx=866000i,max_data_rate_rx=866700i,max_data_rate_tx=866700i 1737063884318166000 +fritzbox_hosts,node=device#8,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318179000 +fritzbox_hosts,node=device#9,node_ap=device#1,node_ap_role=master,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=390000i,cur_data_rate_tx=433000i,max_data_rate_rx=433300i,max_data_rate_tx=433300i 1737063884318192000 +fritzbox_hosts,node=device#13,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318215000 +fritzbox_hosts,node=device#24,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=LAN:1,link_type=LAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=0i,cur_data_rate_tx=0i,max_data_rate_rx=1000000i,max_data_rate_tx=1000000i 1737063884318233000 +fritzbox_hosts,node=device#6,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=AP:2G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=72200i,cur_data_rate_tx=72000i,max_data_rate_rx=72000i,max_data_rate_tx=72000i 1737063884318251000 +fritzbox_hosts,node=device#10,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318263000 +fritzbox_hosts,node=device#22,node_ap=device#17,node_ap_role=slave,node_role=client,link_name=AP:5G:0,link_type=WLAN,service=Hosts1,source=127.0.0.1 cur_data_rate_rx=866700i,cur_data_rate_tx=866000i,max_data_rate_rx=866000i,max_data_rate_tx=866000i 1737063884318275000 diff --git a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt index 549b4c6a141fe..6b7bed1c96448 100644 --- a/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt +++ b/plugins/inputs/fritzbox/testdata/metrics/fritzbox_wlan.txt @@ -1 +1 @@ -fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=127.0.0.1,ssid=MOCK1234 total_associations=11u 1737063660847310000 +fritzbox_wlan,band=2400,channel=13,service=WLANConfiguration1,source=127.0.0.1,ssid=MOCK1234,status=Up total_associations=11u 1737063660847310000 diff --git a/plugins/inputs/fritzbox/testdata/DeviceInfo.xml b/plugins/inputs/fritzbox/testdata/mock/DeviceInfo.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/DeviceInfo.xml rename to plugins/inputs/fritzbox/testdata/mock/DeviceInfo.xml diff --git a/plugins/inputs/fritzbox/testdata/Hosts.xml b/plugins/inputs/fritzbox/testdata/mock/Hosts.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/Hosts.xml rename to plugins/inputs/fritzbox/testdata/mock/Hosts.xml diff --git a/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml b/plugins/inputs/fritzbox/testdata/mock/WANCommonInterfaceConfig1.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig1.xml rename to plugins/inputs/fritzbox/testdata/mock/WANCommonInterfaceConfig1.xml diff --git a/plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml b/plugins/inputs/fritzbox/testdata/mock/WANCommonInterfaceConfig2.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/WANCommonInterfaceConfig2.xml rename to plugins/inputs/fritzbox/testdata/mock/WANCommonInterfaceConfig2.xml diff --git a/plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml b/plugins/inputs/fritzbox/testdata/mock/WANDSLInterfaceConfig.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/WANDSLInterfaceConfig.xml rename to plugins/inputs/fritzbox/testdata/mock/WANDSLInterfaceConfig.xml diff --git a/plugins/inputs/fritzbox/testdata/WANPPPConnection.xml b/plugins/inputs/fritzbox/testdata/mock/WANPPPConnection.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/WANPPPConnection.xml rename to plugins/inputs/fritzbox/testdata/mock/WANPPPConnection.xml diff --git a/plugins/inputs/fritzbox/testdata/WLANConfiguration.xml b/plugins/inputs/fritzbox/testdata/mock/WLANConfiguration.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/WLANConfiguration.xml rename to plugins/inputs/fritzbox/testdata/mock/WLANConfiguration.xml diff --git a/plugins/inputs/fritzbox/testdata/dummySCPD.xml b/plugins/inputs/fritzbox/testdata/mock/dummySCPD.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/dummySCPD.xml rename to plugins/inputs/fritzbox/testdata/mock/dummySCPD.xml diff --git a/plugins/inputs/fritzbox/testdata/igddesc.xml b/plugins/inputs/fritzbox/testdata/mock/igddesc.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/igddesc.xml rename to plugins/inputs/fritzbox/testdata/mock/igddesc.xml diff --git a/plugins/inputs/fritzbox/testdata/meshlist.json b/plugins/inputs/fritzbox/testdata/mock/meshlist.json similarity index 100% rename from plugins/inputs/fritzbox/testdata/meshlist.json rename to plugins/inputs/fritzbox/testdata/mock/meshlist.json diff --git a/plugins/inputs/fritzbox/testdata/tr64desc.xml b/plugins/inputs/fritzbox/testdata/mock/tr64desc.xml similarity index 100% rename from plugins/inputs/fritzbox/testdata/tr64desc.xml rename to plugins/inputs/fritzbox/testdata/mock/tr64desc.xml From 6974a96af5cdc3aa17b41d5eab129fee7739dc71 Mon Sep 17 00:00:00 2001 From: Holger Date: Fri, 17 Jan 2025 23:09:08 +0100 Subject: [PATCH 11/12] feat(inputs.fritzbox): Fix Errorf format --- plugins/inputs/fritzbox/fritzbox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index 3400789b57ccd..5a4ae69a9ae4a 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -381,7 +381,7 @@ func (plugin *Fritzbox) fetchHostsConnections(serviceClient *hosts.ServiceClient return make([]*mesh.Connection, 0), nil } if meshListResponse.StatusCode != http.StatusOK { - return nil, fmt.Errorf("failed to fetch mesh list '%s' (status: %s)", meshListPath.NewX_AVM_DE_MeshListPath, meshListResponse.Status) + return nil, fmt.Errorf("failed to fetch mesh list %q (status: %s)", meshListPath.NewX_AVM_DE_MeshListPath, meshListResponse.Status) } defer meshListResponse.Body.Close() meshListBytes, err := io.ReadAll(meshListResponse.Body) From 779ebfa16c4dcfd1bd7e106b9fd2e3905ba1af08 Mon Sep 17 00:00:00 2001 From: Holger Date: Sat, 18 Jan 2025 08:27:30 +0100 Subject: [PATCH 12/12] feat(inputs.fritzbox): Fixed double conversion --- plugins/inputs/fritzbox/fritzbox.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inputs/fritzbox/fritzbox.go b/plugins/inputs/fritzbox/fritzbox.go index 5a4ae69a9ae4a..9bf6a43de4a2e 100644 --- a/plugins/inputs/fritzbox/fritzbox.go +++ b/plugins/inputs/fritzbox/fritzbox.go @@ -191,7 +191,6 @@ func (plugin *Fritzbox) gatherWanInfo(acc telegraf.Accumulator, deviceClient *tr if err != nil { return err } - strconv.ParseUint(addonInfos.NewX_AVM_DE_TotalBytesSent64, 10, 64) totalBytesSent, err := strconv.ParseUint(addonInfos.NewX_AVM_DE_TotalBytesSent64, 10, 64) if err != nil { return err