From 9ea63072cc6bed219feabf8ea80e479054adaaab Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 21 Aug 2025 21:47:33 +0200 Subject: [PATCH 1/3] hddtemp2: check if disk is a valid device --- agent-local/hddtemp2 | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/agent-local/hddtemp2 b/agent-local/hddtemp2 index cb2f0eefe..de04457d0 100644 --- a/agent-local/hddtemp2 +++ b/agent-local/hddtemp2 @@ -3,7 +3,7 @@ # Name: hddtemp2 # Author: Jason Cheng (www.jason.tools) # Date: 2025-02-17 -# Version: 1.1 +# Version: 1.2 # Purpose: This script replaces the obsolete hddtemp tool for librenms agent to monitor disk temperatures # License: Free Software @@ -26,25 +26,28 @@ if [ "${smartctl}" != "" ]; then for disk in $disks; do # Exclude non-physical disks like RBD (RADOS Block Device) if [[ ! "$disk" =~ rbd ]]; then - # Get disk model first - model=$(${smartctl} -i $disk | grep 'Device Model' | cut -d':' -f2 | sed 's/^\s*//g') - - # Try different temperature attributes in order of preference - # First try Airflow_Temperature_Cel - temp_info=$(${smartctl} -A $disk | grep 'Airflow_Temperature_Cel' | awk '{print $10}') + # Check if the disk is a valid device + if ${smartctl} -i "$disk" > /dev/null 2>&1; then + # Get disk model first + model=$(${smartctl} -i $disk | grep 'Device Model' | cut -d':' -f2 | sed 's/^\s*//g') - # If not found, try Temperature_Celsius - if [ -z "$temp_info" ]; then - temp_info=$(${smartctl} -A $disk | grep 'Temperature_Celsius' | awk '{print $10}') - fi + # Try different temperature attributes in order of preference + # First try Airflow_Temperature_Cel + temp_info=$(${smartctl} -A $disk | grep 'Airflow_Temperature_Cel' | awk '{print $10}') - # If still not found, try Drive_Temperature - if [ -z "$temp_info" ]; then - temp_info=$(${smartctl} -A $disk | grep 'Drive_Temperature' | awk '{print $4}') - fi + # If not found, try Temperature_Celsius + if [ -z "$temp_info" ]; then + temp_info=$(${smartctl} -A $disk | grep 'Temperature_Celsius' | awk '{print $10}') + fi - # Format output regardless of which temperature was found - output="${output}|${disk}|${model}|${temp_info}|C|" + # If still not found, try Drive_Temperature + if [ -z "$temp_info" ]; then + temp_info=$(${smartctl} -A $disk | grep 'Drive_Temperature' | awk '{print $4}') + fi + + # Format output regardless of which temperature was found + output="${output}|${disk}|${model}|${temp_info}|C|" + fi fi done # Clean output, keep only printable characters From a5765f7e2fb2029b3f10aaf6fb431e5d959ffd00 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 21 Aug 2025 21:49:06 +0200 Subject: [PATCH 2/3] hddtemp2: fix model name for smartctl --- agent-local/hddtemp2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent-local/hddtemp2 b/agent-local/hddtemp2 index de04457d0..6e00ba3c8 100644 --- a/agent-local/hddtemp2 +++ b/agent-local/hddtemp2 @@ -29,7 +29,7 @@ if [ "${smartctl}" != "" ]; then # Check if the disk is a valid device if ${smartctl} -i "$disk" > /dev/null 2>&1; then # Get disk model first - model=$(${smartctl} -i $disk | grep 'Device Model' | cut -d':' -f2 | sed 's/^\s*//g') + model=$(${smartctl} -i $disk | grep 'Device Model' | cut -d':' -f2 | tr -d '[:space:]$') # Try different temperature attributes in order of preference # First try Airflow_Temperature_Cel From f91158e07215360565a3ccb22f5402cf837b837c Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 22 Aug 2025 18:12:02 +0200 Subject: [PATCH 3/3] hddtemp2: fix perms --- agent-local/hddtemp2 | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 agent-local/hddtemp2 diff --git a/agent-local/hddtemp2 b/agent-local/hddtemp2 old mode 100644 new mode 100755