API Issue - URL Encoding Issue with Port Graph

Since the 1.54 update of LibreNMS, I am having issues with retrieving device port information through the API, specifically ports which require URL Encoding (i.e Gi1/0/1).

The following json message is returned when I try to retrieve stats from https://[hostname]/api/v0/devices/[devicename]/ports/Gi1%2F0%2F5.
“status”: “error”,
“message”: “This API route doesn’t exist.”

Ports that don’t require URL Encoding are able to be returned (https://[hostname]/api/v0/devices/[devicename]/ports/vl250)

“status”: “ok”,
“port”: {…
“count”: 78

Has something changed in the respect to this? I have looked through the release notes and haven’t necessarily seen anything related to this listed.

I dont know the answer but I found some possible clues.

LibreNMS moved API routing to Laravel 7 days ago, does that tie in with what you see?
If so, could be related to Laravel
e.g #https://github.com/laravel/framework/issues/22125

some web servers and some browsers will treat %2F as equivalent to a real slash

e.g You could try AllowEncodedSlashes NoDecode for example in Apache.

I would say that the Laravel API Routing change would be consistent with what I’m seeing here.

Reading the comments in that Laravel issue, I don’t think there is much I can do except wait to see if the LibreNMS Dev’s remap API calls for port names with forward slashes to something else.

Impacted by this change as well… I guess it’s time to stop auto updates and keep libre on an old internal stable version, then run through tests before upgrading.

Well,hmm https://github.com/laravel/framework/issues/22125

Unfortunately, we cannot fix or work around this. Workaround in that thread won’t work due to a conflict with the graph api url.

I will be adding the ability for those two routes to accept port_id in addition to ifName and I will make a note that ifName will not work if it contains a / in the docs. If anyone can come up with any better idea, I’m all ears.

Best I could come up with:

Guys I need feedback to know if that should be merged or not. Thanks.

Getting port by ID seems to be working well, I had some issues using the ifName?ifName=0/4 process which I hadn’t had time to look at why it wasn’t working correctly.

What was the URL you were using?

@murrant the URL I was using was https://[hostname]/api/v0/devices/[devicename]/ports/ifName/portbits/?ifName=Te1/0/1 which was returning me the following error.

“message”: “require(): Failed opening required ‘/opt/librenms/includes/html/graphs//auth.inc.php’ (include_path=’.:/usr/share/pear:/usr/share/php’)”,
“exception”: “Symfony\Component\Debug\Exception\FatalErrorException”,
“file”: “/opt/librenms/includes/html/graphs/graph.inc.php”,
“line”: 41,
“trace”: []

However, https://[hostname]/api/v0/devices/[devicename]/ports/ifName?ifName=Te1/0/1 returned the correct information.

Using the port id for the API gets also worked (https://[hostname]/api/v0/devices/[devicename]/ports/6622/port_bits and https://[hostname]/api/v0/devices/[devicename]/ports/6622/port_bits)

That’s because portbits isn’t a graph, it is port_bits.

Ahhh sorry, my bad. In that case the work around works perfectly okay then :slight_smile:

Ok, new approach that restores the original way of functioning.