Added new speedtest script for Linux and updated Linux README.md file
This commit is contained in:
		
							parent
							
								
									e679c9499c
								
							
						
					
					
						commit
						923a3e2ef1
					
				| @ -1,18 +1,20 @@ | ||||
| # Speedtest_logger | ||||
| 
 | ||||
| A basic script that uses Speedtest-cli and logs the result to a csv file. | ||||
| 
 | ||||
| Within this folder there is 2 different versions of the speedtest script. | ||||
| A basic script that uses Speedtest-cli and/or iperf3 and logs the result to a csv file, Discord server or InfluDB. | ||||
| 
 | ||||
| 
 | ||||
| ## speedtest-cli | ||||
| This script uses the speedtest-cli test and requires the following dependencies. | ||||
| #### Dependencies | ||||
| ## Dependencies | ||||
| 
 | ||||
| ### speedtest-cli | ||||
| If you want to use speedtest-cli to test, the following dependencies will be required. | ||||
| 
 | ||||
| 1) Speedtest CLI: https://www.speedtest.net/apps/cli | ||||
| 
 | ||||
| 
 | ||||
| ## iperf3 | ||||
| This script uses the iperf3 software and required a iperf3 server ip to be used to test. This version requires the following dependencies. | ||||
| #### Dependencies | ||||
| ### iperf3 | ||||
| If you want to use iperf3 to test a, iperf3 server ip will be needed, as well as the following dependencies on the system that will run this script. | ||||
| 
 | ||||
| 1) iperf3: https://iperf.fr/iperf-download.php | ||||
| 2) jq (lightweight and flexible command-line JSON processor): https://github.com/jqlang/jq | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -1 +0,0 @@ | ||||
| Date,ISP,IP,Download,Upload | ||||
| 
 | 
| @ -1,128 +0,0 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| # Settings | ||||
| # Set WAN Number | ||||
| WAN=SET_NUMBER | ||||
| 
 | ||||
| # Do you want the script to log to a CSV file? Set log variable to 1 for yes, 0 for no | ||||
| log=SET_NUMBER | ||||
| 
 | ||||
| # Set the path to the log file | ||||
| LOG_FILE="./speedtest.csv" | ||||
|    | ||||
| # Do you want the script to output to a Discord webhook? Set discord variable to 1 for yes, 0 for no | ||||
| discord=SET_NUMBER | ||||
| 
 | ||||
| # Set your Discord webhook URL | ||||
| WEBHOOK_URL="https://DISCORD_WEBHOOK_URL" | ||||
| 
 | ||||
| # Set the iPerf3 server IP that you wantr to use | ||||
| IPERF3_SERVER_IP=SERVER.IP.ADDRESS.HERE | ||||
| 
 | ||||
