Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FREEBOX Plugin unable to parse data #927

Open
3 of 7 tasks
brissou opened this issue Jan 3, 2025 · 7 comments
Open
3 of 7 tasks

FREEBOX Plugin unable to parse data #927

brissou opened this issue Jan 3, 2025 · 7 comments
Labels
bug 🐛 Something isn't working next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed.

Comments

@brissou
Copy link

brissou commented Jan 3, 2025

Is there an existing issue for this?

The issue occurs in the following browsers. Select at least 2.

  • Firefox
  • Chrome
  • Edge
  • Safari (unsupported) - PRs welcome
  • N/A - This is an issue with the backend

Current Behavior

Hy and thank for netalert x ;)

I'm not able to get devices names from freebox

FREEBOX Plugin add is OK
Pairing freebox with netalertX is OK
I tried to set the good version of API wich is 12.2 with my french Freebox Ultra but :

  • only the number 12 appear in the and tell me it come back to v6 default in log
  • I tried with 6,7 11 Version I've always the same problem

The data are well retrieved (you can see data in app/log)
But there is a parsing error
-> KeyError: 'l3connectivities'

Expected Behavior

Retrieve device name from freebox

Steps To Reproduce

No response

app.conf

# FREEBOX
#---------------------------
FREEBOX_RUN='always_after_scan'
FREEBOX_RUN__metadata="{\"function\": \"RUN\", \"events\": [\"run\"], \"type\": {\"dataType\": \"string\", \"elements\": [{\"elementType\": \"select\", \"elementOptions\": [], \"transformers\": []}]}, \"default_value\": \"disabled\", \"options\": [\"disabled\", \"once\", \"schedule\", \"always_after_scan\", \"on_new_device\", \"on_notification\"], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"When to run\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"When the plugin should run.\"}]}"
FREEBOX_RUN_SCHD='*/5 * * * *'
FREEBOX_RUN_SCHD__metadata="{\"function\": \"RUN_SCHD\", \"type\": {\"dataType\": \"string\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [], \"transformers\": []}]}, \"default_value\": \"*/5 * * * *\", \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"Schedule\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Only enabled if you select <code>schedule</code> in the <a href=\\\"#SYNC_RUN\\\"><code>SYNC_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\\\"https://crontab.guru/\\\" target=\\\"_blank\\\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\\\"toggleAllSettings()\\\" href=\\\"#TIMEZONE\\\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes.\"}]}"
FREEBOX_address='192.168.0.254'
FREEBOX_address__metadata="{\"function\": \"address\", \"type\": {\"dataType\": \"string\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [], \"transformers\": []}]}, \"maxLength\": 50, \"default_value\": \"mafreebox.freebox.fr\", \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"Address\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Address of the Freebox router. You will need to pair the device as explained in the docs\"}]}"
FREEBOX_api_version=11
FREEBOX_api_version__metadata="{\"function\": \"api_version\", \"type\": {\"dataType\": \"integer\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [{\"type\": \"number\"}], \"transformers\": []}]}, \"default_value\": 6, \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"API version\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Which version of the API o use\"}]}"
FREEBOX_api_port=80
FREEBOX_api_port__metadata="{\"function\": \"api_port\", \"type\": {\"dataType\": \"integer\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [{\"type\": \"number\"}], \"transformers\": []}]}, \"default_value\": 443, \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"HTTP(S) port\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Port for HTTP(S) access. This might be different for your device, more info in the plugin documentation.\"}]}"
FREEBOX_CMD='python3 /app/front/plugins/freebox/freebox.py'
FREEBOX_CMD__metadata="{\"function\": \"CMD\", \"type\": {\"dataType\": \"string\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [{\"readonly\": \"\"}], \"transformers\": []}]}, \"default_value\": \"python3 /app/front/plugins/freebox/freebox.py\", \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"Command\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Command to run. This can not be changed\"}]}"
FREEBOX_RUN_TIMEOUT=30
FREEBOX_RUN_TIMEOUT__metadata="{\"function\": \"RUN_TIMEOUT\", \"type\": {\"dataType\": \"integer\", \"elements\": [{\"elementType\": \"input\", \"elementOptions\": [{\"type\": \"number\"}], \"transformers\": []}]}, \"default_value\": 30, \"options\": [], \"localized\": [\"name\", \"description\"], \"name\": [{\"language_code\": \"en_us\", \"string\": \"Run timeout\"}], \"description\": [{\"language_code\": \"en_us\", \"string\": \"Maximum time in seconds to wait for the script to finish. If this time is exceeded the script is aborted.\"}]}"

docker-compose.yml

