mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Ping via interface instead of IP only
This commit is contained in:
parent
403488eb53
commit
61bc8cf0b7
2 changed files with 10 additions and 10 deletions
|
@ -985,13 +985,13 @@ function interfaces_status()
|
||||||
|
|
||||||
local latency = ""
|
local latency = ""
|
||||||
local server_ping = ""
|
local server_ping = ""
|
||||||
if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" then
|
if connectivity ~= "ERROR" and ifname ~= "" and gateway ~= "" and gw_ping ~= "DOWN" and ifname ~= nil and mArray.openmptcprouter["service_addr"] ~= "" and ipaddr ~= "" then
|
||||||
local serverip = mArray.openmptcprouter["service_addr"]
|
local serverip = mArray.openmptcprouter["service_addr"]
|
||||||
if serverip == "127.0.0.1" then
|
if serverip == "127.0.0.1" then
|
||||||
serverip = mArray.openmptcprouter["wan_addr"]
|
serverip = mArray.openmptcprouter["wan_addr"]
|
||||||
end
|
end
|
||||||
if serverip ~= "" and uci:get("openmptcprouter", "settings", "disableserverping") ~= "1" then
|
if serverip ~= "" and uci:get("openmptcprouter", "settings", "disableserverping") ~= "1" then
|
||||||
local server_ping_test = sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. serverip)
|
local server_ping_test = sys.exec("ping -B -w 1 -c 1 -I " .. ifname .. " " .. serverip)
|
||||||
local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'"))
|
local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'"))
|
||||||
if server_ping_result ~= "" then
|
if server_ping_result ~= "" then
|
||||||
server_ping = "DOWN"
|
server_ping = "DOWN"
|
||||||
|
|
|
@ -77,9 +77,9 @@ _post_tracking() {
|
||||||
|
|
||||||
_ping_server() {
|
_ping_server() {
|
||||||
local serverip=$(uci -q get openmptcprouter.$1.ip)
|
local serverip=$(uci -q get openmptcprouter.$1.ip)
|
||||||
local deviceip=$2
|
local device=$2
|
||||||
if [ -n "$serverip" ] && [ -n "$deviceip" ]; then
|
if [ -n "$serverip" ] && [ -n "$device" ]; then
|
||||||
_ping $serverip $deviceip "yes"
|
_ping $serverip $device "yes"
|
||||||
statusp=$?
|
statusp=$?
|
||||||
if $(exit $statusp); then
|
if $(exit $statusp); then
|
||||||
serverip_ping=true
|
serverip_ping=true
|
||||||
|
@ -91,9 +91,9 @@ _ping_server() {
|
||||||
|
|
||||||
_ping() {
|
_ping() {
|
||||||
local host=$1
|
local host=$1
|
||||||
local deviceip=$2
|
local device=$2
|
||||||
local localip=$3
|
local localip=$3
|
||||||
ret=$(ping -I "${deviceip}" \
|
ret=$(ping -B -I "${device}" \
|
||||||
-w "$OMR_TRACKER_TIMEOUT" \
|
-w "$OMR_TRACKER_TIMEOUT" \
|
||||||
-c 1 \
|
-c 1 \
|
||||||
-q \
|
-q \
|
||||||
|
@ -200,7 +200,7 @@ while true; do
|
||||||
tries="$OMR_TRACKER_TRIES"
|
tries="$OMR_TRACKER_TRIES"
|
||||||
# loop until tries attempts have been reached
|
# loop until tries attempts have been reached
|
||||||
while [ "$tries" -gt 0 ]; do
|
while [ "$tries" -gt 0 ]; do
|
||||||
_ping "$OMR_TRACKER_DEVICE_GATEWAY" "$OMR_TRACKER_DEVICE_IP" "no"
|
_ping "$OMR_TRACKER_DEVICE_GATEWAY" "$OMR_TRACKER_DEVICE" "no"
|
||||||
status=$?
|
status=$?
|
||||||
if $(exit $status) && [ "$OMR_TRACKER_TYPE" = "none" ]; then
|
if $(exit $status) && [ "$OMR_TRACKER_TYPE" = "none" ]; then
|
||||||
OMR_TRACKER_STATUS_MSG=""
|
OMR_TRACKER_STATUS_MSG=""
|
||||||
|
@ -213,7 +213,7 @@ while true; do
|
||||||
serverip_ping=false
|
serverip_ping=false
|
||||||
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
|
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
|
||||||
config_load openmptcprouter
|
config_load openmptcprouter
|
||||||
config_foreach _ping_server server $OMR_TRACKER_DEVICE_IP
|
config_foreach _ping_server server $OMR_TRACKER_DEVICE
|
||||||
fi
|
fi
|
||||||
if [ "$serverip_ping" = false ]; then
|
if [ "$serverip_ping" = false ]; then
|
||||||
# Check if route is not used
|
# Check if route is not used
|
||||||
|
@ -225,7 +225,7 @@ while true; do
|
||||||
_restart
|
_restart
|
||||||
done
|
done
|
||||||
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
|
if [ "$OMR_TRACKER_TYPE" = "ping" ]; then
|
||||||
_ping "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE_IP" "yes"
|
_ping "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE" "yes"
|
||||||
statusb=$?
|
statusb=$?
|
||||||
elif [ "$OMR_TRACKER_TYPE" = "httping" ]; then
|
elif [ "$OMR_TRACKER_TYPE" = "httping" ]; then
|
||||||
_httping "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE_IP" "yes"
|
_httping "$OMR_TRACKER_HOST" "$OMR_TRACKER_DEVICE_IP" "yes"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue