Please get help. I need a to run any ping (with count=1) command and write timeout to variable.
I plan to send this values to influxdb for both external ifaces (dual wan). So it is important that the interface is specified.
I tried many cases. But cannot found a working solution.
I apologize for the extra code - this is an outline for now.
Case 1. Here I cannot save timeout to variable:
[admin@MikroTik] > /ping address="8.8.8.8" count=1
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 56 56 27ms
sent=1 received=1 packet-loss=0% min-rtt=27ms avg-rtt=27ms max-rtt=27ms
# how to get avg-rtt at line here in the variable ?
Case 2. Here I cannot understand how it works, and why it works not as expected.
:log info "my script started"
:local pingIp "87.250.250.242"
:local pingCount 1
:local pingInterface "pppoe-rt"
:local pingStatus
:local avgRtt
:local influxurl "http://192.168.129.2:8086/write?db=icmp"
:log info "my script middle"
:while (true) do={
:log info "icmp-monitoring: while start"
/tool flood-ping $pingIp count=$pingCount do={
:if ($sent = 2) do={
:set avgRtt $"avg-rtt"
:log info "sent for $pingIp is $sent"
:log info "avgRtt for $pingIp is $avgRtt"
}
}
/delay delay-time=5s
:log info "icmp-monitoring: while end"
};
:log info "my script ended: $influxurl"
Here is what it writes to logging:
15:20:30 script,info icmp-monitoring: while start
15:20:30 script,info sent for 87.250.250.242 is 1
15:20:30 script,info avgRtt for 87.250.250.242 is 0
15:20:31 script,info sent for 87.250.250.242 is 1
15:20:31 script,info avgRtt for 87.250.250.242 is 38
15:20:32 script,info icmp-monitoring: while end
15:20:32 script,info icmp-monitoring: while start
15:20:32 script,info sent for 87.250.250.242 is 1
15:20:32 script,info avgRtt for 87.250.250.242 is 0
15:20:33 script,info sent for 87.250.250.242 is 1
15:20:33 script,info avgRtt for 87.250.250.242 is 37
15:20:34 script,info icmp-monitoring: while end
15:20:34 script,info icmp-monitoring: while start
15:20:34 script,info sent for 87.250.250.242 is 1
15:20:34 script,info avgRtt for 87.250.250.242 is 0