Community discussions

MikroTik App
 
EarthStation
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Mon May 24, 2010 4:06 pm

Need help with script to make simple queue for dhcp entries

Thu Jan 19, 2012 12:28 pm

Hi,

I am trying to write a script that will look at the DHCP leases, and compare the (IP) address entry to the Name list in the simple queues, and if it doesn't exist, create a simple queue.

I am trying (and failing!) with:
{:foreach d in=[/ip dhcp-server lease find address] 
 do={:if ([/queue simple find name]!="$d") do={/queue simple add burst-limit=192k/512k burst-threshold=100k/220k burst-time=5s/5s direction=both disabled=no interface=all limit-at=128k/256k max-limit=128k/256k name=$d parent=none priority=8 queue=wireless-default/wireless-default target-addresses=$d/32 total-queue=wireless-default;  :log info ("New Queue Created: " . [/ip dhcp-server lease get $d address]);
}
   }
       }
Please help me correct the errors. I think the target address ($d/32) is amongst the errors.

Thanks
Brian
Zimbabwe
 
User avatar
huigezi
newbie
Posts: 43
Joined: Sat Dec 24, 2011 4:39 am
Location: apple

Re: Need help with script to make simple queue for dhcp entr

Thu Jan 19, 2012 4:12 pm

/queue simple
:foreach a in=[find] do={
:local tmpip [get $a target-addresses]
/ip dhcp-server lease
:foreach i in=[find] do={
:local oldip ([get $i address]."/32")
:if ($oldip!=$tmpip && [:typeof $tmpip]!="nil") do={
/queue simple
add name=[:pick $oldip 0 [:find $oldip "/"]] target-address=\
$oldip max-limit=1000000/2000000 interface=all disabled=no
}}}
/queue simple
First there was a address rules
 
EarthStation
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Mon May 24, 2010 4:06 pm

Re: Need help with script to make simple queue for dhcp entr

Thu Jan 19, 2012 4:52 pm

/queue simple
:foreach a in=[find] do={
:local tmpip [get $a target-addresses]
/ip dhcp-server lease
:foreach i in=[find] do={
:local oldip ([get $i address]."/32")
:if ($oldip!=$tmpip && [:typeof $tmpip]!="nil") do={
/queue simple
add name=[:pick $oldip 0 [:find $oldip "/"]] target-address=\
$oldip max-limit=1000000/2000000 interface=all disabled=no
}}}
/queue simple
First there was a address rules
Not working, maybe because no simple rules to populate $a? No error message. Running ROS V5.11 latest firmware.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Need help with script to make simple queue for dhcp entr

Fri Jan 20, 2012 2:34 am

I test and work fine
 
EarthStation
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Mon May 24, 2010 4:06 pm

Re: Need help with script to make simple queue for dhcp entr

Fri Jan 20, 2012 12:48 pm

Ok, problem sorted. Need to create a simple queue entry first. Would not populate until this was done. So added a Master Queue in the script that I used to create the dhcp to queue script. No runs on a scheduler every 15 minutes as well. So had to adjust to look for existing queues, and we now have:

/queue simple
:foreach a in=[find] do={
:local tmpip [get $a target-addresses]
/ip dhcp-server lease
:foreach i in=[find] do={
:local oldip ([get $i address]."/32")
:if ($oldip!=$tmpip && [:typeof $tmpip]!="nil") do={
/queue simple
:if ([find name=[:pick $oldip 0 [:find $oldip "/"]]]="") do={
add name=[:pick $oldip 0 [:find $oldip "/"]] target-address=\
$oldip max-limit=100M/100M parent="Master Queue" interface=all disabled=no}
}}}

Added the red colored code to prevent errors on second run.

Many thanks for all the help. Karma's adjusted accordingly :D

Brian
Zimbabwe
 
User avatar
jwcn
Forum Guru
Forum Guru
Posts: 1495
Joined: Sun Aug 27, 2006 6:49 am
Location: Maryland, USA
Contact:

Re: Need help with script to make simple queue for dhcp entr

Fri Sep 21, 2012 5:14 am

Tried this with no success. I have a few DHCP leases, no queues. Ran this and still no queues.

Thoughts?
 
Zapnologica
Long time Member
Long time Member
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Need help with script to make simple queue for dhcp entr

Sat Jun 22, 2013 7:44 pm

Need to add a simple queue called "Master Queue"
run the script and it will then work.

:)
 
Zapnologica
Long time Member
Long time Member
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Need help with script to make simple queue for dhcp entr

Sat Jun 22, 2013 7:51 pm

I got it to work with including the Host Name from the DHCP in the name of the simple queue.

Only problem i am having now is that it doesn't delete queues if the dhcp address is removed, ?
 
Zapnologica
Long time Member
Long time Member
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Need help with script to make simple queue for dhcp entr

Wed Sep 10, 2014 8:18 pm

Does this script still work with V6.19 ?

I am trying to implement this script again and I cant seem to get it to work.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Need help with script to make simple queue for dhcp entr

Sun Sep 14, 2014 7:17 am

Does this script still work with V6.19 ?

I am trying to implement this script again and I cant seem to get it to work.
the original scritp is for 5.x, I remove the wrong code
tested in 6.19:

ros code

:foreach a in=[/queue simple find] do={
:local tmpip [/queue simple get $a target]
/ip dhcp-server lease
:foreach i in=[find] do={
:local oldip ([get $i address]."/32")
:if ($oldip!=$tmpip && [:typeof $tmpip]!="nil") do={
/queue simple add name=[:pick $oldip 0 [:find $oldip "/"]] target=\
$oldip max-limit=1000000/2000000  disabled=no
}}}
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Need help with script to make simple queue for dhcp entr

Sun Sep 14, 2014 2:28 pm

A slightly more efficient version:
/ip dhcp-server lease {
    :foreach i in=[find] do={
        :local leasedIp [get $i address]
        /queue simple {
            :if ([:len [find target=("$leasedIp/32")]] = 0) do={
                add name=$leasedIp target=$leasedIp max-limit=1000000/2000000
            }
        }
    }
}
Since you are at 6.x, there is a new option top add a script to the DHCP-server.
Here is what would be needed for at an automatic creation and deletion (if needed):
/queue simple {
    :if ($leaseBound = "1") do={
	    add name=$leaseActIP target=$leaseActIP max-limit=1000000/2000000
    } else={
        remove [find name=$leaseActIP]
    }
}

Who is online

Users browsing this forum: No registered users and 11 guests