mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add choice between ping or dns to omr-tracker
This commit is contained in:
parent
7b94b8742e
commit
8eb08542c0
4 changed files with 61 additions and 26 deletions
|
@ -73,7 +73,40 @@ _post_tracking() {
|
|||
done
|
||||
}
|
||||
|
||||
_restart
|
||||
_ping() {
|
||||
local host=$1
|
||||
local deviceip=$2
|
||||
local localip=$3
|
||||
ret=$(ping "${host}" \
|
||||
-I "${deviceip}" \
|
||||
-W "$OMR_TRACKER_TIMEOUT" \
|
||||
-c 1 \
|
||||
-q
|
||||
) && echo "$ret" | grep -sq "0% packet loss" && {
|
||||
if [ "$localip" = "yes" ]; then
|
||||
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f4 | cut -d "." -f1)
|
||||
_update_rto "$OMR_TRACKER_LATENCY"
|
||||
fi
|
||||
return
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
_dns() {
|
||||
local host=$1
|
||||
local deviceip=$2
|
||||
ret=$(dig @"${host}" \
|
||||
-b "${deviceip}" \
|
||||
+time="$OTB_TRACKER_TIMEOUT" \
|
||||
+tries=1 \
|
||||
openmptcprouter.com
|
||||
) && echo "$ret" | grep -sq "94.23.252.192" && {
|
||||
OTB_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}')
|
||||
_update_rto "$OTB_TRACKER_LATENCY"
|
||||
return
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
# main loop
|
||||
while true; do
|
||||
|
@ -86,36 +119,36 @@ while true; do
|
|||
if [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
|
||||
# retrieve iface ip and gateway
|
||||
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
|
||||
if [ -z "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
|
||||
OTB_TRACKER_DEVICE_GATEWAY=$(ip -4 r list dev "$OMR_TRACKER_DEVICE" | grep -v default | awk '/proto static/ {print $1}' | tr -d "\n")
|
||||
fi
|
||||
|
||||
# execute specific tracker
|
||||
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
|
||||
retgw=$(ping "$OMR_TRACKER_DEVICE_GATEWAY" \
|
||||
-I "$OMR_TRACKER_DEVICE_IP" \
|
||||
-W 1 \
|
||||
-c 1 \
|
||||
-q
|
||||
) && echo "$retgw" | grep -sq "0% packet loss" && {
|
||||
_ping "$OMR_TRACKER_DEVICE_GATEWAY" "$OMR_TRACKER_DEVICE_IP" "no"
|
||||
status=$?
|
||||
if ! $(exit $status); then
|
||||
# setup loop variable
|
||||
tries="$OMR_TRACKER_TRIES"
|
||||
ip route replace "$OMR_TRACKER_HOST" via "$OMR_TRACKER_DEVICE_GATEWAY" dev "$OMR_TRACKER_DEVICE" src "$OMR_TRACKER_DEVICE_IP"
|
||||
# loop until tries attempts have been reached
|
||||
while [ "$tries" -gt 0 ]; do
|
||||
ret=$(ping "$OMR_TRACKER_HOST" \
|
||||
-I "$OMR_TRACKER_DEVICE_IP" \
|
||||
-W "$OMR_TRACKER_TIMEOUT" \
|
||||
-c 1 \
|
||||
-q
|
||||
) && echo "$ret" | grep -sq "0% packet loss" && {
|
||||
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f4 | cut -d "." -f1)
|
||||
_update_rto "$OMR_TRACKER_LATENCY"
|
||||
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
|
||||
_ping "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE_IP" "yes"
|
||||
status=$?
|
||||
elif [ "$OMR_TRACKER_TYPE" = "dns" ]; then
|
||||
_dns "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE_IP" "yes"
|
||||
status=$?
|
||||
fi
|
||||
if ! $(exit $status); then
|
||||
OMR_TRACKER_STATUS="OK"
|
||||
break
|
||||
}
|
||||
fi
|
||||
tries=$((tries - 1))
|
||||
OMR_TRACKER_TIMEOUT=$((OMR_TRACKER_TIMEOUT * 2))
|
||||
done
|
||||
ip route del "$OMR_TRACKER_HOST" via "$OMR_TRACKER_DEVICE_GATEWAY" dev "$OMR_TRACKER_DEVICE" src "$OMR_TRACKER_DEVICE_IP"
|
||||
}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue