DHCP email alert to ignore specific hostname

Hi guys,

I have a script in place which sends out email notification when a new client joins the network.
The script looks for non-static addresses.
I want to exclude a hostname from this notification, but cannot figure this out from the script.

Update: solution is here:

https://forum.mikrotik.com/viewtopic.php?f=9&t=177581#p872770

You mean exclude hostname that have specific name like “android-7b87234bc987” or “iPhoneNormis” :stuck_out_tongue:

Or you do not want receive the mail if the iPhone change again the MAC address?

To be more precise, I run Docker on a raspberry PI and it has a bug when restarting containers, as these request IP addresses from DHCP server with a random MAC address, but with static hostname.
The containers have their own static IP addresses already set, so the allocated IP addresses won't ever be used (I scheduled a task to clear this up on a regular basis)
So in short I want to exclude these leases from the email alerts by filtering them out based on hostname.

Now you can do that with my script

Use this as model:

# start and stop the list with ; separate each element with ; no space
:local HostnamesToSkipNotification ";pihole1;pihole2;pihole3;"
/ip dhcp-server
:if ($leaseBound = 1) do={
    :local leasehostname $"lease-hostname"
    :if (!($HostnamesToSkipNotification ~ ";$leasehostname;")) do={

# place here what you want run

    }
}

I hate to say this, but it doesn’t work.
For the sake of testing I only added :log info “TEST” as action, to be sure I’m not messing up the script.
Result doesn’t show up in the logs, and no email is sent, when action is /tool e-mail.

Put the modified script on forum

# start and stop the list with ; separate each element with ; no space
:local HostnamesToSkipNotification ";raspberry-pi;"
/ip dhcp-server
:if ($leaseBound = 1) do={
    :if ($HostnamesToSkipNotification ~ ("[^(;".$"lease-hostname".";)") ) do={

:log info "test"

    } 
}

fixed, please modify your old post and remove the wrong script

# start and stop the list with ; separate each element with ; no space
:local HostnamesToSkipNotification ";raspberry-pi;"
/ip dhcp-server
:if ($leaseBound = 1) do={
    :local leasehostname $"lease-hostname"
    :if (!($HostnamesToSkipNotification ~ ";$leasehostname;")) do={

:log info "not raspberry-pi"

    }
}

Thanks, this works!
You rock!

Very thanks! :slight_smile:
, thanks.

@rextended just a little fine tune request if I may, I am receiving alerts for static DHCP clients as well, I am assuming that the “dynamic” property should be added somewhere, but I am not so good in editing scripts, so maybe you can give a hint where and how should I modify it.
Thanks!

Later edit: nevermind, I think I solved it.