Community discussions

MikroTik App
 
aunk
just joined
Topic Author
Posts: 1
Joined: Fri Jun 15, 2007 10:54 am

need script advance ping based

Sat Aug 25, 2007 8:49 am

halo all, anyone can give me a clue, i want script that can sum the duration of downtime connection based on ping. the sum of downtime can be place on a file such downupconnection.log or something.

for example the output log is like this...

mon 17 August 2007 22:30PM down - mon 17 August 2007 22:37PM up, duration down 7 minutes
mon 17 August 2007 23:37PM up - mon 18 August 2007 00:50 down, duration up 73 minutes

also vice versa...
Is netwatch capable doing this? i'm sorry for my bad english. thanks before,


regards.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7054
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: need script advance ping based

Sat Aug 25, 2007 10:52 am

on netwatch Down:

:global downStart [ /system clock get time ];

on netwatch Up:

:if( $downStat != "" ) do={
:log warning ( "Down, duration " . ( [ /system clock get time ] - downStart ) ;
:set downStart "";
}


Something like that
 
User avatar
Viroslash
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Wed Jun 20, 2007 5:39 am
Location: La Plata, Buenos Aires, Argentina
Contact:

Re: need script advance ping based

Wed Sep 26, 2007 6:42 am

And if I want to create a logfile of these information how can I do it?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7054
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: need script advance ping based

Wed Sep 26, 2007 9:19 am

/log print file=filename will print logs to file
 
User avatar
Viroslash
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Wed Jun 20, 2007 5:39 am
Location: La Plata, Buenos Aires, Argentina
Contact:

Re: need script advance ping based

Wed Sep 26, 2007 8:20 pm

OK, my idea is use Netwatch for ping a host and when this host is down the alarm script in Netwatch is turned on. I need log in a file the date, hour and ip of the host:

My script:
:for c from=1 to=10 step=1  \

    do={ \
         :set i 15
          :set x 1900

         :do {\
                 :beep length=400ms frequency=$x; :delay 25ms
                 :set i ($i - 1);
                 :set x ($x +35)

               } \
                 while (($i <16) && ($i >0))
                :beep length=0 frequency=0
    }
I hope you can understand, my english is bad.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7054
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: need script advance ping based

Thu Sep 27, 2007 9:23 am

As far as i know it is not possible to get hosts IP from netwatch. Instead you can run a script from scheduler:

:if ([/ping 192.168.1.1 count=3] = 0) do={ ... host is down issue alarm... };

something like that.
 
sten
Forum Veteran
Forum Veteran
Posts: 919
Joined: Tue Jun 01, 2004 12:10 pm

Re: need script advance ping based

Sun Sep 30, 2007 4:07 am

First add the scripts to handle the up and down events.
/ system script add name=netup source={ :log info ( $nethost . " is up" ) }
/ system script add name=netdown source={ :log info ( $nethost . " is down" ) }
Then add netwatch hosts like this
:foreach host in=192.168.1.2,192.168.1.3,192.168.1.4 do={
	/ tool netwatch add host=$host timeout=1s interval=5s \
		up-script=( "{ :global nethost " . $host . "; / system run script netup }" ) 
		down-script=( "{ :global nethost " . $host . "; / system run script netdown }" )
}
Would something like this work?

Who is online

Users browsing this forum: No registered users and 33 guests