hi,
I use a script for when my main WAN fails, it switch over to my backup WAN. This is working fine but I need the script to send an email when it does.
The one I adapted send me an email every time the script runs and not only when the link fails.
Where am I wrong?
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 8.8.8.8 interface=ether5 interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find comment=“Default Route”] distance]=1) do={:log info “Main Gateway down”;
/ip route set [find comment=“Default Route”] distance=3}
/tool e-mail send to=“email@mydomain.co.za” subject=“Main link down”
:log info “Down”
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping x.x.x.x interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find comment=“Default Route”] distance]=1) do={:log info “Main Gateway down”;
/ip route set [find comment=“Default Route”] distance=3}
And I’m wondering if someone can help me to understand is interval between these 5 pings ? I had a situation today when WAN was probably wrongly recognized as “down” and flapped twice and I’m wondering if it couldn’t be caused by the fact that there is too small interval between pings. Can also someone confirm that “interval=3” in script above means that there is 3s of timeout for each ping ?
What will happen if the Ping to that specific host fails due to ISP blockage, or for any reason , the host is down , the script will give FALSE results.
add at least (minimum) two hosts for monitoring.
Example.
Make a Scheduled script that checks for multiple hosts and act accordingly.Ping host1 / host2 & update there up/down status in value, then run IF statement which matches both variable values & IF found DOWN both hosts, then take action accordingly.