mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Use httping to ping server if option defined in omr-tracker
This commit is contained in:
parent
fff416b868
commit
b974317b37
1 changed files with 75 additions and 21 deletions
|
@ -87,16 +87,45 @@ _post_tracking() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ping_server() {
|
_ping_server() {
|
||||||
local serverip=$(uci -q get openmptcprouter.$1.ip)
|
local servername=$1
|
||||||
|
local disabled=$(uci -q get openmptcprouter.$1.disabled)
|
||||||
local device=$2
|
local device=$2
|
||||||
if [ -n "$serverip" ] && [ -n "$device" ]; then
|
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
|
||||||
_ping $serverip $device "yes"
|
check_ping() {
|
||||||
statusp=$?
|
serverip=$1
|
||||||
if $(exit $statusp); then
|
if [ -n "$serverip" ]; then
|
||||||
serverip_ping=true
|
_ping $serverip $device "yes"
|
||||||
fi
|
statusp=$?
|
||||||
else
|
if $(exit $statusp); then
|
||||||
serverip_ping=false
|
serverip_ping=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,18 +167,34 @@ _httping() {
|
||||||
local host=$1
|
local host=$1
|
||||||
local deviceip=$2
|
local deviceip=$2
|
||||||
local localip=$3
|
local localip=$3
|
||||||
ret=$(httping "${host}" \
|
local https=$4
|
||||||
-y "${deviceip}" \
|
if [ -z "$https" ] || [ "$https" = false ]; then
|
||||||
-t "$OMR_TRACKER_TIMEOUT" \
|
ret=$(httping "${host}" \
|
||||||
-c 1 \
|
-y "${deviceip}" \
|
||||||
-q
|
-t "$OMR_TRACKER_TIMEOUT" \
|
||||||
) && echo "$ret" | grep -sq "1 ok" && {
|
-c 1 \
|
||||||
if [ "$localip" = "yes" ]; then
|
-q
|
||||||
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
|
) && echo "$ret" | grep -sq "1 ok" && {
|
||||||
_update_rto "$OMR_TRACKER_LATENCY"
|
if [ "$localip" = "yes" ]; then
|
||||||
fi
|
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1)
|
||||||
return
|
_update_rto "$OMR_TRACKER_LATENCY"
|
||||||
}
|
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
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +328,10 @@ while true; do
|
||||||
config_load openmptcprouter
|
config_load openmptcprouter
|
||||||
config_foreach _ping_server server $OMR_TRACKER_DEVICE
|
config_foreach _ping_server server $OMR_TRACKER_DEVICE
|
||||||
fi
|
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
|
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")
|
OMR_TRACKER_HOST=$(resolveip -4 -t 5 $OMR_TRACKER_HOST | head -n 1 | tr -d "\n")
|
||||||
if [ -n "$OMR_TRACKER_HOST" ]; then
|
if [ -n "$OMR_TRACKER_HOST" ]; then
|
||||||
|
@ -366,6 +415,11 @@ while true; do
|
||||||
config_load openmptcprouter
|
config_load openmptcprouter
|
||||||
config_foreach _ping_server server $OMR_TRACKER_DEVICE
|
config_foreach _ping_server server $OMR_TRACKER_DEVICE
|
||||||
fi
|
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
|
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")
|
OMR_TRACKER_HOST6=$(resolveip -6 -t 5 $OMR_TRACKER_HOST6 | head -n 1 | tr -d "\n")
|
||||||
if [ -n "$OMR_TRACKER_HOST6" ]; then
|
if [ -n "$OMR_TRACKER_HOST6" ]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue