Hello,
If I use the line from the Wiki below in order to retrieve the file via API (and convert it back to the text forma), I get a parsing error - presumably from jq. If I download only the file taking jq out of the equation, it's not a json file, but rather, a HTML file. I assume that's why there's a parsing error when jq reads it. Is the info from the Wiki out of date?
Thanks, Lee K5DAT
curl -s https://user:key@portal.ampr.org/api/v1/encap | jq -r '.[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"'
I ran into the same issue earlier this year and suggested a fix on this and the wiki mailing list (before they were moved, so you may not be able to see it in archives). The change is as you suspect with the parsing argument of jq, see here in diff style format what worked for me:
# download api data with curl into a file json-data.out
-cat json-data.out | jq -r '.[] | "route addprivate
+cat json-data.out | jq -r '.encap[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"' >> encap.txt
-andreas K6OTT
On Thu, Apr 25, 2024 at 3:32 PM Lee D Bengston via 44net < 44net@mailman.ampr.org> wrote:
Hello,
If I use the line from the Wiki below in order to retrieve the file via API (and convert it back to the text forma), I get a parsing error - presumably from jq. If I download only the file taking jq out of the equation, it's not a json file, but rather, a HTML file. I assume that's why there's a parsing error when jq reads it. Is the info from the Wiki out of date?
Thanks, Lee K5DAT
curl -s https://user:key@portal.ampr.org/api/v1/encap | jq -r '.[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"
The URL is wrong and you need a Bearer token not Basic authentication, also you should probably add an Accept: header, so this should work to get the JSON:
curl -s -H "Authorization: Bearer YourApiTokenHere" -H "Accept: application/json" https://portal.ampr.org/api/v1/encap/routes
The Wiki needs updating, so if you want to give it a test then let me know if the jq parsing bit works as well and I will update.
If you’re subscribed to 44Net on groups.io http://groups.io/ I posted a PHP script to download and parse the encap routes a couple of weeks ago: https://ardc.groups.io/g/44net/message/93
When I get a moment I will put that on the Wiki.
Thanks, Chris - G1FEF — ARDC Administrator
Web: https://www.ardc.net
On 25 Apr 2024, at 23:48, Andreas Ott via 44net 44net@mailman.ampr.org wrote:
I ran into the same issue earlier this year and suggested a fix on this and the wiki mailing list (before they were moved, so you may not be able to see it in archives). The change is as you suspect with the parsing argument of jq, see here in diff style format what worked for me:
# download api data with curl into a file json-data.out -cat json-data.out | jq -r '.[] | "route addprivate +cat json-data.out | jq -r '.encap[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"' >> encap.txt
-andreas K6OTT
On Thu, Apr 25, 2024 at 3:32 PM Lee D Bengston via 44net 44net@mailman.ampr.org wrote: Hello,
If I use the line from the Wiki below in order to retrieve the file via API (and convert it back to the text forma), I get a parsing error - presumably from jq. If I download only the file taking jq out of the equation, it's not a json file, but rather, a HTML file. I assume that's why there's a parsing error when jq reads it. Is the info from the Wiki out of date?
Thanks, Lee K5DAT
curl -s https://user:key@portal.ampr.org/api/v1/encap | jq -r '.[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)" _______________________________________________ 44net mailing list -- 44net@mailman.ampr.org To unsubscribe send an email to 44net-leave@mailman.ampr.org
On Fri, Apr 26, 2024, 2:18 AM Chris chris@ardc.net wrote:
The URL is wrong and you need a Bearer token not Basic authentication, also you should probably add an Accept: header, so this should work to get the JSON:
curl -s -H "Authorization: Bearer YourApiTokenHere" -H "Accept: application/json" https://portal.ampr.org/api/v1/encap/routes
Thank-you. That worked to retrieve the JSON file. The jq parsing from the wiki did not work. There was an error message, but I'm not at my desk now and don't recall the details. A simpler jq parse to add line breaks for human readability worked fine.
I wrote a very ugly perl script that runs the simpler jq parse, then reads the resulting file line by line and builds a new file in "JNOS" format. It doesn't truncate the last octet if it's zero, though. For normal operation, that's neither needed nor desired.
I'm just now noticing the message from Andreas, so I probably wrote the bulk of that script for nothing, lol. Oh well, it's done, and it automatically downloads and converts the file.
If you’re subscribed to 44Net on groups.io http://groups.io/ I posted a PHP script to download and parse the encap routes a couple of weeks ago: https://ardc.groups.io/g/44net/message/93
I haven't subscribed yet but will shortly.
When I get a moment I will put that on the Wiki.
Thanks, Lee K5DAT
I would recommend that unless you have an environment that cannot support that, instead of the encap file you use the RIP broadcasts with the program ampr-ripd. It keeps the routing table uptodate without regular file downloads and it can write an encap.txt file when you require that for some purpose (and which you can use as a backup when the RIP broadcasts are down for some reason)
Rob
On 2024-04-26 00:32, Lee D Bengston via 44net wrote:
Hello,
If I use the line from the Wiki below in order to retrieve the file via API (and convert it back to the text forma), I get a parsing error - presumably from jq. If I download only the file taking jq out of the equation, it's not a json file, but rather, a HTML file. I assume that's why there's a parsing error when jq reads it. Is the info from the Wiki out of date?
Thanks, Lee K5DAT
curl -s https://user:key@portal.ampr.org/api/v1/encap https://user:key@portal.ampr.org/api/v1/encap | jq -r '.[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"'
44net mailing list -- 44net@mailman.ampr.org To unsubscribe send an email to 44net-leave@mailman.ampr.org
I would second Rob’s suggestion - by far the best option - you receive the routes the moment anything changes rather than having to download them manually or on a cron script.
Chris - G1FEF — ARDC Administrator
Web: https://www.ardc.net
On 26 Apr 2024, at 08:58, Rob PE1CHL via 44net 44net@mailman.ampr.org wrote:
I would recommend that unless you have an environment that cannot support that, instead of the encap file you use the RIP broadcasts with the program ampr-ripd. It keeps the routing table uptodate without regular file downloads and it can write an encap.txt file when you require that for some purpose (and which you can use as a backup when the RIP broadcasts are down for some reason)
Rob
On 2024-04-26 00:32, Lee D Bengston via 44net wrote:
Hello,
If I use the line from the Wiki below in order to retrieve the file via API (and convert it back to the text forma), I get a parsing error - presumably from jq. If I download only the file taking jq out of the equation, it's not a json file, but rather, a HTML file. I assume that's why there's a parsing error when jq reads it. Is the info from the Wiki out of date?
Thanks, Lee K5DAT
curl -s https://user:key@portal.ampr.org/api/v1/encap https://user:key@portal.ampr.org/api/v1/encap | jq -r '.[] | "route addprivate (.network)/(.maskLength) encap (.gatewayIP)"'
44net mailing list -- 44net@mailman.ampr.org To unsubscribe send an email to 44net-leave@mailman.ampr.org
44net mailing list -- 44net@mailman.ampr.org To unsubscribe send an email to 44net-leave@mailman.ampr.org
My reply to Rob inadvertently didn't copy the list. I included it below.
-------------------------- From: Lee D Bengston Date: Fri, Apr 26, 2024 at 6:44 AM Subject: Re: [44net] Re: Encap file To: Rob PE1CHL 44net@pe1chl.nl
I'm already receiving the RIP broadcasts and using those routes. I like to be able to fall back to the text file in the event that I stop receiving the broadcasts, which has happened in the past.
Also, in this case, the application I'm using has a new version of code that addresses an issue with the routes that skip the last octet if it's zero. I simply want to test the new version of the software with a fresh copy of the text file.
Lee K5DAT
On Fri, Apr 26, 2024 at 11:46 AM Chris via 44net 44net@mailman.ampr.org wrote:
I would second Rob’s suggestion - by far the best option - you receive the routes the moment anything changes rather than having to download them manually or on a cron script.
Chris - G1FEF — ARDC Administrator
Web: https://www.ardc.net
Lee,
Ok in that case you can start ampr-ripd with the parameter: -s It will write your encap file to /var/lib/ampr-ripd/encap.txt whenever it changes (you may need to mkdir /var/lib/ampr-ripd one time) and you can copy it to wherever you want, and also when ampr-ripd starts it automatically reads this file so you do not need to wait 5 minutes to receive the RIP before you have the routes.
It works fine for me. Study the ampr-ripd parameters, it has lots of interesting options.
Rob
On 2024-04-27 15:36, Lee D Bengston via 44net wrote:
My reply to Rob inadvertently didn't copy the list. I included it below.
From: *Lee D Bengston* Date: Fri, Apr 26, 2024 at 6:44 AM Subject: Re: [44net] Re: Encap file To: Rob PE1CHL <44net@pe1chl.nl mailto:44net@pe1chl.nl>
I'm already receiving the RIP broadcasts and using those routes. I like to be able to fall back to the text file in the event that I stop receiving the broadcasts, which has happened in the past.
Also, in this case, the application I'm using has a new version of code that addresses an issue with the routes that skip the last octet if it's zero. I simply want to test the new version of the software with a fresh copy of the text file.
Lee K5DAT
On Fri, Apr 26, 2024 at 11:46 AM Chris via 44net <44net@mailman.ampr.org mailto:44net@mailman.ampr.org> wrote:
I would second Rob’s suggestion - by far the best option - you receive the routes the moment anything changes rather than having to download them manually or on a cron script. Chris - G1FEF — ARDC Administrator Web: https://www.ardc.net <https://www.ardc.net>
44net mailing list -- 44net@mailman.ampr.org To unsubscribe send an email to 44net-leave@mailman.ampr.org
Rob,
I'm not using ampr-ripd. I'm using XRouter, which runs RIP and can also use the encap.txt file. (I believe JNOS has the same capabilities.) You brought up another reason why I like to have the file on hand, though. XRouter also has the routes right away upon restart when the file is present.
Good information, though, as sometime down the road I could possibly switch to a Linux based gateway instead of using an application based gateway.
73, Lee K5DAT
On Sat, Apr 27, 2024 at 12:02 PM Rob PE1CHL via 44net < 44net@mailman.ampr.org> wrote:
Lee,
Ok in that case you can start ampr-ripd with the parameter: -s It will write your encap file to /var/lib/ampr-ripd/encap.txt whenever it changes (you may need to mkdir /var/lib/ampr-ripd one time) and you can copy it to wherever you want, and also when ampr-ripd starts it automatically reads this file so you do not need to wait 5 minutes to receive the RIP before you have the routes.
It works fine for me. Study the ampr-ripd parameters, it has lots of interesting options.