pdreker / fritz_exporter

Prometheus exporter for Fritz!Box home routers
Other
145 stars 32 forks source link

Fritzbox 7270 UPnPError: 402 Invalid Args #203

Closed Apfelwurm closed 11 months ago

Apfelwurm commented 11 months ago

Hey there,

when using a FRITZ!Box Fon WLAN 7270 v3 i get the following error:

Exception has occurred: FritzArgumentError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
UPnPError: 
errorCode: 402
errorDescription: Invalid Args
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 191, in raise_fritzconnection_error
    raise exception(message)
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 268, in handle_response
    raise_fritzconnection_error(response)
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 286, in execute
    return handle_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/fritzconnection.py", line 441, in call_action
    return self.soaper.execute(service, action_name, arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/fritzexporter/fritzcapabilities.py", line 56, in checkCapability
    device.fc.call_action(svc, action)
  File "/home/volza/Projects/fritz_exporter/fritzexporter/fritzcapabilities.py", line 112, in check_present
    self.capabilities[c].checkCapability(device)
  File "/home/volza/Projects/fritz_exporter/fritzexporter/fritzcapabilities.py", line 87, in __init__
    self.check_present(device)
  File "/home/volza/Projects/fritz_exporter/fritzexporter/fritzdevice.py", line 39, in __init__
    self.capabilities = FritzCapabilities(self, host_info)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/fritzexporter/__main__.py", line 92, in main
    fritz_device = FritzDevice(
                   ^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/fritzexporter/__main__.py", line 128, in <module>
    main()
  File "/usr/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.11/runpy.py", line 198, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fritzconnection.core.exceptions.FritzArgumentError: UPnPError: 
errorCode: 402
errorDescription: Invalid Args

it happens right after

DEBUG fritzexporter.fritzcapability | Capability WanPPPConnectionStatus set to True on device fb-7270-01..local

so i could narrow down that commenting out the WanPPPConnectionStatus class "fixes" the breaking of the exporter at least.

The output of fritzconnection -i fb-7270-01..local -s

fritzconnection v1.12.2
FRITZ!Box Fon WLAN 7270 v3 at http://fb-7270-01..local
FRITZ!OS: None

Servicenames:
                    any1
                    WANCommonIFC1
                    WANDSLLinkC1
                    WANIPConn1
                    DeviceInfo1
                    DeviceConfig1
                    Layer3Forwarding1
                    LANConfigSecurity1
                    ManagementServer1
                    Time1
                    UserInterface1
                    X_VoIP1
                    X_AVM-DE_Storage1
                    X_AVM-DE_OnTel1
                    X_AVM-DE_WebDAVClient1
                    X_AVM-DE_UPnP1
                    X_AVM-DE_RemoteAccess1
                    X_AVM-DE_MyFritz1
                    X_AVM-DE_TAM1
                    WLANConfiguration1
                    WLANConfiguration2
                    Hosts1
                    LANEthernetInterfaceConfig1
                    LANHostConfigManagement1
                    WANCommonInterfaceConfig1
                    WANDSLInterfaceConfig1
                    WANDSLLinkConfig1
                    WANEthernetLinkConfig1
                    WANPPPConnection1
                    WANIPConnection1

The output of fritzconnection -i fb-7270-01..local -S WANPPPConnection1

fritzconnection v1.12.2
FRITZ!Box Fon WLAN 7270 v3 at http://fb-7270-01..local
FRITZ!OS: None

Servicename:        WANPPPConnection1
Actionnames:
                    GetInfo
                    GetConnectionTypeInfo
                    SetConnectionType
                    GetStatusInfo
                    GetUserName
                    SetUserName
                    SetPassword
                    GetNATRSIPStatus
                    SetConnectionTrigger
                    ForceTermination
                    RequestConnection
                    GetGenericPortMappingEntry
                    GetSpecificPortMappingEntry
                    AddPortMapping
                    DeletePortMapping
                    GetExternalIPAddress
                    X_GetDNSServers
                    X_SetDNSServers
                    GetLinkLayerMaxBitRates
                    GetPortMappingNumberOfEntries
                    SetRouteProtocolRx
                    SetIdleDisconnectTime
                    X_AVM-DE_GetAutoDisconnectTimeSpan
                    X_AVM-DE_SetAutoDisconnectTimeSpan

The output of fritzconnection -i fb-7270-01..local -A WANPPPConnection1 GetStatusInfo

fritzconnection v1.12.2
FRITZ!Box Fon WLAN 7270 v3 at http://fb-7270-01..local
FRITZ!OS: None

Service:            WANPPPConnection1
Action:             GetStatusInfo
Parameters:

    Name                                  direction     data type

    NewConnectionStatus                      out ->     string
    NewLastConnectionError                   out ->     string
    NewUptime                                out ->     ui4

Running your helper script:

python3 -m fritz_export_helper fb-7270-01..local user password WANPPPConnection1 GetInfo   

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/volza/Projects/fritz_exporter/fritz_export_helper.py", line 26, in <module>
    result = fc.call_action(args.service, args.action)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/fritzconnection.py", line 441, in call_action
    return self.soaper.execute(service, action_name, arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 286, in execute
    return handle_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 268, in handle_response
    raise_fritzconnection_error(response)
  File "/home/volza/Projects/fritz_exporter/.venv/lib/python3.11/site-packages/fritzconnection/core/soaper.py", line 191, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzArgumentError: UPnPError: 
errorCode: 402
errorDescription: Invalid Args

Sadly i did not really understand how to test further from here to maybe help including support for the broken WanPPPConnectionStatus or add X_VoIP1 for example.

Maybe you can use this info to build in some adjustments :) Let me know if i can provide you somehow with additional Information.

pdreker commented 11 months ago

Seems like fritzconnection can also return InvalidArgumentError when calling a function, which has no arguments. While this maybe unexpected I havechecked the code of fritzcopnnection and this may have been updated/introduced some time last year and I have updated the version of fritzconnection used in the code several times.

I have now aded the FritzArgumentError to the list of exceptions, which disables a command for a device, which in turn should make the exporter work for your setup.

I'll release an update shortly.

pdreker commented 11 months ago

NB: I had a look at the X_VoIP1 TR-064 service on my box and this does not return any metrics which would be useful in a prometheus context. The command under that service only return static configuration information (like configured numbers, configured clients, area codes etc.) but no metrics like e.g. "number of calls" etc.

As such I am not going to put any of these into the prometheus metrics. The best I could see is "X_VoIP1 X_AVM-DE_GetVoIPStatus" but as I do not have VoIP accounts on my box this is difficult to say. At best this should deliver "true/false" information on the online status.

If you think this may be worthwhile, could you please open another issue, and provide some example output using the export_helper tool for the metrics you would like to see.

kind regards, Patrick