Community discussions

MikroTik App
 
anassar26
just joined
Topic Author
Posts: 20
Joined: Sun Aug 02, 2020 3:20 pm

Script DHCP Lease to Simple Queues don't work since update to 7.13

Sat Jan 06, 2024 12:15 am

Hi,

i have used a DDNS script on mikrotik roouter OS9.6 for years but since the update to 7.13 the script don't work.

I hope someone can point out whats wrong or what changed in 7.13
# DHCP Lease to Simple Queues
# 2014 Lonnie Mendez (lmendez@anvilcom.com)
#
# Mikrotik RouterOS v6.9
 
/ip dhcp-server lease
:foreach x in=[find] do={
 
# grab variables for use below
:local leaseaddr ([get $x address]."/32")
:local leasemacaddr [get $x mac-address]
:local leasehostname [get $x host-name]
:local leasename [get $x comment]
:local queuecomment
 
:local leaseinqueue false
 
/queue simple
:foreach y in=[find] do={
 
#grab variables for use below
:local queuetargetaddr [get $y target]
:set queuecomment [get $y comment]
 
# Isolate information  from the comment field (MAC, Hostname)
:local queuemac [:pick $queuecomment 4 21]
:local queuehostname [:pick $queuecomment 22 [:len $queuecomment]]
 
# If MAC from lease matches the queue MAC then refresh the queue item
:if ($queuemac = $leasemacaddr) do={
# build a comment field
:set queuecomment ("dtq," . $leasemacaddr . "," . $leasehostname)
 
set $y target=$leaseaddr comment=$queuecomment
:if ($leasename != "") do= {
set $y name=($leasename . " (" . $leasemacaddr . ")")
} else= {
:if ($leasehostname != "") do= {
set $y name=($leasehostname . " (" . $leasemacaddr . ")")
} else= {
set $y name=$leasemacaddr
}
}
:set leaseinqueue true
} else= {
# if ip exists for this lease but mac is different then update mac/hostname and reset counter
:if ($queuetargetaddr = $leaseaddr) do={
# build a comment field
:set queuecomment ("dtq," . $leasemacaddr . "," . $leasehostname)
 
set $y comment=$queuecomment
reset-counters $y
:if ($leasename != "") do= {
set $y name=($leasename . " (" . $leasemacaddr . ")")
} else= {
:if ($leasehostname != "") do= {
set $y name=($leasehostname . " (" . $leasemacaddr . ")")
} else= {
set $y name=$leasemacaddr
}
}
:set leaseinqueue true
}
}
}
 
# There was not an existing entry so add one for this lease
:if ($leaseinqueue = false) do={
# build a comment field
:set queuecomment ("dtq," . $leasemacaddr . "," . $leasehostname)
# build command
:local cmd "/queue simple add target=$leaseaddr max-limit=100M/100M comment=$queuecomment"
:if ($leasename != "") do={ 
:set cmd "$cmd name=\"$leasename ($leasemacaddr)\"" 
} else= {
:if ($leasehostname != "") do={
:set cmd "$cmd name=\"$leasehostname ($leasemacaddr)\""
} else= {
:set cmd "$cmd name=\"$leasemacaddr\""
}
}
 
:execute $cmd
}
}
 
# Cleanup Routine - remove dynamic entries that no longer exist in the lease table
/queue simple
:foreach z in=[find] do={
:local queuecomment [get $z comment]
:local queue1stpart [:pick $queuecomment 0 3]
:local queue2ndpart [:pick $queuecomment 4 21]
:if ( $queue1stpart = "dtq") do={
:if ( [/ip dhcp-server lease find mac-address=$queue2ndpart] = "") do={
:log info ("DTQ: Removing stale entry for MAC Address - " . $queue2ndpart)
remove $z
}
}
}
[/quote]
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Sat Jan 06, 2024 1:38 pm

Script do work fine on my 7.6 test router. Simple Queue was added for the new DHCP release, then removed if script was run after DHCP lease was removed. It may have change some thing in later version that do break it. Will do some more testing.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Sat Jan 06, 2024 1:58 pm

Update.

Runs fine on 7.13 as well.
I just wrap the whole script in { } and cut past it to a terminal windows. This way its easy to see if some breaks (red color).

PS this i a plain router installed with just default config. So it may be some thing in your config.
 
dotis
just joined
Posts: 2
Joined: Wed Apr 22, 2015 11:48 am

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Sat Feb 17, 2024 12:32 pm

I have almost the same problem.
I have this script but its not working in V7

/queue simple add max-limit=5M/25M name="Total_Clients" target=10.4.29.0/23

:local child "MacAddr - $leaseActMAC"
:if ($leaseBound = "1") do={
/queue simple add name="MacAddr - $leaseActMAC" target=($leaseActIP."/32") limit-at=2M/25M max-limit=2M/25M burst-limit=2M/25M burst-threshold=2M/25M burst-time=5/5 priority=8/8 parent="Total_Clients" comment=("Computer LAN ".[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name]);
} else={
/queue simple remove $child
}

