Improved Netwatch: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
m (Reverted edits by ZovIbo (Talk); changed back to last version by Eugene)
 
No edit summary
Line 13: Line 13:
   
   


This works very well for me. I would welcome any improvements and comments.
[[Category:Scripting]]
 
savagedavid

Revision as of 10:49, 29 October 2007

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}