From 4c78930373f367c52d924d213999fbcc9c74b20f Mon Sep 17 00:00:00 2001 From: Meliox <5264368+Meliox@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:06:44 +0200 Subject: [PATCH] Fix sensors JSON output to formatted version - only comtible with proxmox 9 and onwards(#106) --- pve-mod-gui-sensors.sh | 9 ++++++--- readme.md | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index 28ca75a..395460d 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -33,6 +33,9 @@ DEBUG_SAVE_FILENAME="sensorsdata.json" ##################### DO NOT EDIT BELOW ####################### # Only to be used to debug on other systems. Save the "sensor -j" output into a json file. # Information will be loaded for script configuration and presented in Proxmox. + +# DEV NOTE: lm-sensors version >3.6.0 breakes properly formatted JSON output using 'sensors -j'. This implements a workaround using uses a python3 for formatting + DEBUG_REMOTE=false DEBUG_JSON_FILE="/tmp/sensordata.json" @@ -105,7 +108,7 @@ function configure { warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used." sensorsOutput=$(cat $DEBUG_JSON_FILE) else - sensorsOutput=$(sensors -j) + sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool) fi if [ $? -ne 0 ]; then @@ -320,7 +323,7 @@ function install_mod { else # WTF: sensors -f used for Fahrenheit breaks the fan speeds :| #local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j") - sensorsCmd="sensors -j" + sensorsCmd="sensors -j 2>/dev/null | python3 -m json.tool" fi sed -i '/my \$dinfo = df('\''\/'\'', 1);/i\'$'\t''$res->{sensorsOutput} = `'"$sensorsCmd"'`;\n\t# sanitize JSON output\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+):\\s(.+)/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/ERROR:.+\\s(\\w+)!/\\"$1\\": 0.000,/g;\n\t$res->{sensorsOutput} =~ s/,(.*[.\\n]*.+})/$1/g;\n' "$NODES_PM_FILE" msg "Sensors' output added to \"$NODES_PM_FILE\"." @@ -995,7 +998,7 @@ function save_sensors_data { local choiceContinue=$(ask "Do you wish to continue? (y/n)") case "$choiceContinue" in [yY]) - sensors -j >"$filepath" + sensors -j 2>/dev/null | python3 -m json.tool >"$filepath" msgb "Sensors data saved in $filepath." ;; *) diff --git a/readme.md b/readme.md index 6bb1d22..3d91889 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ A small collection of scripts and mods for Proxmox Virtual Environment (PVE) If you find this helpful, a small donation is appreciated, [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K8XPMSEBERH3W). ## Node sensor readings view -(Tested compatibility: 7.x - 8.3.5) +(Tested compatibility: 9.x. Using older version (7.x-8.x), use git version from Apr 6th 2025) ![Promxox temp mod](https://github.com/Meliox/PVE-mods/blob/main/pve-mod-sensors.png?raw=true) This bash script installs a modification to the Proxmox Virtual Environment (PVE) web user interface (UI) to display sensor readings in a flexible and readable manner. Supported are CPU, NVMe/HDD/SSD temperatures (Celsius/Fahrenheit), fan speeds, ram temperatures, mixed CPU's core nodes setups, motherboard information or system information.