diff --git a/speeder.py b/speeder.py index fbf1836..c69537f 100644 --- a/speeder.py +++ b/speeder.py @@ -54,7 +54,7 @@ exit(1) else: # Create list from comma separated string of server IDs - SPEEDER_SPEEDTEST_SERVER_ID = SPEEDER_SPEEDTEST_SERVER_ID.split(",") + SPEEDER_SPEEDTEST_SERVER_IDs = SPEEDER_SPEEDTEST_SERVER_ID.split(",") # Connect to InfluxDB logger.debug( @@ -67,7 +67,7 @@ ) as client: # Run the speedtest using the librespeed/speedtest-cli on an interval while True: - for server_id in SPEEDER_SPEEDTEST_SERVER_ID: + for server_id in SPEEDER_SPEEDTEST_SERVER_IDs: logger.debug(f"Running speedtest for server ID: {server_id}.") result = subprocess.run( [ @@ -84,15 +84,18 @@ # Check if the speedtest failed if result.returncode != 0: # CLI errors go to stdout - logger.debug( + logger.error( f"Speedtest for server ID: {server_id} failed with exit code: {result.returncode}.\nError: {result.stdout}" ) else: logger.debug(f"Speedtest for server ID: {server_id} succeeded.") try: json_result = json.loads(result.stdout) + # Check if the JSON result is empty + if not json_result: + raise json.decoder.JSONDecodeError("JSON result is empty.", json_result, 0) except json.decoder.JSONDecodeError as err: - logger.debug( + logger.error( f"Failed to parse JSON results for server ID: {server_id}.\nError: {err}" ) continue