Setting DHCP-Server static leases active-server as server

Hi everybody!

In DHCP-Server Lease we need to set the current “active-server” as “server” in each leased address.
After a backup restore, we have all the static leases with “server=all”, and we have a lot of DHCP-Servers configured in different vlans.

We test something like that script in a lot of combinations, but is not working…

:local servers [/ip dhcp-server find]
:put "Servidores encontrados:"
:put $servers
:foreach server in=$servers do={
    :local active [/ip dhcp-server lease get $server active-server]
    :local leases [/ip dhcp-server lease find dynamic=no server=all]
    :foreach lease in=$leases do={
        /ip dhcp-server lease set $lease server=$active
    }
}

The most rare is when i check the variable “leases” with the command :put $leases, and the result is empty, can be a bug of v7.8?

Thanks in advanced and regards!

Is not clear…

active-server is readonly, and has a value only when a device is actively taken one IP, till the lease expire.
if valorized again when device take again the IP.

Your script is a mess, for example:

:foreach server in=$servers do={
    :local active [/ip dhcp-server lease get $server active-server]

For each dhcp-server go on leases and get active-server… of server…
On the leases are present leases, not servers…

etc.


Use this:

/ip dhcp-server lease
    :foreach item in=[find where ((server="all") and ([:typeof $"active-server"]="str"))] do={
        set $item server=[get $item active-server]
    }

Hi bro, thanks for you reply and suggestion, how you see, we are don´t good in scripting :smiley: because this we need help…
We tested your suggested code and others variants without success…

Something like that:

:foreach i in=[/ip/dhcp-server/lease find where ((server="all") and (dynamic=no) and (status=bound))] do={
/ip/dhcp-server/lease set $i server=(get $i active-server)
}

Thanks in advanced and hope you can try and send a fix,
Regards!