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

Add test count as setting for OMR-Tracker

This commit is contained in:
Ycarus (Yannick Chabanois) 2023-12-15 19:30:31 +01:00
parent e374f7cb2e
commit ced4a76faa
5 changed files with 35 additions and 12 deletions

View file

@ -110,12 +110,18 @@ o.default = "1"
o.datatype = "range(1, 100)" o.datatype = "range(1, 100)"
o.rmempty = false o.rmempty = false
o = s:option(Value, "tries", translate("Tries")) o = s:option(Value, "tries", translate("Tries"), translate("How many times repeat test"))
o.placeholder = "4" o.placeholder = "4"
o.default = "4" o.default = "4"
o.datatype = "range(1, 10)" o.datatype = "range(1, 10)"
o.rmempty = false o.rmempty = false
o = s:option(Value, "count", translate("Count"), translate("How many packets send on each test"))
o.placeholder = "2"
o.default = "2"
o.datatype = "range(1, 100)"
o.rmempty = false
o = s:option(Value, "interval", translate("Retry interval (s)")) o = s:option(Value, "interval", translate("Retry interval (s)"))
o.placeholder = "2" o.placeholder = "2"
o.default = "2" o.default = "2"
@ -191,6 +197,12 @@ o.default = "4"
o.datatype = "range(1, 10)" o.datatype = "range(1, 10)"
o.rmempty = false o.rmempty = false
o = s:option(Value, "count", translate("Count"), translate("How many packets send on each test, one wrong make test fail, one wrong make tail fail"))
o.placeholder = "2"
o.default = "2"
o.datatype = "range(1, 100)"
o.rmempty = false
o = s:option(Value, "interval", translate("Retry interval (s)")) o = s:option(Value, "interval", translate("Retry interval (s)"))
o.placeholder = "2" o.placeholder = "2"
o.default = "2" o.default = "2"

View file

