Community discussions

 
abuumarselo
newbie
Topic Author
Posts: 26
Joined: Wed Aug 21, 2019 3:11 pm

get Alert by email on new Device

Tue Nov 05, 2019 10:20 am

Hi

I need a script that send me an email whenever a new device is connected to my network ( Got a dynamic IP in dhcp leases ) ( LAN or WiFi)
note that all known devices has static IP given
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 926
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: get Alert by email on new Device

Tue Nov 05, 2019 10:29 am

You could trigger /tool e-mail from your dhcp server's lease-script
-Chris
Christopher Diedrich
MTCNA, MTCUME, MTCWE
Basel, Switzerland
Bremen, Germany

There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data
 
abuumarselo
newbie
Topic Author
Posts: 26
Joined: Wed Aug 21, 2019 3:11 pm

Re: get Alert by email on new Device

Tue Nov 05, 2019 10:33 am

I've added the flowing script in dhcp server alerts but not working
:tool e-mail send to=email@example.com subject="Violation alert!!! New DHCP client in the network" body="MAC: $leaseActMAC,
please guide me
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 926
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: get Alert by email on new Device

Tue Nov 05, 2019 1:41 pm

Did you configure /tool e-mail before?

Like:
/tool e-mail
set address=mail.provider.com from=dhcpalerts@provider.com password=youremailpassword port=465 start-tls=tls-only user=dhcpalerts@provider.com
-Chris
Christopher Diedrich
MTCNA, MTCUME, MTCWE
Basel, Switzerland
Bremen, Germany

There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data
 
abuumarselo
newbie
Topic Author
Posts: 26
Joined: Wed Aug 21, 2019 3:11 pm

Re: get Alert by email on new Device

Tue Nov 05, 2019 2:17 pm

yes
and I already have a scheduled script that emails me configuration backup every certain period of time
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 926
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: get Alert by email on new Device

Tue Nov 05, 2019 2:31 pm

Hmmm...
Turn on logging for topics e-mail,debug and trigger that command manually. Then you can see the whole smtp session in your log.
Maybe you find a hint on what's wrong there.
-Chris
Christopher Diedrich
MTCNA, MTCUME, MTCWE
Basel, Switzerland
Bremen, Germany

There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data
 
pe1chl
Forum Guru
Forum Guru
Posts: 5913
Joined: Mon Jun 08, 2015 12:09 pm

Re: get Alert by email on new Device

Tue Nov 05, 2019 2:32 pm

Your script has a syntax error, missing closing quote.
Test your script commands e.g. in a CLI window to see if they work.
 
abuumarselo
newbie
Topic Author
Posts: 26
Joined: Wed Aug 21, 2019 3:11 pm

Re: get Alert by email on new Device

Tue Nov 05, 2019 2:54 pm

I've got this script from a search but also no email sent when a new device connected to network

I put it in dhcp server alert with default settings of new alert
:local recipient "someemail@soemserver.com"
/ip dhcp-server lease
:if ($leaseBound = 1) do={
	:do {
		:tool e-mail send to=$recipient subject="DHCP Address Alert [MAC: $leaseActMAC]" body="The following MAC address [$leaseActMAC] received an IP address [$leaseActIP] from the DHCP Server [$leaseServerName]"
		:log info "Sent DHCP alert for MAC $leaseActMAC"
	} on-error={:log error "Failed to send alert email to $recipient"}}
there is no log entry

I think the event didn't fire and the code never executed
 
pe1chl
Forum Guru
Forum Guru
Posts: 5913
Joined: Mon Jun 08, 2015 12:09 pm

Re: get Alert by email on new Device

Tue Nov 05, 2019 7:00 pm

Debugging MikroTik scripting (especially scripts executed on event) is very frustrating!
When there is the slightest syntax error in your script it will just do nothing and no error is logged.
Also, some syntax that you would think is valid in reality is not, e.g. for some complicated expressions.
That is why I recommend testing the script from CLI first.
Also be sure you fully understand the script permissions thing.
 
WeWiNet
Member Candidate
Member Candidate
Posts: 168
Joined: Thu Sep 27, 2018 4:11 pm

Re: get Alert by email on new Device

Thu Nov 07, 2019 1:25 am

Would be interested in such a script as well! For me just logging with a custom text would be enough...

Keep us updated when you find the solution...
WeWiNet

**
MTCNA
hapac2, map, hap-lite, ltap-mini, RB4011 :-) !!!

Who is online

Users browsing this forum: No registered users and 41 guests