:len returns 1 when counting target-address from queue

Hi guys

I’ve been battling with this for the past couple of hours, couldn’t find any solution on the forum or wiki. When I do the following (lets assume queue1 exist and the target-address is 192.168.1.1/24) :

 :put [:len [/queue simple get queue1 target-addresses ]]
1

It seems that whenever you use the len function to count the length of the target-address from a queue, it counts it as 1.

I’m trying to write a script that will assign a queue for each IP lease, but I need to check if a queue already exist for the IP. And I need to do this check by comparing the IP’s (I use the comment for something else). I’m trying to strip the subnet (ie, the /24 at the end of 192.168.1.1/24) so I’m left with only the IP address.

Any help would be greatly appreciated!

http://forum.mikrotik.com/t/need-help-with-script-to-make-simple-queue-for-dhcp-entries/53490/1


Send from my mobile phone using Tapatalk.

Since the queue allows you to set multiple target addresses, they are stored in an array even if there is only one. So, when you check the length, it’s just checking how many items are in the array.

In v6, you can get the length by selecting the first array item (position 0) with [:pick], something like this:

:put [:len [:pick [/queue simple get queue1 target] 0]]

But since you’re using “target-addresses”, I’m assuming you’re using v5? They are still stored in an array, but I couldn’t get the code above to work… So, a workaround is simply to convert it to a string:

:put [:len [:tostr [/queue simple get queue1 target-addresses]]]

HTH