-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcheck_internet_speed
69 lines (59 loc) · 2.25 KB
/
check_internet_speed
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Uses pyspeedtest or speedtest-cli to test internet speed and format for nagios
# Felipe Ferreira 08/2016
# Version 2.0 - allows use of two different tools now
downw=$1
downc=$2
upw=$3
upc=$4
## SOME OF THE SERVERS I USE
#id="3837" sp1.wind.it:8080 DESC="Rome Italia Wind "
#id="6512" speedtest.tecnoadsl.it:8080 DESC="Telecom Italia S.p.A. (Perugia, Italy) [23.00 km]"
#id="5470" speedtestpg1.telecomitalia.it:8080
#id="9636" speedtestfi1.telecomitalia.it:8080 DESC="Telecom Italia S.p.A. (Florence, Italy) [99.02 km]"
#id="3676" speedtest-rma.clouditalia.com:8080 DESC="Clouditalia S p A (Rome, Italy) [142.40 km]"
# There is a FULL list of servers here http://www.speedtest.net/speedtest-servers.php
#TIP: Too make speedtest-cli work without opening outbound to any I downloaded set to local web folder 2 xml files
# ://<MYSERVER>/speedtest-servers-static.xml
# ://centreon/c/speedtest-config.xml
###########EDIT HERE##############
SERVERID=3837
SERVER="sp1.wind.it"
TOUT=50 # only for speedtest-cli
RUNS=8 # only for pyspeedtest
TMP=".speedtest.$SERVER.$RANDOM"
if [ -z $4 ]; then
echo "UNOKNWN - Please pass all 4 paramateres $0 <download_warn> <download_crit> <upload_warn> <upload_crit>"
exit 3
fi
PWD=$(pwd)
PWD="/usr/lib/nagios/plugins"
SCRIPT="${PWD}/speedtest-cli"
if [ -f $SCRIPT ]; then
CMD="$SCRIPT --server $SERVERID --timeout $TOUT --simple > $TMP 2>&1"
elif [[ $(command -v pyspeedtest >/dev/null 2>&1) ]]; then
SCRIPT="pyspeedtest"
CMD="$SCRIPT -s $SERVER -r $RUNS > $TMP 2>&1"
else
echo "UNKONW - could not find requirements: speedtest-cli or pyspeedtest "
echo "Download speedtest-cli https://github.com/sivel/speedtest-cli"
echo "Download: pyspeedtest https://github.com/fopina/pyspeedtest"
exit 3
fi
#echo $CMD
R=$(eval $CMD)
P=$(grep Ping $TMP |awk '{ print $(NF -1) }')
D=$(grep Download $TMP |awk '{ print $(NF -1)}' |awk -F"." '{print $1}' )
U=$(grep Upload $TMP |awk '{ print $(NF -1) }' |awk -F"." '{print $1}' )
MSG="TestServer: $SERVER Ping $P ms Download $D Mbit/s Upload $U Mbit/s |Download=$D;Upload=$U"
rm -f $TMP
if [ $D -lt $downc ] || [ $U -lt $upc ]; then
echo "CRITICAL - $MSG"
exit 2
elif [ $D -lt $downw ] || [ $U -lt $upw ]; then
echo "WARNING - $MSG"
exit 1
else
echo "OK - $MSG"
exit 0
fi