version: "3"
services:
  netalertx:
    container_name: netalertx
    # use the below line if you want to test the latest dev image
    # image: "jokobsk/netalertx-dev:latest" 
    image: "jokobsk/netalertx:latest"      
    network_mode: "host"        
    restart: unless-stopped
    volumes:
      - /volume1/docker/netalertx/config:/app/config
      - /volume1/docker/netalertx/db:/app/db      
      # (optional) useful for debugging if you have issues setting up the container
      -  /volume1/docker/netalertx/log:/app/front/log
    environment:
      - TZ=Europe/Paris      
      - PORT=20211

What branch are you running?

Production

app.log

app (3).log

Debug enabled

  • I have read and followed the steps in the wiki link above and provided the required debug logs and the log section covers the time when the issue occurs.
@brissou brissou added the bug 🐛 Something isn't working label Jan 3, 2025
jokob-sk pushed a commit that referenced this issue Jan 3, 2025
@jokob-sk
Copy link
Owner

jokob-sk commented Jan 3, 2025

Hi @brissou ,

Thanks for the report.

I've tried to implement a fix. It would be great if you could test this. Can you please switch to the netalertx-dev docker image (backup everything at first or, ideally spin up a separate container with a separate db and config), in about 15 minutes (or after the last action finishes) from now?

FYI @KayJay7 @Lucide this was the error.

'reachable': False, 'last_activity': 0, 'primary_name': ''}]
Traceback (most recent call last):
  File "/app/front/plugins/freebox/freebox.py", line 171, in <module>
    main()
  File "/app/front/plugins/freebox/freebox.py", line 151, in main
    for ip in [ip for ip in host["l3connectivities"] if ip["reachable"]]:
                            ~~~~^^^^^^^^^^^^^^^^^^^^
KeyError: 'l3connectivities'

The fix hopefully is:

for host in hosts:
        # Check if 'l3connectivities' exists and is a list
        if "l3connectivities" in host and isinstance(host["l3connectivities"], list):
            for ip in [ip for ip in host["l3connectivities"] if ip.get("reachable")]:
                mac: str = host.get("l2ident", {}).get("id", "(unknown)")
                if mac != '(unknown)':
                    plugin_objects.add_object(
                        primaryId=mac,
                        secondaryId=ip.get("addr", "0.0.0.0"),
                        watched1=host.get("primary_name", "(unknown)"),
                        watched2=host.get("vendor_name", "(unknown)"),
                        watched3=map_device_type(host.get("host_type", "")),
                        watched4=datetime.fromtimestamp(ip.get("last_time_reachable", 0)),
                        extra="",
                        foreignKey=mac,
                    )
        else:
            # Optional: Log or handle hosts without 'l3connectivities'
            mylog("verbose", [f"[{pluginName}] Host missing 'l3connectivities': {host}"])

@jokob-sk jokob-sk added Waiting for reply⏳ Waiting for the original poster to respond, or discussion in progress. next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed. labels Jan 3, 2025
@brissou
Copy link
Author

brissou commented Jan 3, 2025

Hy @jokob-sk it works perfecty now ;)

12:56:59 [FREEBOX] In script
12:56:59 [FREEBOX] Settings: {'api_address': '192.168.0.254', 'api_version': 12, 'api_port': 80}
12:57:00 [Plugins] Processed and deleted file: /app/log/plugins/last_result.FREEBOX.log
12:57:00 [Plugins] SUCCESS, received 51 entries

@jokob-sk
Copy link
Owner

jokob-sk commented Jan 3, 2025

Thanks for testing it! Glad it's working.

@jokob-sk jokob-sk removed the Waiting for reply⏳ Waiting for the original poster to respond, or discussion in progress. label Jan 3, 2025
@Lucide
Copy link
Contributor

Lucide commented Jan 3, 2025

The fix will ignore devices without l3connectivities, right?

If some devices have the field and some do not, I suppose this is an intended behaviour, not just an api version incompatibility.

But I don't get when that would be the case: a device found by the box but without ip (be v4 or v6) connectivity🤔.

@brissou The freebox api wrapper library supports v6 and ignores minor releases. In my case my box reports v11.1, but the version check is broken (it compares lexicographically, so "11"<"6") and v11 causes a false deprecation warn.

For this purpose 6 is still ok.

@jokob-sk
Copy link
Owner

jokob-sk commented Jan 3, 2025

Hi @Lucide,

Thanks for checking! Not sure what you mean by returning an empty array.

Happy for you to submit a PR to improve on it further.

@Lucide
Copy link
Contributor

Lucide commented Jan 3, 2025

Oh! my bad I meant missing field, not empty array. I've edited for clarity.

I was wondering in what situation this would happen (and what it would mean).

Your fix is correct! There's not much to do in this situation 🤷🏻‍♂️

@jokob-sk
Copy link
Owner

jokob-sk commented Jan 3, 2025

Haha, all good - my brain was like "what am I missing here" 🤔😄

As always, thanks for all the help and support @Lucide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed.
Projects
None yet
Development

No branches or pull requests

3 participants