Email Script When Interface Status Change (Running or Not Running)

Hello,

We are trying to code a script which will check/monitor the Interface Running status and when ever the interface status is change from Running–>not running or vice versa then it will send an Email Alert to Admin.

Can anyone Help us???

:global currentIP;
:local newIP [/ip address get [find interface="ethert1"] address];
:if ($newIP != $currentIP) do={
    :local newIP [/ip address get [find interface="ethert1"] address];
/tool e-mail send to="xxxxx@hotmail.com" subject=([/system identity 
get name]) body=" This is your new IP:  $newIP" start-tls=yes;
    :set currentIP $newIP;
}

Can we assume that the script can be applied to any interface on the router (aka its not specifically designed of the WAN interface)?
How is the script scheduled then??

This script tests the for change of IP, not if interface is running or not that Op requested.


This will test status of interface ether1. If status changes, it will run the line :put “change to xxxx”, that can be change to email a message.

:global ifstatus
:if ([/interface ethernet get ether1 running]=true) do={
	:put "running"
	:if ($ifstatus="down") do={
		:put "changed to up"
	}
	:set $ifstatus "up"
} else={
	:put "not running"
	:if ($ifstatus="up") do={
		:put "changed to down"
	}
	:set $ifstatus "down"
}

Nice!
(PS sent you an email)

Where did you put the email, to send it to me it doesn’t work for me, put your script please.

You can send email directly to user when they have added email to their profile.

I do not understand anything friend Jotne

Anav did send me a private email to my email asking for something.
It has nothing to do with this post :slight_smile:

geez now everyone will think we are lovers LOL.

Jotne, in which part of the script should I put my email so that when the interface changes, please let me know.

Its written in the post.

it will run the line :put “change to xxxx”, that can be change to email a message.

Replace with some like these two lines

/tool e-mail send to=youremail@gmail.com subject="Host is D own" from=youremail@gmail.com port=587 start-tls=yes user=youremail@gmail.com password=123456 body="IF Down"



/tool e-mail send to=youremail@gmail.com subject="Host is D own" from=youremail@gmail.com port=587 start-tls=yes user=youremail@gmail.com password=123456 body="IF UP"

Hi Jotne,

Thank You so much for your Help!!!

Script Worked for me…

Greetings, friend could you share your script, since it does not work for me. Thanks.

No need to quote the quoted the quoted post :slight_smile:

Just use the Post Reply button under the post.

The email part of the script worded for me once i removed the - start tls - portion. Since tls is already set on my tools - emails settings!!

But the emails are exchanging bodily bits since then…

Publish your script please, since it doesn’t work for me. Thanks.

Sure but my script has a different purpose.
I use recursive routing and whenever the gateway changes on my ISP, the gatewayIPs, in my IP routes do not get updated.
This script addresses that.

:if ($bound=1) do={
:local iface $interface
:local gw [ /ip dhcp-client get [ find interface=$“iface” ] gateway ]
/ip route set [ find comment=“PrimaryRecursive” gateway!=$gw ] gateway=$gw
/ip route set [ find comment=“SecondaryRecursive” gateway!=$gw ] gateway=$gw
/tool e-mail send to=“myaddress@email.com” subject=([/system identity
get name]) body=" This is your new gateway IP: $newIgw";
}

My TOOLS EMAIL Setting.
/tool e-mail
set address=ISP_email_server_IP from=myaddress@email.com port=465 start-tls=
tls-only user=myaddress@email.com

Share your script please.