Script for pinging IP in WAN

Hey guys,
I am trying to create a script for NETWATCH. It needs to ping an IP to our provider for troubleshooting loss of connection. I am having problems with finding exactly what I need, and also some language barriers between older firmwares maybe. What we are wanting to see is if our fiber provider up north are having issues with in and out connections. What we would like is to ping there end of link, and when it fails disable and enable the SFP port. I would also like to have email notifications when it comes back up. I have all the email settings set right in email section, but had a hard time adding to script. Heres what I got:

:if ([/ping 88.42.137.34 interval=5 count=30] = 0) do={
:log info “resetting WAN SFP1”
[/interface disable SFP1]
[/interface enable SFP1]
}

you are almost there, Use variables, they have amazing use in the script :slight_smile:
One working example:

:local HOST "8.8.8.8"
:local PINGCOUNT "30"
:local INT "sfp1"
:local DELAY "3s"
:local sub1 ([/system identity get name])
:local sub2 ([/system clock get time])
:local sub3 ([/system clock get date])
:local ADMINMAIL1 "YOUR_EMAIL@hotmail.com"
:if ([/ping $HOST interval=1 count=$PINGCOUNT] = 0) do={
:log error "HOST $HOST is not responding to ping request, reseting $INT interface ..."
/interface disable $INT
:log error "$INT is now disabled, waiting $DELAY ..."
:delay $DELAY
/interface enable $INT
:delay $DELAY
:log error "$INT is now enabled"
:log warning "Sending Email alert to $ADMINMAIL1 for Link reset ..."
/tool e-mail send to=$ADMINMAIL1 subject="$INT got reset @ $sub3 $sub2 $sub1" start-tls=yes
} else {
:log warning "HOST $HOST ping is ok, no need to take any action ...";
}

But there is one big issue with traditional host monitoring with email alert, Every time the script invokes, it will check and sends email to the admin about down time, means if you have configured the script to to run every minute, you will receive 60 emails in an hour :open_mouth:
So you have to add some smart sensing that it should send one email per status changed.
Something like
Script to monitor Device with options email/sms alerts