From 556fc2179c3205b95392cac4feeaaee1c6d6cd0c Mon Sep 17 00:00:00 2001 From: jonas Date: Sat, 1 Apr 2023 12:29:11 +0200 Subject: [PATCH] added working speedtest sensor --- inc/sensor-scripts/speedtest.sh | 37 ++++++++++++++++++++++++++++++--- sensors.d/speedtest.sh | 3 +++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 sensors.d/speedtest.sh diff --git a/inc/sensor-scripts/speedtest.sh b/inc/sensor-scripts/speedtest.sh index 5865935..425f167 100644 --- a/inc/sensor-scripts/speedtest.sh +++ b/inc/sensor-scripts/speedtest.sh @@ -16,10 +16,41 @@ function doSpeedtest { logScript "Doing internet speedtest${INTERFACE_TEXT}${SERVER_ID_TEXT}" - if ! OUT=$(speedtest -f json); then + if ! OUT=$(speedtest -f json 2>/dev/null); then logError "Speedtest failed" - logError "${OUT}" + echo "${OUT}" | logError + + SUCCESS=false + JITTER=-1 + LATENCY=-1 + PING_LOW=-1 + PING_HIGH=-1 + DOWNLOAD_BANDWIDTH=0 + UPLOAD_BANDWIDTH=0 + PACKET_LOSS=-1 + ISP="" + INTERFACE="" + EXTERNAL_IP="" + SERVER_ID="" + RESULT_ID="" else - echo + SUCCESS=true + JITTER=$(echo "${OUT}" | jq .ping.jitter) + LATENCY=$(echo "${OUT}" | jq .ping.latency) + PING_LOW=$(echo "${OUT}" | jq .ping.low) + PING_HIGH=$(echo "${OUT}" | jq .ping.high) + DOWNLOAD_BANDWIDTH=$(echo "${OUT}" | jq .download.bandwidth) + UPLOAD_BANDWIDTH=$(echo "${OUT}" | jq .upload.bandwidth) + PACKET_LOSS=$(echo "${OUT}" | jq .packetLoss) + ISP="$(echo "${OUT}" | jq .isp)" + INTERFACE=$(echo "${OUT}" | jq .interface.name) + EXTERNAL_IP=$(echo "${OUT}" | jq .interface.externalIp) + SERVER_ID=$(echo "${OUT}" | jq .server.id) + RESULT_ID=$(echo "${OUT}" | jq .result.id) fi + + writeData \ + speedtest \ + "sourceHost=$(hostname -f)" \ + "success=${SUCCESS},jitter=${JITTER},latency=${LATENCY},ping_low=${PING_LOW},ping_high=${PING_HIGH},download_bandwidth=${DOWNLOAD_BANDWIDTH},upload_bandwidth=${UPLOAD_BANDWIDTH},packetloss=${PACKET_LOSS},isp=${ISP},interface=${INTERFACE},external_ip=${EXTERNAL_IP},server_id=${SERVER_ID},result_id=${RESULT_ID}" } \ No newline at end of file diff --git a/sensors.d/speedtest.sh b/sensors.d/speedtest.sh new file mode 100644 index 0000000..7750859 --- /dev/null +++ b/sensors.d/speedtest.sh @@ -0,0 +1,3 @@ +INTERVAL=300 + +doSpeedtest \ No newline at end of file