Improved Netwatch - MikroTik Script RouterOS
This is an improved version of Netwatch that removes false positives. It works by pinging the target IP 5 times. If all 5 time out then the specified action is taken.
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 72.14.207.104 interval=3 count=1]=0))};
:if ($i=5 && [/ip route get [find comment="Default Route"] disabled]=false) do={:log info "Main Gateway down";
/ip route set [find comment="Default Route"] disabled=yes}
In this case it searches for a route labelled "Default Route" and disables it if 5 pings in a row to www.google.com time out. To re-enable on 5 succesfull pings you could have some thing like:
:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 72.14.207.104 interval=3 count=1]=1))};
:if ($i=5 && [/ip route get [find comment="Default Route"] disabled]=true) do={:log info "Main Gateway up";
/ip route set [find comment="Default Route"] disabled=no}
ping return number of recieved packets (at last on latest 3.x and щт 4.x). Next do same
:if ([/ping 72.14.207.104 interval=3 count=5]=5 && [/ip route get [find comment="Default Route"] disabled]=false) do={
:log info "Main Gateway down"; /ip route set [find comment="Default Route"] disabled=yes}