| # The script that will run | ||||
| # Get IP info | ||||
| INFO=$(curl -s https://ipv4.am.i.mullvad.net/json | python -m json.tool) | ||||
| 
 | ||||
| # Reported IP | ||||
| IP=$(echo "$INFO" | grep -oE '"ip":\s*"[^"]+"' | grep -oE '[0-9.]+') | ||||
| 
 | ||||
| # Reported ISP | ||||
| ORG=$(echo "$INFO" | grep -oP '(?<="organization": ")[^"]+') | ||||
| 
 | ||||
| # Run iperf3 upload and parse the output | ||||
| IPERF_UP=$(iperf3 -R -c "$IPERF3_SERVER_IP" -J) | ||||
| 
 | ||||
| # Check if the iperf3 output is empty or contains errors | ||||
| if [ -z "$IPERF_UP" ] || [[ "$IPERF_UP" == *"error"* ]]; then | ||||
|   echo "Iperf3 test failed: $IPERF_UP" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Run iperf3 and parse the output | ||||
| IPERF_DOWN=$(iperf3 -c "$IPERF3_SERVER_IP" -J) | ||||
| 
 | ||||
| # Check if the iperf3 download output is empty or contains errors | ||||
| if [ -z "$IPERF_DOWN" ] || [[ "$IPERF_DOWN" == *"error"* ]]; then | ||||
|   echo "Iperf3 test failed: $IPERF_DOWN" | ||||
|   exit 1 | ||||
| fi | ||||
| # Extract download and upload speeds from iperf3 output | ||||
| DOWNLOAD=$(echo "$IPERF_UP" | jq -r '.end.sum_received.bits_per_second') | ||||
| UPLOAD=$(echo "$IPERF_DOWN" | jq -r '.end.sum_sent.bits_per_second') | ||||
| 
 | ||||
| # Convert the download and upload speeds to Mbps | ||||
| DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") | ||||
| UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") | ||||
| 
 | ||||
| # Check if the required fields are missing or invalid | ||||
| if [ -z "$DOWNLOAD_Mbps" ] || [ -z "$UPLOAD_Mbps" ]; then | ||||
|   echo "Missing or invalid iperf3 fields: DOWNLOAD=$DOWNLOAD_Mbps, UPLOAD=$UPLOAD_Mbps" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| if [ "$log" -eq 1 ]; then | ||||
|   echo "Log Variable is set to 1. Writing to log." | ||||
| 
 | ||||
|   # Append the result to the log file | ||||
|   echo "$(date +"%Y-%m-%d %H:%M:%S"),$IPERF3_SERVER_IP,$ORG,$IP,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$log" -eq 0 ]; then | ||||
|   echo "Log Variable is set to 0. Skipping log to file" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "Discord Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| if [ "$discord" -eq 1 ]; then | ||||
|   echo "Discord Variable is set to 1. Sending to Discord" | ||||
| 
 | ||||
