I’m trying to build a script to improve netwatch ability to notify downs on some VPN connections, those VPN connections are from SIM routers so I’m getting a lot of false downs while using netwatch (they disconnect for a while sometimes).
My idea is to create a script run by the scheduler that ping’s all the IP’s on /ppp secret tab, if the IP is down then a global variable ( counter unique for that host) is increased by 1, and if the IP is up then the counter goes back to 0. At the end, there’s an IF that checks if the counter is bigger than X and sends a notification. In my lack of understanding, I have not been able to implement that global “per-host variable” that I need. Since dynamic variables, or “variable in a variable” are not possible I’m stuck…
So far that’s the script I’ve written.
:local pingip
:log info "Script"
:foreach id in=[/ppp secret find where profile=SIMRouters ] do={
:global $id_counter
:local name [/ppp secret get $id name]
:local address [/ppp secret get $id remote-address]
:set pingip [/ping $address count=1]
:if ($pingip = 0) do={
:log info "Fail PING on $address $name"
THERE SHOULD BE THE COUNTER + 1 #PSEUDOCODE
IF COUNTER > X NOTIFY #PSEUDOCODE
} else={
log info "Ping OK on $address $name"
COUNTER = 0 #PSEUDOCODE
}
}
I’m missing a lot of knowledge so any advice would be really apreciated.
Perfect base for create better netwatch.
I start my own with idea of :local arrayofoperators {“WAN1 Orange GW”=192.168.1.1 ; “WAN2 ITSA GW”=192.168.2.2 } … but this is OT here.
What when we receive that:
put [typeof [ping 192.168.1.1 count=1]]
Columns: SEQ, HOST, SIZE, TTL, TIME, STATUS
SEQ HOST SIZE TTL TIME STATUS
0 37.109.59.29 84 64 1ms497us > net unreachable
nil
Probably better when main ([:ping $premip count=1] = 1) do={put “Only OK”} else={put “All timeout and nil results and other like no buffer space :D”}
:put [:typeof [:ping 1.1.1.1 count=1]]
return nil at 7.1rc4 what is bug of course and a !=1 not help because even ping is OK then this nil exist and we have falsepossitive :).
Many, many thanks to you all especially for the brilliant response of @rextended, not only works flawlessly but also you’ve taken you time to explain and give really good advice about the script, I’m truly happy for your help. I do know now a little bit more about ROS thanks to you