fix check_coturn

This commit is contained in:
Cyberes 2023-06-06 23:32:00 -06:00
parent 337ee609d3
commit 73651ba0fc
1 changed files with 10 additions and 5 deletions

View File

@ -12,8 +12,10 @@ SEND_DROPPED_WARN=3
SEND_DROPPED_CRIT=5
AVG_RTT_WARN=100
AVG_RTT_CRIT=200
REQUESTED_RELAY_ADDR="false"
while getopts "s:S:u:r:p:w:c:W:C:R:T:" opt; do
while getopts "s:S:u:r:p:w:c:W:C:R:T:x:" opt; do
case $opt in
s)
SERVER_ADDRESS="$OPTARG"
@ -45,8 +47,11 @@ while getopts "s:S:u:r:p:w:c:W:C:R:T:" opt; do
T)
AVG_RTT_CRIT="$OPTARG"
;;
x)
REQUESTED_RELAY_ADDR="-x $OPTARG"
;;
*)
echo "Usage: $0 -s SERVER_ADDRESS -S SECRET -r REALM [-p PORT] [-P PROTOCOL] [-t TIMEOUT] [-w LOST_PACKETS_WARN] [-c LOST_PACKETS_CRIT] [-W SEND_DROPPED_WARN] [-C SEND_DROPPED_CRIT] [-R AVG_RTT_WARN] [-T AVG_RTT_CRIT]"
echo "Usage: $0 -s SERVER_ADDRESS -S SECRET -r REALM [-p PORT] [-P PROTOCOL] [-t TIMEOUT] [-w LOST_PACKETS_WARN] [-c LOST_PACKETS_CRIT] [-W SEND_DROPPED_WARN] [-C SEND_DROPPED_CRIT] [-R AVG_RTT_WARN] [-T AVG_RTT_CRIT] [-x REQUESTED_RELAY_ADDR]"
exit -1
;;
esac
@ -54,12 +59,12 @@ done
# Check if required options are set
if [[ -z "$SERVER_ADDRESS" || -z "$SECRET" || -z "$REALM" ]]; then
echo "Usage: $0 -s SERVER_ADDRESS -S SECRET -r REALM [-p PORT] [-P PROTOCOL] [-t TIMEOUT] [-w LOST_PACKETS_WARN] [-c LOST_PACKETS_CRIT] [-W SEND_DROPPED_WARN] [-C SEND_DROPPED_CRIT] [-R AVG_RTT_WARN] [-T AVG_RTT_CRIT]"
echo "Usage: $0 -s SERVER_ADDRESS -S SECRET -r REALM [-p PORT] [-P PROTOCOL] [-t TIMEOUT] [-w LOST_PACKETS_WARN] [-c LOST_PACKETS_CRIT] [-W SEND_DROPPED_WARN] [-C SEND_DROPPED_CRIT] [-R AVG_RTT_WARN] [-T AVG_RTT_CRIT] [-x REQUESTED_RELAY_ADDR]"
exit -1
fi
if ! command -v turnutils_uclient &>/dev/null; then
echo "UNKNOWN - turnutils_uclient not found! Please install coturn. Make sure to run \`service coturn stop; systemctl disable coturn\`"
echo "UNKNOWN - turnutils_uclient not found! Please install coturn. Make sure to run \`sudo apt install coturn; sudo service coturn stop; sudo systemctl disable coturn\`"
exit -1
fi
@ -78,7 +83,7 @@ if [[ -z "$PEER_ADDRESS" ]]; then
exit -1
fi
TURNUTILS_OUTPUT=$(turnutils_uclient -s -W "$SECRET" -r "$REALM" -p "$PORT" -e "$PEER_ADDRESS" -B -y "$SERVER_ADDRESS" 2>&1)
TURNUTILS_OUTPUT=$(turnutils_uclient "$SERVER_ADDRESS" -s -W "$SECRET" -r "$REALM" -p "$PORT" -e "$PEER_ADDRESS" $REQUESTED_RELAY_ADDR -B -y 2>&1)
if [ $? -eq 0 ]; then
LOST_PACKETS=$(echo "$TURNUTILS_OUTPUT" | grep -m1 "Total lost packets" | awk -F'[(%)]' '{print $2"%"}' | tr -d '%' | cut -d. -f1)