Community discussions

 
wildbill442
Forum Guru
Forum Guru
Topic Author
Posts: 1050
Joined: Wed Dec 08, 2004 7:29 am
Location: Sacramento, CA

E-mail and scripting quesiton..

Thu May 18, 2006 6:46 pm

I've created a simple script in the /ip dhcp-server alerts submenu to notify me when it detects rogue DHCP servers. Is there anyway to have that same script include the MAC-Addresses and networks in the email?

Here's the current script:
/tool e-mail send to="bill@domain.com" subject=([/system identity get name] . " found rouge DHCP server")
What I'm uncertain on is how do I pull that information from the router? The DHCP Alert automatically creates an entry in the log, if I could just pull that out from the log and send it in the body of the email that would be great.

As always any and all help is appreciated,

Bill
 
eflanery
Member
Member
Posts: 382
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Sun May 21, 2006 6:51 pm

Unfortunately, MT seems to be missing the '/ip dhcp-server alert get' command, which would be needed to do it exactly as you describe, but...

You can do something very similar using the logger directly, no script needed:
/ system logging action add name="DhcpAlert" target=email email-to="foo@bar.com"
/ system logging add topics=dhcp,critical,error action=DhcpAlert disabled=no
With extra effort, a more advanced setup could be constructed using remote scripting (expect, or similar, triggered by a syslog event), but I don't think it would really be worth it.

--Eric
 
tully
MikroTik Support
MikroTik Support
Posts: 505
Joined: Fri May 28, 2004 11:07 am

Wed May 24, 2006 11:57 am

There are multiple ways how you can
get it without using 'get':
1) using '/system logging action add target=email';
2) using $interface, $mac-address and $address variables in dhcp-alert

We will add this in the list of things to do.

John
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 111
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re:

Thu Oct 25, 2012 1:54 am

There are multiple ways how you can
2) using $interface, $mac-address and $address variables in dhcp-alert
Is it correct? :

/tool e-mail send from=test@gmail.com to=test@gmail.com tls=yes subject=DHCP-alert body=" $address $interface $mac-address "

It isn't work :(

[greek@12345Router] > /tool e-mail send from=test@gmail.com to=test@gmail.com
tls=yes subject=DHCP-alert body=" $address $interface $mac-address "
expected end of command (line 1 column 97)

And from "On Alert:" it is not workin too :(
 
a1abhishek
just joined
Posts: 1
Joined: Fri Oct 26, 2012 4:20 pm
Contact:

Re:

Fri Oct 26, 2012 4:22 pm

There are multiple ways how you can
get it without using 'get':
1) using '/system logging action add target=email';
2) using $interface, $mac-address and $address variables in dhcp-alert

We will add this in the list of things to do.

John
yes correct. i think we can follow it.
bde at packersm
 
snowkiterdude
just joined
Posts: 4
Joined: Fri Jun 01, 2012 12:59 am

Re: E-mail and scripting quesiton..

Thu Jan 24, 2013 11:35 pm

by tully
There are multiple ways how you can
get it without using 'get':
1) using '/system logging action add target=email';
2) using $interface, $mac-address and $address variables in dhcp-alert

We will add this in the list of things to do.
Can you please elaborate for all of us that are not as familiar with Mikrotik scripting syntax. I know their are others that are having this same issue. I can't find any scripts that show this working.
http://forum.mikrotik.com/viewtopic.php?f=7&t=40658
 
Limer
just joined
Posts: 16
Joined: Tue Dec 06, 2011 1:41 pm

Re:

Mon Sep 16, 2013 7:46 pm

There are multiple ways how you can
get it without using 'get':
1) using '/system logging action add target=email';
2) using $interface, $mac-address and $address variables in dhcp-alert

We will add this in the list of things to do.

John
Everything works in ROS 6.4 but variable $mac-address is invalid - In e-mail I had blank value.
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 111
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: E-mail and scripting quesiton..

Tue Feb 04, 2014 4:07 pm

Anybody know how to insert $mac-address in email body?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: E-mail and scripting quesiton..

Tue Feb 04, 2014 4:27 pm

If the variable is at all defined,
$"mac-address"
is the way to access it.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
Limer
just joined
Posts: 16
Joined: Tue Dec 06, 2011 1:41 pm

Re: E-mail and scripting quesiton..

Tue Feb 04, 2014 9:10 pm

That's work. Thanks.
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 111
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: E-mail and scripting quesiton..

Wed Feb 05, 2014 11:14 am

Thanks a lot! It's works!
 
User avatar
aacable
Member
Member
Posts: 423
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: E-mail and scripting quesiton..

Thu Feb 06, 2014 11:08 am

Just to add a little contribution. I tried following, and it worked too ...
Sends Email Alert of ROGUE DHCP using GMAIL ID
:local CurrentTime [/system clock get time];
:local hostname [/system identity get name]
:global date [/system clock get date]
:local int "$interface"
:local addr "$address"
:local mac $"mac-address"
 
/tool e-mail send server=173.194.69.109 port=587 start-tls=yes YOUR_GMAIL_ID@gmail.com password=YOURPASSWORD to=aacable@hotmail.com subject=DHCP-Detected body=("ROGUE DHCP Server have been detected on $hostname at $date  - time $CurrentTime  - Interface= $int  - IP Address=$addr - MAC-Address= $mac  !! GO HUNT & KILL :D")
To set GMAIL account
/tool e-mail set address=74.125.45.109 from=gmailid@gmail.com password=mypassword port=587 starttls=no user=gmailid

To view Email activity in LOG for troubleshooting purposes ... enable email logs
/system logging add topics=e-mail action=memory

http://aacable.wordpress.com/2014/02/06 ... via-email/
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
plisken
Forum Guru
Forum Guru
Posts: 2425
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: E-mail and scripting quesiton..

Sun Apr 13, 2014 2:18 pm

Hello Limer write down your full working script please.
Thanks in advance

That's work. Thanks.
 
Limer
just joined
Posts: 16
Joined: Tue Dec 06, 2011 1:41 pm

Re: E-mail and scripting quesiton..

Mon Apr 14, 2014 12:24 pm

No problem.

'on alert' section:
/tool e-mail send to="admin@example.com" subject=("DHCP Alert on ".[/system identity get name]) body=" $address $interface $server $"mac-address"";
 
plisken
Forum Guru
Forum Guru
Posts: 2425
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: E-mail and scripting quesiton..

Mon Apr 14, 2014 3:16 pm

It's works verry good.
Thanks Limer

Who is online

Users browsing this forum: No registered users and 15 guests