1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

New version of OMR-Tracker

This commit is contained in:
Ycarus (Yannick Chabanois) 2024-01-12 17:28:40 +01:00
parent bb64827a1e
commit f5b3aa6831
15 changed files with 831 additions and 318 deletions

View file

@ -17,6 +17,9 @@ export OMR_TRACKER_INTERFACE
export OMR_TRACKER_HOST
export OMR_TRACKER_HOST6
export OMR_TRACKER_TIMEOUT
export OMR_TRACKER_SIZE
export OMR_TRACKER_MAX_TTL
export OMR_TRACKER_LOSS
export OMR_TRACKER_STATUS
export OMR_TRACKER_STATUS_MSG
export OMR_TRACKER_PREV_STATUS
@ -150,6 +153,8 @@ _ping() {
ret=$(ping -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
-c "$OMR_TRACKER_COUNT" \
-s "$OMR_TRACKER_SIZE" \
-t "$OMR_TRACKER_MAX_TTL" \
-Q 184 \
"${host}" 2>&1
) && echo "$ret" | grep -sq " 0% packet loss" && {
@ -163,15 +168,20 @@ _ping() {
ret=$(ping -B -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
-c "$OMR_TRACKER_COUNT" \
-s "$OMR_TRACKER_SIZE" \
-t "$OMR_TRACKER_MAX_TTL" \
-Q 184 \
"${host}" 2>&1
) && echo "$ret" | grep -sq " 0% packet loss" && {
)
loss=$(echo "$ret" | grep 'packet loss' | sed -ne 's/.*\([0-9]\+\)% packet loss.*/\1/p')
if [ -n "$loss" ] && [ "$loss" -ne 100 ]; then
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
OMR_TRACKER_LOSS="$loss"
_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
fi
#) && echo "$ret" | grep -sq "bytes from" && {
fi
false
@ -242,6 +252,7 @@ while true; do
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG=""
OMR_TRACKER_LATENCY=
OMR_TRACKER_LOSS=
#OMR_TRACKER_TIMEOUT=$((rto / 1000 + (rto % 1000 ? 1 : 0)))
OMR_TRACKER_LIST_HOSTS=""
OMR_TRACKER_DEVICE_GATEWAY=
@ -259,7 +270,7 @@ while true; do
if [ -n "$OMR_TRACKER_DEVICE" ] && [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
if [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep UP)" ]; then
# retrieve iface ip and gateway
if [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
if [ -z "$OMR_TRACKER_DEVICE_IP" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 addr show dev "$OMR_TRACKER_DEVICE" | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1)
@ -305,7 +316,7 @@ while true; do
OMR_TRACKER_DEVICE_GATEWAY=$(ip -4 r list dev "$OMR_TRACKER_DEVICE" | awk '/via/ {print $3}' | tr -d "\n")
fi
fi
if [ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ]; then
if ([ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ] || [ -z "$OMR_TRACKER_IPV6" ]) && ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]); then
#OMR_TRACKER_DEVICE_IP6=$(ip -6 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
#if [ -z "$OMR_TRACKER_DEVICE_IP6" ]; then
OMR_TRACKER_DEVICE_IP6=$(ip -6 addr show dev "$OMR_TRACKER_DEVICE" | sort -r | grep -m 1 inet6 | awk '{print $2}' | cut -d'/' -s -f1)
@ -331,9 +342,13 @@ while true; do
fi
# execute specific tracker
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
# setup loop variable
tries="$OMR_TRACKER_TRIES"
if [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
tries="$OMR_TRACKER_TRIES"
else
tries="$OMR_TRACKER_TRIES_UP"
fi
# loop until tries attempts have been reached
while [ "$tries" -gt 0 ]; do
if [ -n "$OMR_TRACKER_DEVICE_ROUTE" ]; then
@ -430,9 +445,14 @@ while true; do
sleep "$OMR_TRACKER_INTERVAL_TRIES"
done
fi
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
#if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
if ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; then
# setup loop variable
tries="$OMR_TRACKER_TRIES"
if [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
tries="$OMR_TRACKER_TRIES"
else
tries="$OMR_TRACKER_TRIES_UP"
fi
# loop until tries attempts have been reached
while [ "$tries" -gt 0 ]; do
#if [ -n "$OMR_TRACKER_DEVICE_ROUTE" ]; then
@ -534,7 +554,7 @@ while true; do
[ -z "$OMR_TRACKER_STATUS_MSG" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_INTERFACE may have ip issues"
[ -z "$OMR_TRACKER_DEVICE_IP" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv4"
[ -z "$OMR_TRACKER_DEVICE_GATEWAY" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv4 gateway"
if [ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "0" ]; then
if ([ "$OMR_TRACKER_IPV6" = "1" ] || [ "$OMR_TRACKER_IPV6" = "auto" ] || [ -z "$OMR_TRACKER_IPV6" ]) && ([ "$OMR_TRACKER_FAMILY" = "ipv6" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]); then
[ -z "$OMR_TRACKER_DEVICE_IP6" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv6"
[ -z "$OMR_TRACKER_DEVICE_GATEWAY6" ] && OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG, interface have no IPv6 gateway"
fi
@ -558,6 +578,26 @@ while true; do
OMR_TRACKER_STATUS_MSG="$OMR_TRACKER_STATUS_MSG and $OMR_TRACKER_TYPE from $OMR_TRACKER_DEVICE_IP error ($OMR_TRACKER_LIST_HOSTS6)"
fi
fi
if [ "$OMR_TRACKER_CHECK_QUALITY" = "1" ]; then
if [ "$OMR_TRACKER_PREV_STATUS" = "OK" ]; then
if [ -n "$OMR_TRACKER_LOSS" ] && [ "$OMR_TRACKER_LOSS" -ge "$OMR_TRACKER_LOSS_FAILURE" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG="Packet loss is $OMR_TRACKER_LOSS this is more than limit defined at $OMR_TRACKER_LOSS_FAILURE"
fi
if [ -n "$OMR_TRACKER_LATENCY" ] && [ "$OMR_TRACKER_LATENCY" -ge "$OMR_TRACKER_LATENCY_FAILURE" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="ERROR"
OMR_TRACKER_STATUS_MSG="Latency is $OMR_TRACKER_LATENCY this is more than limit defined at $OMR_TRACKER_LATENCY_FAILURE"
fi
elif [ "$OMR_TRACKER_PREV_STATUS" = "ERROR" ]; then
OMR_TRACKER_STATUS="ERROR"
if [ -n "$OMR_TRACKER_LOSS" ] && [ "$OMR_TRACKER_LOSS" -le "$OMR_TRACKER_LOSS_RECOVERY" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="OK"
fi
if [ -n "$OMR_TRACKER_LATENCY" ] && [ "$OMR_TRACKER_LATENCY" -ge "$OMR_TRACKER_LATENCY_RECOVERY" ] && [ "$OMR_TRACKER_STATUS" = "OK" ]; then
OMR_TRACKER_STATUS="OK"
fi
fi
fi
#[ "$OMR_TRACKER_HOSTS" = "$initial_hosts" ] || [ "$OMR_TRACKER_STATUS" = "OK" ] && _post_tracking
#[ "$OMR_TRACKER_STATUS" = "ERROR" ] && _restart
@ -567,5 +607,9 @@ while true; do
OMR_TRACKER_PREV_STATUS="$OMR_TRACKER_STATUS"
_restart
sleep "$OMR_TRACKER_INTERVAL"
if [ "$OMR_TRACKER_STATUS" = "ERROR" ]; then
sleep "$OMR_TRACKER_FAILURE_INTERVAL"
else
sleep "$OMR_TRACKER_INTERVAL"
fi
done