Code: Select all
:put $idList->ether1
So far my experimentation has lead me down 2 different paths so I'll document both of those.
Adding referenced array values to the array
Ideally this would work similar to a python dictionary object where I could just append a new key:value pair to the end of the array dynamically and have it work just like a statically defined one, however I've not found a way to get this to work.
Code: Select all
:local neighborList [/ip neighbor print as-value]; #Unformatted input
:local idList [{}]
:foreach neighbor in=$neighborList do={
#Append the interface hostname pair to the end of the list
:set idList ($idList,{[:tostr ($neighbor->"interface")]=[:tostr ($neighbor->"identity")]})#Problem here
}
:local ifName ether4; #Interface to find
:put $idList; #Debugging; Remove
:put ($idList->$ifName); #Print the desired interface
I know that the rest of my code works and that the idea is sound because it works as I would expect if I statically set the key like such:
Code: Select all
:set idList ($idList,{ether4=[:tostr ($neighbor->"identity")]})
String matching
After spending a couple hours messing with the above and reading numerous wiki pages and forum threads I came to the conclusion that the above is either impossible or has no easy solution so I decided to try kludging it by just storing everything as one string and using the ":find" to get the right entry. However my problem is that I can't get ":find" to do anything except exact matching.
Code: Select all
:local neighborList [/ip neighbor print as-value]; #Unformatted input
:local idList [{}]
:foreach neighbor in=$neighborList do={
#Extracts the interface name and hostname and adds them to list
:set idList ($idList , [:tostr ($neighbor->"interface")]. " " .[:tostr ($neighbor->"identity")])
}
:local ifName ether4; #Interface to find
:put $idList; #Debugging; Remove
:put ($idList->[:find $idList ~ ([:tostr $ifName]."*")]); #Wild card match any string with the right interface in front
Conclusiong
Any help with either of the 2 above paths or a 3rd totally separate way to accomplish what I'm looking for would be much appreciated.