-
-
Save mturch/bfedf142b4f052db0997e01184bf20ee to your computer and use it in GitHub Desktop.
Log speedtest results on Firewalla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# v 0.20 | |
BASEDIR=$(dirname $0) | |
IFTTTKEY="$(cat $BASEDIR/IFTTT.data | grep IFTTTKEY| cut -f2 -d "=" )" | |
EVENT="FWspeedtest" | |
# set to false if you don't want to log speed to a google Spreadsheet | |
GoogleSpreadsheet=true | |
# Create a webhook with IFTT where: | |
# event = speedtest | |
# set a Speedtest server ID. Set to blank to let speedtest choose for you. example below | |
# SERVER="" | |
SERVER="-s 41818" | |
PARAMS="-f json -p no" | |
# set to false if you don't want to log speed on your firewalla | |
LOCALLOG=true | |
# Give your WAN ports names. Leave blank if not used. No spaces in names. | |
WAN1="Sail" | |
# WAN2="LTE" | |
eth1=eth0 | |
eth2=eth1 | |
log=/data/logs/logspeed.log | |
installer="/home/pi/.firewalla/config/post_main.d/install_speedtest.sh" | |
if [ ! -f "/data/speedtest" ]; then | |
echo -e "\n\nspeedcheck not instaleld!\n" | |
if [ -f "$installer" ]; then | |
echo Running installer | |
read -p "Do you want to continue? (y|n) ? " -n 1 -r | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
echo "Can't continue without speedtest." | |
exit | |
else | |
echo "Running installer..." | |
/home/pi/.firewalla/config/post_main.d/install_speedtest.sh | |
fi | |
else | |
echo -e "Download https://gist.github.com/mbierman/9ac6a35622ee5a0c631ed6f6ad74b722,\nrun it to install speedtest and try again." | |
exit | |
fi | |
else | |
echo speedtest installed! | |
fi | |
now=$(date +"%D %H:%M" | sed -e "s|/|-|g") | |
speedapp=/data/speedtest | |
if [ -n "$WAN1" ]; then | |
echo "Testing $WAN1..." | |
WAN1P=$($speedapp $SERVER -I $eth1 $PARAMS) | |
WAN1L=$(echo $WAN1P | jq '.ping.latency') | |
WAN1J=$(echo $WAN1P | jq '.ping.jitter') | |
WAN1D=$(echo $WAN1P | jq '.download.bandwidth'/125000) | |
WAN1U=$(echo $WAN1P | jq '.upload.bandwidth'/125000) | |
WAN1URL=$(echo $WAN1P | jq -r '.result.url') | |
WAN1P="$now,${WAN1L},${WAN1J},${WAN1D},${WAN1U},${WAN1URL}" | |
echo -e "$WAN1 Down: $WAN1D $WAN1 Up: $WAN1U\n\n" | |
else | |
echo "No WAN1" | |
fi | |
if [ -n "$WAN2" ]; then | |
echo "Testing $WAN2..." | |
WAN2P=$($speedapp $SERVER -I $eth2 $PARAMS) | |
WAN2L=$(echo $WAN2P | jq '.ping.latency') | |
WAN2J=$(echo $WAN2P | jq '.ping.jitter') | |
WAN2D=$(echo $WAN2P | jq '.download.bandwidth'/125000) | |
WAN2U=$(echo $WAN2P | jq '.upload.bandwidth'/125000) | |
WAN2URL=$(echo $WAN2P | jq -r '.result.url') | |
WAN2P="$now,${WAN2L},${WAN2J},${WAN2D},${WAN2U},${WAN2URL}" | |
echo -e "$WAN2 Down: $WAN2D $WAN2 Up: $WAN2U\n\n" | |
else | |
echo "No WAN2" | |
fi | |
if [ -n "$IFTTTKEY" ] && [ "$GoogleSpreadsheet" = "true" ]; then | |
if [ -n "$WAN1" ]; then | |
curl -X POST -H "Content-Type: application/json" -d "{\"value1\": \"$now|||$WAN1|||$WAN1U|||$WAN1D|||$WAN1URL|||$WAN1L|||$WAN1J\"}" https://maker.ifttt.com/trigger/$EVENT/with/key/$IFTTTKEY | |
else | |
echo -e "\n\nSkipping WAN1 report..." | |
fi | |
if [ -n "$WAN2" ]; then | |
sleep 10s | |
curl -X POST -H "Content-Type: application/json" -d "{\"value1\": \"$now|||$WAN2|||$WAN2U|||$WAN2D|||$WAN2URL|||$WAN2L|||$WAN2J\"}" https://maker.ifttt.com/trigger/$EVENT/with/key/$IFTTTKEY | |
else | |
echo -e "\n\nSkipping WAN2 report" | |
fi | |
else | |
echo "IFTTT disabled" | |
fi | |
if [ "$LOCALLOG" = "true" ]; then | |
# Create a log file if it doesn't exist and add a header | |
HEADER='\"date\",\"ISP\",\"server name\",\"server id\",\"latency\",jitter\",\"packet loss\",\"download\",\"upload\",\"download bytes\",\"upload bytes\",\"share url\"' | |
if [ ! -f "$log" ]; then | |
echo -e "\n\nno logfile!\n" | |
echo $HEADER > $log | |
fi | |
echo $WAN1P | tee -a $log | |
echo $WAN2P | tee -a $log | |
exit | |
echo $HEADER > $log.$$ | |
tail -n 2000 $log >> $log.$$ | |
mv $log.$$ $log | |
else | |
echo "Local log disabled" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment