Hi guys,
I’m working on a project that requires me to retrieve a bgp-communities value from a RouterOS device and commit it to a text file, however am having a problem with the bgp-communities value.
The problem I’m having appears to be due to the fact that the bgp-communities is output like so
a) one community on a route exported looks like this
add bgp-communities=1234:1234 comment="Test 1"
b) multiple communities on a route exported looks like this
add bgp-communities=1234:1234,2222:2222 comment="Test 2"
My script cycles through the specific routes it wants to grab and uses the following line to commit the bgp-communities value to a variable.
:set bgpcommunities [/ip route get $entry value=bgp-communities]
And then commits it to part of a text file like so
:set entrydata ("This is route number $rnumber with the following BGP communities $bgpcommunities");
-------
If there’s one or no communities on the route.. no problem, it’ll continue on to the next line correctly and I get an output like so.
Routes:
add bgp-communities="" comment "1"
add bgp-communities=1234:1234 comment="2"
Output:
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 1234:1234
------
However if there’s more than one community on a route it bugs out and cycles through the whole list for as many times as there are communities:
Routes:
add bgp-communities="" comment "1"
add bgp-communities=1234:1234,2222:2222 comment="2"
Output:
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 1234:1234
,
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 2222:2222
and for 3
Routes:
add bgp-communities="" comment "1"
add bgp-communities=1234:1234,2222:2222,1111:1111 comment="2"
Output:
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 1234:1234
,
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 2222:2222
,
This is route number 1 with the following BGP communities
This is route number 2 with the following BGP communities 1111:1111
------
Which doesn’t make any sense to me, because the loop is only going by the number of routes there are, not anything else.
:foreach entry in=[/ip route find] do={