Community discussions

MikroTik App
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Netwatch II

Tue Oct 14, 2008 11:06 pm

I was using this script http://wiki.mikrotik.com/wiki/Improved_Netwatch_II for a couple of years without a problem on my 2.9.xx Mikrotik.
I had bought a license for Mikrotik 3.x and the same script doesn't work with 3.14
Can somebody adapt it to version 3.14? Without documentation on 3.x scripting host, I can't figure out there the problem lies in the script :(
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Netwatch II

Wed Oct 15, 2008 8:56 am

       :local i 0;
       
       {
       
            :do {
       
                    :set i ($i + 1);
       
            } while=(($i < 5) && ([/ping xx.xx.xx.xx interval=3 count=1]=0))
       
            :if ($i=5 && [/ip route get [find comment="Default Route"] distance]=1) do={
       
            :log info "Main Gateway down";
       
            /ip route set [find comment="Default Route"] distance=3;
       
       }


Last edited by mrz on Wed Oct 15, 2008 4:00 pm, edited 1 time in total.
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Re: Netwatch II

Wed Oct 15, 2008 3:49 pm

mrz Thank you, but it just keeps saying:

For
:set i ($i + 1);
this error:
expected variable name (line 1 column 6)

For
:if ($i=5 && [/ip route get [find comment="Default Route"]
distance]=1
this error:
syntax error (line 1 column 17)

Then I just launch the script by pressing Run Script, only silence I hear.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Netwatch II

Wed Oct 15, 2008 4:00 pm

sorry, script edited. It is working on my router.
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Re: Netwatch II

Wed Oct 15, 2008 7:19 pm

sorry, script edited. It is working on my router.
Sorry to say, but I had tried to paste it with spaces, without spaces...all the ways i could invent :D
Nothing! nothing! nothing! :evil:

Then I launch it, it's not even pinging the host. I can judge this by looking at the counters of my icmp rule.
Then I create a simple script, that just pings(/ping xx.xx.xx.xx), the counters show that it's working and in /ip firewall connections I clearly see this.

WTF i'm doing wrong?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Netwatch II

Thu Oct 16, 2008 8:25 am

Run script manually from console, if there are any errors they will be shown in console output.
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Re: Netwatch II

Thu Oct 16, 2008 1:13 pm

mrz, I did test the script from console and it gives me the same errors as in my previous messages.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Netwatch II

Thu Oct 16, 2008 1:20 pm

1) When you paste script directly in console then put it all in { }.
otherwise first line where local i is defined will be treated as another script.

2) You need route in routing table with comment "Default Route"

Script is working if both conditions above are met.
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Re: Netwatch II

Thu Oct 16, 2008 1:23 pm

1) When you paste script directly in console then put it all in { }.
otherwise first line where local i is defined will be treated as another script.
I didn't know that you have to put the script in { }. Thank you. I will try later.
 
quickgen
newbie
Topic Author
Posts: 25
Joined: Thu Jun 14, 2007 7:42 pm

Re: Netwatch II

Sun Oct 19, 2008 1:32 am

mrz your script is working ok with one more } at the end.

So the final script look like:
:local i 0;

{

:do {

:set i ($i + 1);

} while=(($i < 5) && ([/ping xx.xx.xx.xx interval=3 count=1]=0))

:if ($i=5 && [/ip route get [find comment="Default Route"] distance]=1) do={

:log info "Main Gateway down";

/ip route set [find comment="Default Route"] distance=3;

}
}
Big thanks for your help.