Community discussions

MikroTik App
 
User avatar
Giepie
Member
Member
Topic Author
Posts: 432
Joined: Mon Sep 13, 2004 12:33 pm
Location: Western Cape, South Africa
Contact:

:len returns 1 when counting target-address from queue

Thu Jan 02, 2014 8:34 pm

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!
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: :len returns 1 when counting target-address from queue

Thu Jan 02, 2014 8:40 pm

http://forum.mikrotik.com/viewtopic.php?t=58551


Send from my mobile phone using Tapatalk.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: :len returns 1 when counting target-address from queue

Thu Jan 02, 2014 10:27 pm

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

Who is online

Users browsing this forum: abbio90, alixviral and 51 guests