why i am not getting any log info from this script? Please share your knowledge. thanks
:local pingResult [/ping address=“8.8.8.8” count=1 as-value];
:log info $pingResult
:local minRTT ($pingResult → “min-rtt”);
:local maxRTT ($pingResult → “max-rtt”);
:local avgRTT ($pingResult → “avg-rtt”);
:local sentPackets ($pingResult → “sent”);
:local receivedPackets ($pingResult → “received”);
:local packetLoss ($pingResult → “packet-loss”);
:log info (“Min RTT: $minRTT ms”);
:log info (“Max RTT: $maxRTT ms”);
:log info (“Avg RTT: $avgRTT ms”);
:log info (“Sent Packets: $sentPackets”);
:log info (“Received Packets: $receivedPackets”);
:log info (“Packet Loss: $packetLoss%”);
The first issue is that you code has smart quotes (these “…”) instead of normal quotes. Another issue is that ->
has been converted to →
. Probably both have been messed up by your text editor.
Once that has been corrected, the main problem is that you are trying to access the properties that /ping
does not return by default. You need to include them with the proplist
parameter, this should work:
:local pingResult [/ping address="8.8.8.8" count=1 proplist=min-rtt,max-rtt,avg-rtt,sent,received,packet-loss as-value];
:log info $pingResult
:local minRTT ($pingResult -> "min-rtt");
:local maxRTT ($pingResult -> "max-rtt");
:local avgRTT ($pingResult -> "avg-rtt");
:local sentPackets ($pingResult -> "sent");
:local receivedPackets ($pingResult -> "received");
:local packetLoss ($pingResult -> "packet-loss");
:log info ("Min RTT: $minRTT ms");
:log info ("Max RTT: $maxRTT ms");
:log info ("Avg RTT: $avgRTT ms");
:log info ("Sent Packets: $sentPackets");
:log info ("Received Packets: $receivedPackets");
:log info ("Packet Loss: $packetLoss%");
Please note that if you set the count
parameter of the /ping
command to something greater than 1
, then $pingResult
will contain a list of results, one item for each line that is normally displayed. You should then retrieve data from the last item of that list. Something like this (adjust $pingCount
accordingly):
:local pingCount 5;
:local pingResult [/ping address="8.8.8.8" count=$pingCount proplist=min-rtt,max-rtt,avg-rtt,sent,received,packet-loss as-value];
:log info $pingResult
:if ($pingCount > 1) do={
set pingResult ($pingResult->($pingCount - 1));
}
:local minRTT ($pingResult -> "min-rtt");
:local maxRTT ($pingResult -> "max-rtt");
:local avgRTT ($pingResult -> "avg-rtt");
:local sentPackets ($pingResult -> "sent");
:local receivedPackets ($pingResult -> "received");
:local packetLoss ($pingResult -> "packet-loss");
:log info ("Min RTT: $minRTT ms");
:log info ("Max RTT: $maxRTT ms");
:log info ("Avg RTT: $avgRTT ms");
:log info ("Sent Packets: $sentPackets");
:log info ("Received Packets: $receivedPackets");
:log info ("Packet Loss: $packetLoss%");