Community discussions

MikroTik App
 
User avatar
inteq
Member
Member
Topic Author
Posts: 429
Joined: Wed Feb 25, 2015 8:15 pm
Location: Romania

RoS 7.15 broke a DHCP script

Sat Jun 01, 2024 11:03 pm

Hello,

I am using a script that is run on each lease change and it worked quite well up until 7.15. It tries to get the MAC vendor from the lease MAC and set it as a comment.
I am unable to find anything in the changelog pertaining to this issue.
The only thing I can see is
fetch - changed topic "info" to "error" for permission denied logs;
, but I cannot set any permission for the script on DHCP server.

The script:
:log info ( . "Hostname: " . ([/ip dhcp-server lease get [find active-address=$leaseActIP] host-name]))
if ($leaseBound =1) do={
  local result ([/tool fetch url=("https://api.macvendors.com/".$leaseActMAC) output=user as-value ])
  if ($result->"status" = "finished") do={
    local comment0 ("MAC Vendor: ".$result->"data")
    ip dhcp-server lease set [find mac-address=$leaseActMAC dynamic=yes] comment=$comment0
    }
}
The error:
executing script from dhcp failed, please check it manually
Anyone knows about a 7.15 change that might stop this script from running properly? As in why the error, as the MAC is obtained and inserted in the comment.

later edit: it seems creating a separate script and calling the script from the DHCP server instead of running the whole script there got rid of the error.

Thank you
 
User avatar
chechito
Forum Guru
Forum Guru
Posts: 3170
Joined: Sun Aug 24, 2014 3:14 am
Location: Bogota Colombia
Contact:

Re: RoS 7.15 broke a DHCP script

Sun Jun 02, 2024 12:00 am

please use the official topic about 7.15

viewtopic.php?t=208039
 
makrob
just joined
Posts: 4
Joined: Sun Dec 10, 2023 12:44 pm

Re: RoS 7.15 broke a DHCP script

Mon Jun 03, 2024 11:16 pm

Try to use this:
#-----------------works----------------
:if ($leaseBound =1) do={
  local result ([/tool fetch url=("https://api.macvendors.com/".$leaseActMAC) output=user as-value ])
  if ($result->"status" = "finished") do={
    local comment0 ([/system clock get date]." | ".[/system clock get time]." | "."MAC Vendor: ".$result->"data")
    ip dhcp-server lease set [find mac-address=$leaseActMAC dynamic=yes] comment=$comment0
 /tool e-mail send to=your@mail.com  subject="DHCP-List-LAN" body="$leaseActIP - $"lease-hostname" - $leaseActMAC - $comment0"
    }
}
if you don't need send it to email, remove the whole line 7.

ideal save it as script, like dhcp-lan-lease-script and put it in
ip/dhcp-server/add lease-script=dhcp-lan-lease-script
permissions for the script must be ftp,reboot,read,write,policy,test,password,sniff,sensitive