Community discussions

MikroTik App
 
dmfr
newbie
Topic Author
Posts: 44
Joined: Thu Oct 15, 2020 11:14 am

V7 : Ping return as watchdog / scripting

Fri Sep 03, 2021 5:42 pm

Found a divergence in /ping command output between V6 and V7.
Consider an unreachable IP address (10.99.99.99) and script sentence to return TRUE if actually unreachable :
[admin@mtk-V6] > :put ([/ping count=4 address=10.99.99.99]=0)
true
[admin@mtk-V7] > :put ([/ping count=4 address=10.99.99.99]=0)
false
Thing is, V7 ping does not return explicit 0 when nothing pings. It just returns nothing/null.

Workaround :
[admin@mtk-V7] > :put (!([/ping count=4 address=10.99.99.99]>0))
true
Is it expected behavior ?
If V6 behavior cannot be restored, it means a lot of watchdog scripts needs fixing.
 
mTvGqH2
just joined
Posts: 4
Joined: Wed Jan 17, 2018 9:43 pm

Re: V7 : Ping return as watchdog / scripting

Sat Jan 08, 2022 12:04 pm

I think your workaround doesn't solve the problem, isn't it?
It always returns true.
[admin@router] > :put (!([/ping count=1 address=8.8.8.8]>0))
Columns: SEQ, HOST, SIZE, TTL, TIME
SEQ  HOST     SIZE  TTL  TIME    
  0  8.8.8.8    56  118  9ms973us

true
[admin@router] > :put (!([/ping count=1 address=8.8.8.1]>0))
Columns: SEQ, HOST, STATUS
SEQ  HOST     STATUS 
  0  8.8.8.1  timeout

true
Any other hints how to use the result of "ping" in a script with v7 ?
 
michaelj
just joined
Posts: 1
Joined: Mon Mar 25, 2019 2:57 pm

Re: V7 : Ping return as watchdog / scripting

Tue Jan 11, 2022 4:43 pm

I found out that in V7 you can use the parameter "as-value". This converts the result to a string.

Furthermore I found out that the "Status" column only is filled out when the ping has failed. I can be wrong on this but I couldn't create a scenario where there was connection while status was filled out.

We can therefore use the status column (or lack of) to determine if there is connection or not
:put ( [/ping address=8.8.8.8 count=1 as-value]->"status"=null)
true

:put ( [/ping address=8.0.0.0 count=1 as-value]->"status"=null)
false
as-value is NOT available in V6 for the ping command

Hope this helps

Who is online

Users browsing this forum: mrz and 23 guests