Community discussions

MikroTik App
 
Dangeroussss
just joined
Topic Author
Posts: 7
Joined: Thu Sep 27, 2012 10:19 am

Help with my PING script!

Tue Nov 27, 2012 3:15 pm

Hi Guys,

I need some HELP!

Im doing a script for a Mikrotik for a ping test.

Basically the MT needs to ping an ip and if the ip got 5 request timeouts it must do a task(the task is to disable a route on the MT ). But I can't get it to work can you see if below makes any sense for you. Then I have the same script for a up check. So basically if the ping to 10.10.10.1 fails for 5 times it swaps to alternative route( disabling the Default route)

:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 10.10.10.1 interval=3 count=1]=0))};
:if ($i=5 && ( [/ip route find where comment ="Default Route" disabled=yes ] != "")) do={:log info "have swapped";
}

Below is the UP check


:local i 0; {:do {:set i ($i + 1)} while (($i < 5) && ([/ping 10.10.10.1 interval=3 count=1]=1))};
:if ($i=5 && ( [/ip route find where comment ="Default Route" disabled=no ] != "")) do={:log info "have not swapped route";
}


best Regards
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Help with my PING script!

Fri Nov 30, 2012 2:59 am

Try this:
:local p [/ping 172.19.10.201 count=5];

# if ping failed and route is not disabled, disable it
:if ($p = 0 && [/ip route get [find where comment ="Default Route"] disabled] = false) do={
	/log info "ping fail, disabling route";
	/ip route disable [find where comment ="Default Route"];
}
# if ping succeeded and route is not enabled, enable it
:if ($p = 5 && [/ip route get [find where comment ="Default Route"] disabled] = true) do={
	/log info "ping success, enabling route";
	/ip route enable [find where comment ="Default Route"];
}
 
wcsnet
Frequent Visitor
Frequent Visitor
Posts: 64
Joined: Mon Apr 29, 2013 12:43 pm
Location: South Africa

Re: Help with my PING script!

Wed Jul 30, 2014 12:20 pm

Maybe this will help

Address list item looks like this

add address=10.0.0.175 comment=wcsnet-ps1*100 list="router ping"


:global scriptemail
:global lastping

:local content
:local checkip
:local checklaststatus
:local checknewstatus
:local checkcomment

:local difference

:local list
:local alerts 0

:log info "******************** starting - ip ping report********************"
:log info "-"

:foreach i in=[/ip firewall address-list find] do={

:set list ([/ip firewall address-list get $i list] )
:if ($list = "router ping") do={

:set checkip ([/ip firewall address-list get $i address] )
:set content ([/ip firewall address-list get $i comment] )

:if ([:find $content "*"] != "") do={

:local pos1 [:find $content "*"]
:local pos2 [:len $content]

:set checklaststatus ([:pick $content ($pos1+1) $pos2])
:set checkcomment ([:pick $content 0 ($pos1)])

:local perc ([/ping $checkip count=10] * 10)

:set checknewstatus "$perc"

:set difference (checknewstatus - $checklaststatus)

:if ($difference < 0) do={
:set difference ($difference * -1)
} else={
:set difference ($difference * 1)
}

:if (difference >= 50 ) do={
/ip firewall address-list set $i comment="$checkcomment*$checknewstatus"
:set alerts ($alerts + 1)

:log warning "$[/system identity get name] connectively test state changed [ $checkcomment ] $checklaststatus -> $checknewstatus state difference: $difference"

}

}
}
}

:set lastping "$[/system clock get date] $[/system clock get time]"

:log info "******************** ending - ip ping report ********************"

Who is online

Users browsing this forum: navigator and 31 guests