Community discussions

MikroTik App
 
dadaniel
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Fri May 14, 2010 11:51 pm

get packet-loss value from ping

Fri Sep 21, 2018 12:28 pm

Is there a script that gets the built-in packet-loss percentage value of mikrotik's ping command and send a mail when a specific threshold is reached? I'm not very good at scripting, could please someone point me in the right direction?
 
User avatar
rendezz
just joined
Posts: 16
Joined: Mon Sep 17, 2018 11:07 am

Re: get packet-loss value from ping

Fri Sep 21, 2018 2:48 pm

Below is an extract from the Badjr's failover detection code

Take it for a spin
:local totalpingsreceived 0;
:local avgrtt 0;
:local pinglimit 4

/tool flood-ping address=8.8.8.8 count=$pinglimit interval=00:00:01 timeout=00:00:01 do={
        :if ($sent = $pinglimit) do={
             :set totalpingsreceived $"received"
             :if ($totalpingsreceived > 0) do={
                  :set avgrtt $"avg-rtt"
             }
        }
}

:put ("Total Pings Received: ".$totalpingsreceived)
:put ("Avg Rtt: ".$avgrtt)
:put ("Percentage: ".(($pinglimit*100) / ($totalpingsreceived)))