|   # Prepare the payload for the Discord webhook | ||||
|   curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <<EOF | ||||
| { | ||||
|   "content": null, | ||||
|   "embeds": [ | ||||
|     { | ||||
|       "title": "Iperf3 Result - WAN $WAN", | ||||
|       "color": 5814783, | ||||
|       "fields": [ | ||||
|         { | ||||
|           "name": "Date and Time of Test:", | ||||
|           "value": "$(date +'%Y-%m-%d %H:%M:%S')" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Iperf3 Server Used:", | ||||
|           "value": "$IPERF3_SERVER_IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Tested ISP:", | ||||
|           "value": "$ORG" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Tested IP:", | ||||
|           "value": "$IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Download Test Result:", | ||||
|           "value": "$DOWNLOAD_Mbps mbps" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Upload Test Result:", | ||||
|           "value": "$UPLOAD_Mbps mbps" | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ], | ||||
|   "attachments": [] | ||||
| } | ||||
| EOF | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$discord" -eq 0 ]; then | ||||
|   echo "Discord Variable is set to 0. Skipping send to Discord" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "Variable is not set to a valid value." | ||||
| fi | ||||
| @ -1 +0,0 @@ | ||||
| Date,ISP,IP,Download,Upload | ||||
| 
 | 
| @ -1,117 +0,0 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| # Set WAN Number | ||||
| WAN="WAN NUMBER" | ||||
| 
 | ||||
| # Do you want the script to log to a CSV file? Set log variable to 1 for yes, 0 for no | ||||
| log=SET_NUMBER | ||||
| 
 | ||||
| # Set the path to the log file | ||||
| LOG_FILE="PATH TO CSV" | ||||
|    | ||||
| # Do you want the script to output to a Discord webhook? Set discord variable to 1 for yes, 0 for no | ||||
| discord=SET_NUMBER | ||||
| 
 | ||||
| # Set your Discord webhook URL | ||||
| WEBHOOK_URL="DISCORD WEBHOOK URL" | ||||
| 
 | ||||
| # Get IP info | ||||
| INFO=$(curl -s https://ipv4.am.i.mullvad.net/json | python -m json.tool) | ||||
| 
 | ||||
| # Reported IP | ||||
| IP=$(echo "$INFO" | grep -oE '"ip":\s*"[^"]+"' | grep -oE '[0-9.]+') | ||||
| 
 | ||||
| # Reported ISP | ||||
| ORG=$(echo "$INFO" | grep -oE '"organization":\s*"[^"]+"' | grep -oE '"[^"]+"' | tr -d '"') | ||||
| 
 | ||||
| # Run the speedtest and parse the output | ||||
| SPEEDTEST=$(speedtest-cli --csv) | ||||
| 
 | ||||
| # Check if the output is empty or contains errors | ||||
| if [ -z "$SPEEDTEST" ] || [[ "$SPEEDTEST" == *"ERROR"* ]]; then | ||||
|   echo "Speedtest failed: $SPEEDTEST" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| PING=$(echo "$SPEEDTEST" | awk -F',' '{print $6}') | ||||
| DOWNLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $7}') | ||||
| UPLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $8}') | ||||
| 
 | ||||
| # Check if the required fields are missing or invalid | ||||
| if [ -z "$PING" ] || [ -z "$DOWNLOAD" ] || [ -z "$UPLOAD" ]; then | ||||
|   echo "Missing or invalid speedtest fields: PING=$PING, DOWNLOAD=$DOWNLOAD, UPLOAD=$UPLOAD" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Convert the download and upload speeds to Mbps | ||||
| DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") | ||||
| UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") | ||||
| 
 | ||||
| if [ "$log" -eq 1 ]; then | ||||
|   echo "Variable is set to 1. Running command A." | ||||
| 
 | ||||
|   # Append the result to the log file | ||||
|   echo "$(date +"%Y-%m-%d %H:%M:%S"),$ORG,$IP,$PING,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$log" -eq 0 ]; then | ||||
|   echo "Skipping log to file" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| if [ "$discord" -eq 1 ]; then | ||||
|   echo "Variable is set to 1." | ||||
| 
 | ||||
|   # Prepare the payload for the Discord webhook | ||||
| curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <<EOF | ||||
| { | ||||
|   "content": null, | ||||
|   "embeds": [ | ||||
|     { | ||||
|       "title": "Speedtest Result - WAN $WAN", | ||||
|       "color": 5814783, | ||||
|       "fields": [ | ||||
|         { | ||||
|           "name": "Time:", | ||||
|           "value": "$(date +'%Y-%m-%d %H:%M:%S')" | ||||
|         }, | ||||
|         { | ||||
|           "name": "ISP:", | ||||
|           "value": "$ORG" | ||||
|         }, | ||||
|         { | ||||
|           "name": "IP:", | ||||
|           "value": "$IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Ping:", | ||||
|           "value": "$PING ms" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Download:", | ||||
|           "value": "$DOWNLOAD_Mbps mbps" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Upload:", | ||||
|           "value": "$UPLOAD_Mbps mbps" | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ], | ||||
|   "attachments": [] | ||||
| } | ||||
| EOF | ||||
| 
 | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$discord" -eq 0 ]; then | ||||
|   echo "Skipping send to Discord" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
							
								
								
									
										306
									
								
								Linux/speedtest.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										306
									
								
								Linux/speedtest.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,306 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| # Settings | ||||
| # # --------------WAN Number-------------- | ||||
| # Set WAN Number. This is usefull if you are testing multiple connections and having | ||||
| # them log to the same location | ||||
| WAN="SET WAN NUMBER" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------Log File Settings-------------- | ||||
| # Do you want the script to log to a CSV file? Set log variable to 1 for yes, 0 for no | ||||
| # If you set 0 for no, you dont have to fill in LOG_FILE setting | ||||
| log=1 | ||||
| # Set the path to the log file | ||||
| LOG_FILE="./speedtest.csv" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------Speedtest-cli Settings-------------- | ||||
| # Do you want to use Speedtest-cli? Set log variable to 1 for yes, 0 for no | ||||
| SPEEDTESTCLI="SET TO 0 or 1" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------Iperf3 Settings-------------- | ||||
| # Do you want to use Iperf3? Set log variable to 1 for yes, 0 for no | ||||
| # If you set 0 for no, you dont have to fill in the IPERF3_SERVER_IP setting | ||||
| IPERF3="SET TO 0 or 1" | ||||
| # Set the iPerf3 server IP or Hostname that you want to use | ||||
| IPERF3_SERVER_IP="IPERF3.SERVER.IPor.HOSTNAME" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------InflixDB Settings-------------- | ||||
| # Do you want the script to output to a inflix Database? Set INFLUX variable to 1 for yes, 0 for no | ||||
| # If you set 0 for no, you dont have to fill in the INFLUXDB_NAME or INFLUXDB_HOST settings | ||||
| INFLUX="SET TO 0 or 1" | ||||
| # Set Inflix DB Name | ||||
| INFLUXDB_NAME="SET_DB_NAME" | ||||
| #Set Influx DB Hostname or IP | ||||
| INFLUXDB_HOST="SET_HOSTNAME_OR_IP" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------DISCORD Settings-------------- | ||||
| # Do you want the script to output to a DISCORD webhook? Set DISCORD variable to 1 for yes, 0 for no | ||||
| # If you set 0 for no, you dont have to fill in the WEBHOOK_URL setting | ||||
| DISCORD="SET TO 0 or 1" | ||||
| # Set your DISCORD webhook URL | ||||
| WEBHOOK_URL="DISCORD_WEBHOOK_URL" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------SpeedTest Script----------------- | ||||
| 
 | ||||
| # # --------------Get Current IP Info-------------- | ||||
| # Get IP info | ||||
| INFO=$(curl -s https://ipv4.am.i.mullvad.net/json | python -m json.tool) | ||||
| # Get Reported IP | ||||
| IP=$(echo "$INFO" | grep -oE '"ip":\s*"[^"]+"' | grep -oE '[0-9.]+') | ||||
| # Get Reported ISP | ||||
| ORG=$(echo "$INFO" | grep -oP '(?<="organization": ")[^"]+') | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------IPERF3 Test Script-------------- | ||||
| # Do you want to use Iperf3? | ||||
| if [ "$IPERF3" -eq 1 ]; then | ||||
|   echo "IPERF3 Variable is set to 1. Running IPERF3 test" | ||||
| 
 | ||||
| # Run iperf3 upload and parse the output | ||||
| IPERF_UP=$(iperf3 -R -c "$IPERF3_SERVER_IP" -J) | ||||
| 
 | ||||
| # Check if the iperf3 output is empty or contains errors | ||||
| if [ -z "$IPERF_UP" ] || [[ "$IPERF_UP" == *"error"* ]]; then | ||||
|   echo "Iperf3 test failed: $IPERF_UP" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Run iperf3 and parse the output | ||||
| IPERF_DOWN=$(iperf3 -c "$IPERF3_SERVER_IP" -J) | ||||
| 
 | ||||
| # Check if the iperf3 download output is empty or contains errors | ||||
| if [ -z "$IPERF_DOWN" ] || [[ "$IPERF_DOWN" == *"error"* ]]; then | ||||
|   echo "Iperf3 test failed: $IPERF_DOWN" | ||||
|   exit 1 | ||||
| fi | ||||
| # Extract download and upload speeds from iperf3 output | ||||
| DOWNLOAD=$(echo "$IPERF_UP" | jq -r '.end.sum_received.bits_per_second') | ||||
| UPLOAD=$(echo "$IPERF_DOWN" | jq -r '.end.sum_sent.bits_per_second') | ||||
| 
 | ||||
| # Convert the download and upload speeds to Mbps | ||||
| DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") | ||||
| UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") | ||||
| 
 | ||||
| # Check if the required fields are missing or invalid | ||||
| if [ -z "$DOWNLOAD_Mbps" ] || [ -z "$UPLOAD_Mbps" ]; then | ||||
|   echo "Missing or invalid iperf3 fields: DOWNLOAD=$DOWNLOAD_Mbps, UPLOAD=$UPLOAD_Mbps" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| if [ "$log" -eq 1 ]; then | ||||
|   echo "Log Variable is set to 1. Writing to log." | ||||
| 
 | ||||
|   # Append the result to the log file | ||||
|   echo "$(date +"%Y-%m-%d %H:%M:%S"),iperf3,$ORG,$IP,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$log" -eq 0 ]; then | ||||
|   echo "Log Variable is set to 0. Skipping log to file" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "DISCORD Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| # Do you want the script to output to a DISCORD webhook? | ||||
| if [ "$DISCORD" -eq 1 ]; then | ||||
|   echo "DISCORD Variable is set to 1. Sending to DISCORD" | ||||
| 
 | ||||
|   # Prepare the payload for the DISCORD webhook | ||||
|   curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <<EOF | ||||
| { | ||||
|   "content": null, | ||||
|   "embeds": [ | ||||
|     { | ||||
|       "title": "Iperf3 Result - WAN $WAN", | ||||
|       "color": 5814783, | ||||
|       "fields": [ | ||||
|         { | ||||
|           "name": "Date and Time of Test:", | ||||
|           "value": "$(date +'%Y-%m-%d %H:%M:%S')" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Iperf3 Server Used:", | ||||
|           "value": "$IPERF3_SERVER_IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "ISP Tested:", | ||||
|           "value": "$ORG" | ||||
|         }, | ||||
|         { | ||||
|           "name": "IP Tested:", | ||||
|           "value": "$IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Download Test Result:", | ||||
|           "value": "$DOWNLOAD_Mbps mbps" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Upload Test Result:", | ||||
|           "value": "$UPLOAD_Mbps mbps" | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ], | ||||
|   "attachments": [] | ||||
| } | ||||
| EOF | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$DISCORD" -eq 0 ]; then | ||||
|   echo "DISCORD Variable is set to 0. Skipping send to DISCORD" | ||||
|    | ||||
| # Variable is not set to 1 or 0 | ||||
|     else | ||||
|          echo "DISCORD Variable is not set to a valid value." | ||||
|   fi | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # Do you want the script to output to a INFLUX DB? | ||||
| if [ "$INFLUX" -eq 1 ]; then | ||||
|   echo "INFLUX Variable is set to 1." | ||||
| 
 | ||||
| # Send Data to DB | ||||
| influx --database='INFLUXDB_NAME' --host='INFLUXDB_HOST' --execute="INSERT 'INFLUXDB_NAME',wan=$WAN,test_type=,iperf3,isp=$ORG,ip=$IP download=$DOWNLOAD_Mbps,upload=$UPLOAD_Mbps" | ||||
| 
 | ||||
| # Check if INFLUX is set to 0 | ||||
| elif [ "$INFLUX" -eq 0 ]; then | ||||
|   echo "Skipping send to INFLUX" | ||||
| 
 | ||||
| # Variable for INFLUX is not set to 1 or 0 | ||||
|     else | ||||
|         echo "Variable for INFLUX is not set to a valid value." | ||||
|     fi | ||||
| fi | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # # --------------SPEEDTEST-CLI Test Script-------------- | ||||
| # Do you want to use Speedtest-cli? | ||||
| if [ "$SPEEDTESTCLI" -eq 1 ]; then | ||||
|   echo "SPEEDTESTCLI Variable is set to 1. Running SPEEDTEST-CLI test" | ||||
|    | ||||
|    | ||||
| # Run the speedtest and parse the output | ||||
| SPEEDTEST=$(speedtest-cli --csv) | ||||
| 
 | ||||
| # Check if the output is empty or contains errors | ||||
| if [ -z "$SPEEDTEST" ] || [[ "$SPEEDTEST" == *"ERROR"* ]]; then | ||||
|   echo "Speedtest failed: $SPEEDTEST" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| PING=$(echo "$SPEEDTEST" | awk -F',' '{print $6}') | ||||
| DOWNLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $7}') | ||||
| UPLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $8}') | ||||
| 
 | ||||
| # Check if the required fields are missing or invalid | ||||
| if [ -z "$PING" ] || [ -z "$DOWNLOAD" ] || [ -z "$UPLOAD" ]; then | ||||
|   echo "Missing or invalid speedtest fields: PING=$PING, DOWNLOAD=$DOWNLOAD, UPLOAD=$UPLOAD" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Convert the download and upload speeds to Mbps | ||||
| DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") | ||||
| UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") | ||||
| 
 | ||||
| if [ "$log" -eq 1 ]; then | ||||
|   echo "Variable is set to 1. Running command A." | ||||
| 
 | ||||
|   # Append the result to the log file | ||||
|   echo "$(date +"%Y-%m-%d %H:%M:%S"),Speedtest.net,$ORG,$IP,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$log" -eq 0 ]; then | ||||
|   echo "Skipping log to file" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "Log to File Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| if [ "$DISCORD" -eq 1 ]; then | ||||
|   echo "DISCORD Variable is set to 1." | ||||
| 
 | ||||
| # Prepare the payload for the Discord webhook | ||||
| curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <<EOF | ||||
| { | ||||
|   "content": null, | ||||
|   "embeds": [ | ||||
|     { | ||||
|       "title": "Speedtest.net Result - WAN $WAN", | ||||
|       "color": 5814783, | ||||
|       "fields": [ | ||||
|         { | ||||
|           "name": "Date and Time of Test:", | ||||
|           "value": "$(date +'%Y-%m-%d %H:%M:%S')" | ||||
|         }, | ||||
|         { | ||||
|           "name": "ISP Tested:", | ||||
|           "value": "$ORG" | ||||
|         }, | ||||
|         { | ||||
|           "name": "IP Tested:", | ||||
|           "value": "$IP" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Ping:", | ||||
|           "value": "$PING ms" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Download Test Result:", | ||||
|           "value": "$DOWNLOAD_Mbps mbps" | ||||
|         }, | ||||
|         { | ||||
|           "name": "Upload Test Result:", | ||||
|           "value": "$UPLOAD_Mbps mbps" | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ], | ||||
|   "attachments": [] | ||||
| } | ||||
| EOF | ||||
| 
 | ||||
| 
 | ||||
| # Check if the variable is set to 0 | ||||
| elif [ "$DISCORD" -eq 0 ]; then | ||||
|   echo "Skipping send to Discord" | ||||
| 
 | ||||
| # Variable is not set to 1 or 0 | ||||
| else | ||||
|   echo "DIRCORD Variable is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| # Do you want the script to output to a INFLUX DB? | ||||
| if [ "$INFLUX" -eq 1 ]; then | ||||
|   echo "INFLUX Variable is set to 1." | ||||
| 
 | ||||
| # Send Data to DB | ||||
| influx --database='INFLUXDB_NAME' --host='INFLUXDB_HOST' --execute="INSERT 'INFLUXDB_NAME',wan=$WAN,test_type=,speedtest.net,isp=$ORG,ip=$IP download=$DOWNLOAD_Mbps,upload=$UPLOAD_Mbps" | ||||
| 
 | ||||
| # Check if INFLUX is set to 0 | ||||
| elif [ "$INFLUX" -eq 0 ]; then | ||||
|   echo "Skipping send to INFLUX" | ||||
| 
 | ||||
| # Variable for INFLUX is not set to 1 or 0 | ||||
| else | ||||
|   echo "Variable for INFLUX is not set to a valid value." | ||||
| fi | ||||
| 
 | ||||
| 
 | ||||
| fi | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user