diff --git a/check_iperf3.sh b/check_iperf3.sh index 899d176..4037de5 100755 --- a/check_iperf3.sh +++ b/check_iperf3.sh @@ -19,6 +19,11 @@ if ! command -v iperf3 &>/dev/null; then exit 3 fi +if ! command -v jq &>/dev/null; then + echo "UNKNOWN - jq is not installed" + exit 3 +fi + if [[ $# -eq 0 ]]; then print_help fi @@ -81,7 +86,8 @@ if ! echo "$RESULT" | jq -e '.end.sum.bits_per_second' >/dev/null; then exit 3 fi -SPEED_RAW=$(echo "$RESULT" | jq '.end.sum.bits_per_second / 1000000') +STREAM_RESULT=$(echo "$RESULT" | jq '.end.streams[] | select(.udp.sender == (!0)) | .udp.bits_per_second') +SPEED_RAW=$(echo "$STREAM_RESULT" | jq 'if length > 0 then . / 1000000 else 0 end') SPEED=$(printf "%.0f" "$SPEED_RAW") if (($(echo "$SPEED < $CRITICAL" | bc -l))); then