-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw_iperf_test.sh
53 lines (48 loc) · 2.54 KB
/
raw_iperf_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
source /root/speedtest_config
# create results directory
if [[ ! -d /root/speedtest/results ]]; then
mkdir -p /root/speedtest/results
fi
# test functions
iperf_receive () {
download_results=$(date +%Y-%m-%d-%H-%M-%S)-iperf3-$1-download.json
echo -e "Download (TCP):\niperf3 -4 -V -R -t 5 -O 3 -l 1460 -c $1 -p $2\n" > /root/speedtest/results/$download_results
iperf3 -4 -V -R -t 5 -O 3 -l 1460 -c $1 -p $2 >> /root/speedtest/results/$download_results
}
iperf_send () {
upload_results=$(date +%Y-%m-%d-%H-%M-%S)-iperf3-$1-upload.json
echo -e "Upload (TCP):\niperf3 -4 -V -t 5 -O 3 -l 1460 -c $1 -p $2\n" > /root/speedtest/results/$upload_results
iperf3 -4 -V -t 5 -O 3 -l 1460 -c $1 -p $2 >> /root/speedtest/results/$upload_results
}
iperf_packet_loss () {
packet_loss_results=$(date +%Y-%m-%d-%H-%M-%S)-iperf3-$1-packet_loss.json
echo -e "Packet Loss (UDP):\niperf3 -4 -V -R -t 10 -O 3 -u -b 80M -l 1440 -c $1 -p $2\n" > /root/speedtest/results/$packet_loss_results
iperf3 -4 -V -R -t 10 -O 3 -u -b 80M -l 1460 -c $1 -p $2 >> /root/speedtest/results/$packet_loss_results
}
for hostname in $*; do
if [[ $hostname == emoncms.jakezp.co.za ]]; then
port=5201
else
# elif [[ $hostname == iperf.atomic.ac ]]; then
port=3334
fi
nc -vz $hostname $port -w 1 >/dev/null 2>&1
if [[ ! $? == 0 ]]; then
echo -e "iperf host - $hostname is down. skipping test..."
curl -s "${url}/sendMessage?chat_id=${chat_id}" --data-urlencode "text=iperf host - $hostname is down. skipping test..."
echo -e " "
curl -s -F "token=$pushtoken" -F "user=$pushuser" -F "title=iperf server is down" -F "message=iperf server - $hostname is down. Investigate..." https://api.pushover.net/1/messages.json >/dev/null 2>&1
exit 1
else
iperf_receive $hostname $port
iperf_send $hostname $port
iperf_packet_loss $hostname $port
curl -s "${url}/sendMessage?chat_id=${chat_id}" --data-urlencode "text=$(cat /root/speedtest/results/$download_results)"
curl -s "${url}/sendMessage?chat_id=${chat_id}" --data-urlencode "text=$(cat /root/speedtest/results/$upload_results)"
curl -s "${url}/sendMessage?chat_id=${chat_id}" --data-urlencode "text=$(cat /root/speedtest/results/$packet_loss_results)"
curl -F chat_id="${chat_id}" -F document=@"/root/speedtest/results/$download_results" "${url}/sendDocument"
curl -F chat_id="${chat_id}" -F document=@"/root/speedtest/results/$upload_results" "${url}/sendDocument"
curl -F chat_id="${chat_id}" -F document=@"/root/speedtest/results/$packet_loss_results" "${url}/sendDocument"
fi
done