Easiest Way to have Netwatch Ping More than Once

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?


Thanks.

Implement double-ckeck alarms.

First time alarm triggered set one global variable to previous-value + 1,

The second time again previous value+1,

If the tird time the alarm was triggered, set var +1, and if now is = 3 send email.

If the nth time the alarm are triggered, if the var is = 3 do nothing.

When the alarm return, set global variable to 0

HINT:you can increase check time, instead…


If you like my idea, add Karma… :slight_smile:

Thanks for writing me back.

Do you mean something like this:

Down:
:if ([/ping 10.0.0.1 count=2] = 0) do={
/ip firewall nat set enable 0;
/ip route disable 0;
/tool e-mail send to=“person@email.com” subject=“Gateway Down” body=“Pinged out.”;
}

Up:
:if ([/ping 10.0.0.1 count=2] = 2) do={
/ip firewall nat set disable 0;
/ip route enable 0;
/tool e-mail send to=“person@email.com” subject=“Gateway Up” body=“Pinged in.”;
}

What do you mean by “you can increase check time”?

Ok, wait 5/10 min, I’m writing.

Not working, wait…

On up:

:global trigger1sendmail value=0;

On Down:

:global trigger1sendmail value=1;
/delay delay-time=100s;
:if ($trigger1sendmail = 1) do={
# place send mail here
};

If the service go up inside 100 seconds, the mail are not send.

I don’t have as much knowledge as most of you here at the forum, but is there a way to:

create a variable to count the number of pings.

on up, send an email

on down, ping the device 3 times before an email is sent

Basically I am trying to prevent false alarms.

I’m sure there are many scripts out there that do this.

If anyone has something they can share with me I would appreciate it.

Thank you

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.

(I prefer complete and formatted syntax):

: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
};

Missing the part, when go up send email…

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 :astonished:

Why does this have to be so hard. :smiley:
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 }

Well done, I understand, but this is better than disable default route?

:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=0))};
:if ($i=10 && (> $globalvarname=“ok”> )) do={:log info “Warning: 10 failed pings to IP 192.x.x.x”;
:global globalvarname value=“ko”;
/extra command here
}



:local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 192.x.x.x interval=3 count=1]=1))};
:if ($i=10 && (> $globalvarname=“ko”> )) do={:log info “Warning: 10 successful pings to IP 192.x.x.x”;
:global globalvarname value=“ok”;
/extra command here
}

OK that settles it. :laughing:

Yes!

Only one hint:

put “=” between “while” and “(” when while are after “do”…

:do { } while=( );
:while ( ) do={ };

If you write script on full syntax, do not take risks on future version when scripting are more strict…

You guys are confusing me.

Can I put these scripts in the up and down area of netwatch, or do they need to go somewhere else?

Ok,

I put this in my “down” area in netwatch:

: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 email send to=“tony@xxxx.com” subject=“down”;
}

I am getting the warning message in my log, but the email is not being sent.

What is the problem?

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?

Thanks for all the help.

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.

Is there a variable for how long the system has been up?

If so, I can tell the script not to email if the system has not been up long enough.