Community discussions

MikroTik App
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 8:13 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 8:48 pm

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... :)
I'm Italian, not English. Sorry for my imperfect grammar.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 10:21 pm

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"?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 10:40 pm

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.
I'm Italian, not English. Sorry for my imperfect grammar.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 11:06 pm

Not working, wait...
I'm Italian, not English. Sorry for my imperfect grammar.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Tue Apr 15, 2014 11:10 pm

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'm Italian, not English. Sorry for my imperfect grammar.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 3:12 am

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
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:17 am

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.
Last edited by nerdtron on Wed Apr 16, 2014 4:21 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:18 am

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...
Last edited by rextended on Wed Apr 16, 2014 4:27 am, edited 5 times in total.
I'm Italian, not English. Sorry for my imperfect grammar.
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:20 am

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.}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:28 am

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 :o
I'm Italian, not English. Sorry for my imperfect grammar.
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:48 am

Why does this have to be so hard. :D
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 }
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:56 am

Why does this have to be so hard. :D
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
}
Last edited by rextended on Wed Apr 16, 2014 5:00 am, edited 1 time in total.
I'm Italian, not English. Sorry for my imperfect grammar.
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 4:58 am

OK that settles it. :lol:
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 5:02 am

OK that settles it. :lol:
Yes!

Only one hint:

put "=" between "while" and "(" when while are after "do"...

:do { <commands> } while=( <conditions> );
:while ( <conditions> ) do={ <commands> };

If you write script on full syntax, do not take risks on future version when scripting are more strict...
I'm Italian, not English. Sorry for my imperfect grammar.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 5:15 am

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?
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 6:16 am

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?
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 6:50 am

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:

ros code

: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.
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 7:37 am

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?
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.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 7:43 am

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.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 8:24 am

I found the variable. Here is what I have:

ros code

: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."
:if ([/system resource get uptime] > 5m) do={
/tool e-mail send to="tony@xxxx.com" subject="down";
}
}
It works.

The "/system resource get uptime" variable prevents the script from sending the email upon router reboot. Let's say you have 20 devices being monitored. Every time you reboot the router you would get 20 emails. That's not fun. Setting this variable to more than 5 minutes eliminates the emails on startup.

Now if I could only ping 5 times and spread it out over 2 minutes, I would be happy!

Can you ping at intervals of 30 seconds? If so, how, and, does this hurt router performance?
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 8:34 am

Change the interval in 24 seconds and change the "10" to 5, this will spread the 5 pings in 2 minutes.
 
tabate47
Member
Member
Topic Author
Posts: 439
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 8:37 am

I tried. Once you get over 9 it doesn't work. Is there a special way to enter 24 seconds?

Also, does this bog down any resources and slow down the router?

Thanks.
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Easiest Way to have Netwatch Ping More than Once

Wed Apr 16, 2014 9:58 am

I tried. Once you get over 9 it doesn't work. Is there a special way to enter 24 seconds?

Also, does this bog down any resources and slow down the router?

Thanks.
That's why don't put it on the netwatch.
Put the script on System>Scripts and create a scheduler for it to run every 2 minutes.
You define the interval of ping on the script by changing interval=3 to interval=24. You define the number of ping on the ($i <10) and ($i=10) change them to 5.
 
dadaniel
Member Candidate
Member Candidate
Posts: 173
Joined: Fri May 14, 2010 11:51 pm

Re: Easiest Way to have Netwatch Ping More than Once

Thu Apr 17, 2014 4:44 pm

is it possible to use
local i
in more than one script at the same time?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2954
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Easiest Way to have Netwatch Ping More than Once

Fri Apr 18, 2014 12:14 am

LOCAL i
I'm Italian, not English. Sorry for my imperfect grammar.

Who is online

Users browsing this forum: brixsat, m86895, mariopl, robo and 66 guests