1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 02:51:50 +00:00

Use httping to ping server if option defined in omr-tracker

This commit is contained in:
Ycarus (Yannick Chabanois) 2021-02-19 11:38:03 +01:00
parent fff416b868
commit b974317b37

View file

@ -87,16 +87,45 @@ _post_tracking() {
}
_ping_server() {
local serverip=$(uci -q get openmptcprouter.$1.ip)
local servername=$1
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local device=$2
if [ -n "$serverip" ] && [ -n "$device" ]; then
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() {
serverip=$1
if [ -n "$serverip" ]; then
_ping $serverip $device "yes"
statusp=$?
if $(exit $statusp); then
serverip_ping=true
break
fi
else
serverip_ping=false
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
fi
}
_httping_server() {
local servername=$1
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local port=$(uci -q get openmptcprouter.$1.port)
local device=$2
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() {
serverip=$1
if [ -n "$serverip" ]; then
_httping "${serverip}:${port}" $device "yes" true
statusp=$?
if $(exit $statusp); then
serverip_ping=true
break
fi
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
fi
}
@ -138,6 +167,8 @@ _httping() {
local host=$1
local deviceip=$2
local localip=$3
local https=$4
if [ -z "$https" ] || [ "$https" = false ]; then
ret=$(httping "${host}" \
-y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \
@ -150,6 +181,20 @@ _httping() {
fi
return
}
else
ret=$(httping -l "${host}" \
-y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \
-c 1 \
-q
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
fi
false
}
@ -283,6 +328,10 @@ while true; do
config_load openmptcprouter
config_foreach _ping_server server $OMR_TRACKER_DEVICE
fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE
fi
if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST" ]; then
OMR_TRACKER_HOST=$(resolveip -4 -t 5 $OMR_TRACKER_HOST | head -n 1 | tr -d "\n")
if [ -n "$OMR_TRACKER_HOST" ]; then
@ -366,6 +415,11 @@ while true; do
config_load openmptcprouter
config_foreach _ping_server server $OMR_TRACKER_DEVICE
fi
if [ "$OMR_TRACKER_TYPE" = "httping" ]; then
config_load openmptcprouter
config_foreach _httping_server server $OMR_TRACKER_DEVICE
fi
if [ "$serverip_ping" = false ] && [ -n "$OMR_TRACKER_HOST6" ]; then
OMR_TRACKER_HOST6=$(resolveip -6 -t 5 $OMR_TRACKER_HOST6 | head -n 1 | tr -d "\n")
if [ -n "$OMR_TRACKER_HOST6" ]; then