I have been using netwatch with good success, however, some devices simply reboot themselves and then go right back online. I get an email saying device is down, and then seconds later that it is up. I want to eliminate this.
What is the easiest way to have netwatch ping a device more than once to avoid the false alarms?
Script to ping 10 times with an interval of 3 seconds, then execute commands if all pings are unsuccessful.
:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=0))};
:if ($i=10) do={:log info "Warning: 10 unsuccessful pings to IP 192.x.x.x";
/set your command here.}
Set a scheduler to run it every 1 minute if you like.
:local i value=0;
:while (($i < 10) && ([/ping address=192.x.x.x interval=3 count=1]=0)) do={:set i value=($i+1)} ;
:if ($i=10) do={
:log info message=“Warning: 10 unsuccessful pings to IP 192.x.x.x”; #set your command here
};
When it goes up, just write another similar script. Notice the slight difference.
:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=1))};
:if ($i=10) do={:log info "Warning: 10 successful pings to IP 192.x.x.x";
/set your command here.}
:local i value=0;
:while (($i < 10) && ([/ping address=192.x.x.x interval=3 count=1]=1)) do={:set i value=($i+1)} ;
:if ($i=10) do={
:log info message=“Warning: 10 successful pings to IP 192.x.x.x”; #set your command here
};
But on this way every scheduled time send one email…
I already know the soluction, I just want to incite to think
Why does this have to be so hard.
Script to check for if the main link is down. This will perform the commands you specified once only when the check fails.
:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=0))};
:if ($i=10 && [/ip route get 0 disabled]=no) do={:log info "Warning: 10 failed pings to IP 192.x.x.x";
/ip route disable 0;
/extra command here }
Then create another script if the link is up. This will only perform the command once only when the check is successful.
:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=1))};
:if ($i=10 && [/ip route get 0 disabled]=yes) do={:log info "Warning: 10 successful pings to IP 192.x.x.x";
/ip route enable 0;
/extra command here }
I found my error. I was typing email instead of e-mail. That’s why it wasn’t sending out the email.
Here is what I now have that works:
:local i value=0;
:while (($i < 10) && ([/ping address=x.x.x.x interval=3 count=1]=0)) do={:set i value=($i+1)} ;
:if ($i=10) do={
:log info message=“Warning: 10 unsuccessful pings to IP x.x.x.x”;
/tool e-mail send to=“tony@xxxx.com” subject=“down”;
}Instead of pinging 10 times within 30 seconds, is there a way to ping 5 times spread out over a few minutes?
And, also, is there a way to only execute up and down scripts if the router has been on for x amount of time? I want to prevent sending a bunch of emails all at once every time the router is restarted. For example, it would be something like “if the router has been on for x amount of time execute scripts”. Can this be done?
It would be better if you put the script on the System>Script
Then create a System>Scheduler for it where you can also tweak on how it start during boot up.
On the Scheduler put /system script run scriptname to run the script on specified schedules.