@ -148,10 +148,10 @@ _ping() {
if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "3g" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "qmi" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "ncm" ]); then if [ -n "$OMR_TRACKER_INTERFACE" ] && ([ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "3g" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "qmi" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "ncm" ]); then
ret=$(ping -I "${device}" \ ret=$(ping -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \ -w "$OMR_TRACKER_TIMEOUT" \
-c 2 \ -c "$OMR_TRACKER_COUNT" \
-Q 184 \ -Q 184 \
"${host}" 2>&1 "${host}" 2>&1
) && echo "$ret" | grep -sq "bytes from" && { ) && echo "$ret" | grep -sq " 0% packet loss" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY" _update_rto "$OMR_TRACKER_LATENCY"
@ -161,16 +161,17 @@ _ping() {
else else
ret=$(ping -B -I "${device}" \ ret=$(ping -B -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \ -w "$OMR_TRACKER_TIMEOUT" \
-c 2 \ -c "$OMR_TRACKER_COUNT" \
-Q 184 \ -Q 184 \
"${host}" 2>&1 "${host}" 2>&1
) && echo "$ret" | grep -sq "bytes from" && { ) && echo "$ret" | grep -sq " 0% packet loss" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY" _update_rto "$OMR_TRACKER_LATENCY"
fi fi
return return
} }
#) && echo "$ret" | grep -sq "bytes from" && {
fi fi
false false
} }
@ -184,7 +185,7 @@ _httping() {
ret=$(httping "${host}" \ ret=$(httping "${host}" \
-y "${deviceip}" \ -y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \ -t "$OMR_TRACKER_TIMEOUT" \
-c 1 2>&1 -c "$OMR_TRACKER_COUNT" 2>&1
) && echo "$ret" | grep -sq "1 ok" && { ) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
@ -196,7 +197,7 @@ _httping() {
ret=$(httping -l "${host}" \ ret=$(httping -l "${host}" \
-y "${deviceip}" \ -y "${deviceip}" \
-t "$OMR_TRACKER_TIMEOUT" \ -t "$OMR_TRACKER_TIMEOUT" \
-c 1 2>&1 -c "$OMR_TRACKER_COUNT" 2>&1
) && echo "$ret" | grep -sq "1 ok" && { ) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n') OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
@ -214,7 +215,7 @@ _dns() {
ret=$(dig @"${host}" \ ret=$(dig @"${host}" \
-b "${deviceip}" \ -b "${deviceip}" \
+time="$OMR_TRACKER_TIMEOUT" \ +time="$OMR_TRACKER_TIMEOUT" \
+tries=1 \ +tries="$OMR_TRACKER_COUNT" \
one.one.one.one one.one.one.one
) && echo "$ret" | grep -sq "1.1.1.1" && { ) && echo "$ret" | grep -sq "1.1.1.1" && {
OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}') OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}')

View file

@ -18,6 +18,7 @@ config defaults 'defaults'
list hosts6 '2001:4860:4860::8888' list hosts6 '2001:4860:4860::8888'
list hosts6 '2001:4860:4860::8844' list hosts6 '2001:4860:4860::8844'
option timeout '2' option timeout '2'
option count '2'
option tries '3' option tries '3'
option interval '2' option interval '2'
option interval_tries '1' option interval_tries '1'
@ -29,7 +30,6 @@ config defaults 'defaults'
config proxy 'proxy' config proxy 'proxy'
option enabled '1' option enabled '1'
list hosts '1.0.0.1'
list hosts '212.27.48.10' list hosts '212.27.48.10'
list hosts '198.27.92.1' list hosts '198.27.92.1'
list hosts '151.101.129.164' list hosts '151.101.129.164'

View file

@ -16,13 +16,14 @@
. /lib/functions/network.sh . /lib/functions/network.sh
_validate_section() { _validate_section() {
local tmp_hosts=$hosts tmp_hosts6=$hosts6 tmp_timeout=$timeout tmp_tries=$tries local tmp_hosts=$hosts tmp_hosts6=$hosts6 tmp_timeout=$timeout tmp_count=$count tmp_tries=$tries
local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test tmp_server_http_test=$server_http_test local tmp_interval=$interval tmp_interval_tries=$interval_tries tmp_options=$options tmp_type=$type tmp_enabled=$enabled tmp_wait_test=$wait_test tmp_server_http_test=$server_http_test
uci_validate_section omr-tracker "$1" "$2" \ uci_validate_section omr-tracker "$1" "$2" \
'hosts:list(host)' \ 'hosts:list(host)' \
'hosts6:list(host)' \ 'hosts6:list(host)' \
'timeout:uinteger' \ 'timeout:uinteger' \
'count:uinteger' \
'tries:uinteger' \ 'tries:uinteger' \
'interval:uinteger' \ 'interval:uinteger' \
'interval_tries:uinteger' \ 'interval_tries:uinteger' \
@ -35,6 +36,7 @@ _validate_section() {
[ -z "$hosts" ] && hosts=$tmp_hosts [ -z "$hosts" ] && hosts=$tmp_hosts
[ -z "$hosts6" ] && hosts6=$tmp_hosts6 [ -z "$hosts6" ] && hosts6=$tmp_hosts6
[ -z "$timeout" ] && timeout=$tmp_timeout [ -z "$timeout" ] && timeout=$tmp_timeout
[ -z "$count" ] && count=$tmp_count
[ -z "$tries" ] && tries=$tmp_tries [ -z "$tries" ] && tries=$tmp_tries
[ -z "$interval" ] && interval=$tmp_interval [ -z "$interval" ] && interval=$tmp_interval
[ -z "$interval_tries" ] && interval_tries=$tmp_interval_tries [ -z "$interval_tries" ] && interval_tries=$tmp_interval_tries
@ -50,7 +52,7 @@ _launch_tracker() {
loopback|lan*|if0*) return;; loopback|lan*|if0*) return;;
esac esac
[ -z "$1" ] && return [ -z "$1" ] && return
local hosts hosts6 timeout tries interval interval_tries options type enabled wait_test ipv6 proto server_http_test local hosts hosts6 timeout count tries interval interval_tries options type enabled wait_test ipv6 proto server_http_test
_validate_section "defaults" "defaults" _validate_section "defaults" "defaults"
_validate_section "interface" "$1" _validate_section "interface" "$1"
@ -75,8 +77,9 @@ _launch_tracker() {
[ -z "${hosts}" ] && [ "$type" != "none" ] && return [ -z "${hosts}" ] && [ "$type" != "none" ] && return
ifstatus=$(ifstatus "$1" | jsonfilter -q -e '@["up"]') ifstatus=$(ifstatus "$1" | jsonfilter -q -e '@["up"]')
ifdevice=$(ifstatus "$1" | jsonfilter -q -e '@["device"]') ifdevice=$(ifstatus "$1" | jsonfilter -q -e '@["device"]')
[ "${ifstatus}" = "false" ] && [ -z "${ifdevice}" ] && return #[ "${ifstatus}" = "false" ] && [ -z "${ifdevice}" ] && return
[ -z "${interval_tries}" ] && interval_tries=1 [ -z "${interval_tries}" ] && interval_tries=1
[ -z "${count}" ] && count=2
procd_open_instance procd_open_instance
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -84,6 +87,7 @@ _launch_tracker() {
procd_append_param env "OMR_TRACKER_HOSTS=$hosts" procd_append_param env "OMR_TRACKER_HOSTS=$hosts"
procd_append_param env "OMR_TRACKER_HOSTS6=$hosts6" procd_append_param env "OMR_TRACKER_HOSTS6=$hosts6"
procd_append_param env "OMR_TRACKER_TIMEOUT=$timeout" procd_append_param env "OMR_TRACKER_TIMEOUT=$timeout"
procd_append_param env "OMR_TRACKER_COUNT=$count"
procd_append_param env "OMR_TRACKER_TRIES=$tries" procd_append_param env "OMR_TRACKER_TRIES=$tries"
procd_append_param env "OMR_TRACKER_INTERVAL=$interval" procd_append_param env "OMR_TRACKER_INTERVAL=$interval"
procd_append_param env "OMR_TRACKER_INTERVAL_TRIES=$interval_tries" procd_append_param env "OMR_TRACKER_INTERVAL_TRIES=$interval_tries"

View file

@ -64,6 +64,12 @@ if [ "$(uci -q get omr-tracker.proxy.hosts | grep '176.103.130.130')" != "" ]; t
commit omr-tracker commit omr-tracker
EOF EOF
fi fi
if [ "$(uci -q get omr-tracker.proxy.hosts | grep '1.0.0.1')" != "" ]; then
uci -q batch <<-EOF >/dev/null
del_list omr-tracker.proxy.hosts='1.0.0.1'
commit omr-tracker
EOF
fi
if [ "$(uci -q get omr-tracker.proxy.hosts | grep '198.41.212.162')" = "" ]; then if [ "$(uci -q get omr-tracker.proxy.hosts | grep '198.41.212.162')" = "" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null