I ve try the above script but it creates queues for every lease. That what i need is to create queues only for this dhcp-server that the script is triggering.
I believe that is something with variables - not accepting :local in dhcp script, but i am not sure!
 
msaid
just joined
Posts: 3
Joined: Sat Apr 08, 2023 10:14 pm

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Sun Feb 18, 2024 2:39 am

Having the same issue. The following config works in 7.12.2, but doesn't work in 7.13, 7.13.1, 7.13.2, 7.13.3, and 7.13.4.
# 2024-02-18 07:27:12 by RouterOS 7.12.2
# software id = QU8N-B21Q
#
# model = RB750Gr3
# serial number = CC210F11FD6D
/ip dhcp-server
add add-arp=yes address-pool=default-dhcp insert-queue-before=bottom interface=bridge lease-script=":local queueName \"Client - \$leaseActMAC\";\r\
    \n \r\
    \n:if (\$leaseBound = \"1\") do={\r\
    \n   :if ([:len [/queue simple find name=\$queueName]] = 0) do={\r\
    \n      :log warning \"Queue Added for \$leaseActMAC\";\r\
    \n      /queue simple add name=\$queueName  target=(\$leaseActIP.\"/32\") queue=client/client limit-at=128k/128k max-limit=1M/1M burst-limit=4M/4M burst-threshold=2M/2M burst-time=10/10  priority=8/8 parent=\"Gateway\" comment=(\"Client - \".[/ip dhcp-server lease get [find where active-mac-address=\$leaseActMAC && active-address=\$leaseActIP] host-name]);\r\
    \n   } else={\r\
    \n      :local exist [/queue simple get [find name=\$queueName] target];\r\
    \n      \r\
    \n      :if (\$exist = \$leaseActIP) do={\r\
    \n         :log warning \"Queue Enabled - \$exist\";\r\
    \n         /queue simple enable \$queueName;\r\
    \n      } else={\r\
    \n         :log warning \"Queue Updated - \$exist\";\r\
    \n         /queue simple set target=(\$leaseActIP) [find name=\$queueName];\r\
    \n         /queue simple enable \$queueName;\r\
    \n      }\r\
    \n}\r\
    \n} else={\r\
    \n   :log warning \"Queue Disabled for \$leaseActMAC\";\r\
    \n   /queue simple disable \$queueName;\r\
    \n}" lease-time=10m name=default0
/ip dhcp-server network
add address=192.168.88.0/24 dns-server=192.168.88.1 gateway=192.168.88.1
/queue type
add kind=sfq name=client
add cake-ack-filter=filter cake-nat=yes kind=cake name=gwout
/queue simple
add dst=192.168.88.0/24 max-limit=1G/1G name="Local Traffic" target=192.168.88.0/24
add max-limit=20M/20M name=Gateway queue=gwout/gwout target=192.168.88.0/24

Apparently the script is executed up to this line (I can see the log entries):
:log warning "Queue Added for $leaseActMAC";
But no new queue is added upon new client getting its lease bound.
Last edited by msaid on Sun Feb 18, 2024 2:50 am, edited 4 times in total.
 
User avatar
metron6
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Nov 16, 2013 3:41 pm

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Tue Feb 27, 2024 8:08 pm

script is not working on 7.13.5

anyway, is there any such script which works ?
 
robbiereindeer
just joined
Posts: 4
Joined: Tue Feb 20, 2024 10:30 pm

Re: Script DHCP Lease to Simple Queues don't work since update to 7.13

Sat Mar 02, 2024 2:42 pm

This is my first MikroTik router, but after faffing about with the DHCP scripts for a day, here's what I found out:

First off, dhcp scripts *do* run under 7.13 and 7.14 at least, but if there is the tiniest syntax error in your script anywhere, then it will not run - no log messages, no error messages. Nothing. So do test by running them on the console first (you may have to supply fake values for the DHCP variables of course)

Secondly, and this was a big gotcha, the variable names mentioned in the help documentation at https://help.mikrotik.com/docs/display/ ... Properties are wrong, those values are not present when the script is run.

I found that the values mentioned in the 3rd post in this topic DO work: viewtopic.php?t=174626

Here they are:
leaseBound - set to "1" if bound, otherwise set to "0"
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address
lease-hostname - client hostname
lease-options - array of received options
For some reason, these also contain names with a "-" in them, which is a problematic character for variable names in scripts, so you have to use
$"lease-hostname"
to work around that (I just copied their value into a local variable with a normal name, instead of trying to figure out how to use quotes within a quoted string :-(

Anyway, hope this helps someone else and maybe someone can update the documentation?

Who is online

Users browsing this forum: handiansudianto and 5 guests