Fix sensors JSON output to formatted version - only comtible with proxmox 9 and onwards(#106)

This commit is contained in:
Meliox 2025-08-06 14:06:44 +02:00 committed by GitHub
parent fa629cfdd5
commit 4c78930373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -33,6 +33,9 @@ DEBUG_SAVE_FILENAME="sensorsdata.json"
##################### DO NOT EDIT BELOW ####################### ##################### DO NOT EDIT BELOW #######################
# Only to be used to debug on other systems. Save the "sensor -j" output into a json file. # 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. # 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_REMOTE=false
DEBUG_JSON_FILE="/tmp/sensordata.json" 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." warn "Remote debugging is used. Sensor readings from dump file $DEBUG_JSON_FILE will be used."
sensorsOutput=$(cat $DEBUG_JSON_FILE) sensorsOutput=$(cat $DEBUG_JSON_FILE)
else else
sensorsOutput=$(sensors -j) sensorsOutput=$(sensors -j 2>/dev/null | python3 -m json.tool)
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -320,7 +323,7 @@ function install_mod {
else else
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :| # WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j") #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 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" 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\"." 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)") local choiceContinue=$(ask "Do you wish to continue? (y/n)")
case "$choiceContinue" in case "$choiceContinue" in
[yY]) [yY])
sensors -j >"$filepath" sensors -j 2>/dev/null | python3 -m json.tool >"$filepath"
msgb "Sensors data saved in $filepath." msgb "Sensors data saved in $filepath."
;; ;;
*) *)

View File

@ -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). 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 ## 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) ![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. 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.