first commit
This commit is contained in:
55
inc/sensor-scripts/iperf3.sh
Normal file
55
inc/sensor-scripts/iperf3.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_NAME=$(basename ${BASH_SOURCE[0]})
|
||||
|
||||
if ! which jq >/dev/null; then
|
||||
logError "${SCRIPT_NAME}: Did not find jq in path!"
|
||||
return
|
||||
elif ! which iperf3 >/dev/null; then
|
||||
logError "${SCRIPT_NAME}: Did not find iperf3 in path!"
|
||||
return
|
||||
fi
|
||||
|
||||
# Usage: doIperfTest <target-host> [<time>] [<additional-iperf-args>]
|
||||
function doIperfTest {
|
||||
HOST="${1}"
|
||||
shift
|
||||
|
||||
TIME=10
|
||||
if ! [ "${1}" = "" ]; then
|
||||
TIME=${1}
|
||||
LOG_SUFFIX=" for ${TIME} seconds"
|
||||
shift
|
||||
fi
|
||||
|
||||
logScript "Doing IPerf3 test to ${HOST}${LOG_SUFFIX}"
|
||||
|
||||
OUT=$(iperf3 -c "${HOST}" -t ${TIME} -i0 -J ${@})
|
||||
|
||||
SUCCESS=$( [ "$(echo ${OUT} | jq -r .error)" = null ] && echo true || echo false )
|
||||
PROTO=$(echo ${OUT} | jq -r .start.test_start.protocol)
|
||||
REMOTE_HOST=$(echo ${OUT} | jq -r .start.connected[0].remote_host)
|
||||
REMOTE_PORT=$(echo ${OUT} | jq -r .start.connected[0].remote_port)
|
||||
|
||||
NUM_STREAMS=$(echo ${OUT} | jq -r .start.test_start.num_streams)
|
||||
REVERSE=$(echo ${OUT} | jq -r .start.test_start.reverse)
|
||||
SENT_SECONDS=$(echo ${OUT} | jq -r .end.sum_sent.seconds)
|
||||
SENT_BPS=$(echo ${OUT} | jq -r .end.sum_sent.bits_per_second)
|
||||
SENT_RETRANSMITS=$(echo ${OUT} | jq -r .end.sum_sent.retransmits)
|
||||
RECEIVED_SECONDS=$(echo ${OUT} | jq -r .end.sum_received.seconds)
|
||||
RECEIVED_BPS=$(echo ${OUT} | jq -r .end.sum_received.bits_per_second)
|
||||
|
||||
if ! [ "${SUCCESS}" = "true" ]; then
|
||||
NUM_STREAMS=0
|
||||
REVERSE=0
|
||||
SENT_SECONDS=0
|
||||
SENT_BPS=0
|
||||
SENT_RETRANSMITS=0
|
||||
RECEIVED_SECONDS=0
|
||||
RECEIVED_BPS=0
|
||||
fi
|
||||
|
||||
writeData \
|
||||
iperf3 \
|
||||
"sourceHost=$(hostname -f),targetHost=${HOST}" \
|
||||
"success=${SUCCESS},connected_host=\"${REMOTE_HOST}:${REMOTE_PORT}\",proto=\"${PROTO}\",num_streams=${NUM_STREAMS},reverse=${REVERSE},retransmits=${SENT_RETRANSMITS},sent_seconds=${SENT_SECONDS},sent_bps=${SENT_BPS},received_seconds=${RECEIVED_SECONDS},received_bps=${RECEIVED_BPS}"
|
||||
}
|
||||
37
inc/sensor-scripts/ping.sh
Normal file
37
inc/sensor-scripts/ping.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: doPingTest <target-host> [<count>]
|
||||
function doPingTest {
|
||||
HOST=${1}
|
||||
|
||||
logScript "Doing ping to ${HOST}"
|
||||
|
||||
COUNT=1
|
||||
[ "${2}" = "" ] || COUNT=${2}
|
||||
|
||||
ping "${HOST}" -W 10 -c ${COUNT} | {
|
||||
read -r HEADER
|
||||
RESOLVED_NAME=$(echo ${HEADER} | sed 's/.* (\(.*\)) .*/\1/')
|
||||
|
||||
while read -r PINGLINE; do
|
||||
if [[ "${PINGLINE}" == *" bytes from "* ]]; then
|
||||
SUCCESS=true
|
||||
BYTES=$(echo ${PINGLINE} | awk '{ print $1 }')
|
||||
TTL=$(echo ${PINGLINE} | sed 's/.*ttl=\([0-9]\+\) .*/\1/')
|
||||
LATENCY=$(echo ${PINGLINE} | sed 's/.*time=\([0-9\.]\+\) .*/\1/')
|
||||
elif [ "${PINGLINE}" = "" ]; then
|
||||
SUCCESS=false
|
||||
BYTES=0
|
||||
TTL=0
|
||||
LATENCY=-1
|
||||
else
|
||||
continue
|
||||
fi
|
||||
|
||||
writeData \
|
||||
ping \
|
||||
"sourceHost=$(hostname -f),targetHost=${HOST}" \
|
||||
"success=${SUCCESS},resolved=\"${RESOLVED_NAME}\",latency=${LATENCY},ttl=${TTL},bytes=${BYTES}"
|
||||
done
|
||||
}
|
||||
}
|
||||
26
inc/sensor-scripts/tcp-port.sh
Normal file
26
inc/sensor-scripts/tcp-port.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! which nc >/dev/null; then
|
||||
logError "${SCRIPT_NAME}: Did not find nc in path!"
|
||||
return
|
||||
fi
|
||||
|
||||
# Usage: doTcpPortTest <target-host> <target-port> [<timeout>]
|
||||
function doTcpPortTest {
|
||||
HOST=${1}
|
||||
PORT=${2}
|
||||
TIMEOUT=5
|
||||
[ "${3}" = "" ] || TIMEOUT=${3}
|
||||
|
||||
logScript "Doing TCP port test to ${HOST}:${PORT}"
|
||||
|
||||
SUCCESS=false
|
||||
if nc -z -w ${TIMEOUT} ${HOST} ${PORT}; then
|
||||
SUCCESS=true
|
||||
fi
|
||||
|
||||
writeData \
|
||||
tcp-port \
|
||||
"sourceHost=$(hostname -f),targetHost=${HOST},targetPort=${PORT}" \
|
||||
"open=${SUCCESS}"
|
||||
}
|
||||
Reference in New Issue
Block a user