Community discussions

MikroTik App
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

DHCP email alert to ignore specific hostname

Fri Aug 13, 2021 7:13 pm

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:

viewtopic.php?f=9&t=177581#p872770
Last edited by szaboistvan007 on Sat Aug 14, 2021 1:08 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP email alert to ignore specific hostname

Fri Aug 13, 2021 11:50 pm

You mean exclude hostname that have specific name like "android-7b87234bc987" or "iPhoneNormis" :P

Or you do not want receive the mail if the iPhone change again the MAC address?
Last edited by rextended on Sat Aug 14, 2021 12:17 am, edited 1 time in total.
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 12:14 am

You mean exclude hostname that have specific name like "android-7b87234bc987" or "iPhoneNormis" :P

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 12:17 am

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

    }
}
Last edited by rextended on Sat Aug 14, 2021 12:53 am, edited 3 times in total.
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 12:46 am

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.
Last edited by szaboistvan007 on Sun Aug 15, 2021 9:19 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 12:48 am

Put the modified script on forum
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 12:51 am

# 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"

    } 
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP email alert to ignore specific hostname  [SOLVED]

Sat Aug 14, 2021 12:54 am

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"

    }
}
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 1:06 am

Thanks, this works!
You rock!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DHCP email alert to ignore specific hostname

Sat Aug 14, 2021 1:09 am

Thanks, this works!
You rock!
Very thanks! :)
, thanks.
Last edited by rextended on Mon Aug 16, 2021 1:56 am, edited 1 time in total.
 
szaboistvan007
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2020 9:52 pm

Re: DHCP email alert to ignore specific hostname

Sun Aug 15, 2021 9:22 pm

@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.

Who is online

Users browsing this forum: JDF and 18 guests