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
/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
huigezi:
/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.
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
Brian
Zimbabwe
jwcn
September 21, 2012, 2:14am
6
Tried this with no success. I have a few DHCP leases, no queues. Ran this and still no queues.
Thoughts?
Need to add a simple queue called “Master Queue”
run the script and it will then work.
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, ?
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:
: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
September 14, 2014, 11:28am
11
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]
}
}