Add "remote" debug option of json file (#50)

This commit is contained in:
Meliox 2024-06-16 11:42:31 +02:00 committed by GitHub
parent d13d02ab36
commit 3490d3a07e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,7 +30,11 @@ nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
DEBUG_SAVE_PATH="$SCRIPT_CWD" DEBUG_SAVE_PATH="$SCRIPT_CWD"
DEBUG_SAVE_FILENAME="sensorsdata.json" 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.
DEBUG_REMOTE=false
JSON_FILE="/tmp/sensordata.json"
# Helper functions # Helper functions
function msg { function msg {
@ -89,7 +93,15 @@ function install_packages {
function configure { function configure {
sensorsDetected=false sensorsDetected=false
local sensorsOutput=$(sensors -j) local sensorsOutput
if [ $DEBUG_REMOTE = true ]; then
warn "Remote debugging is used. Sensor readings from dump file $JSON_FILE will be used."
sensorsOutput=$(cat $JSON_FILE)
else
sensorsOutput=$(sensors -j)
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n" err "Sensor output error.\n\nCommand output:\n${sensorsOutput}\n\nExiting...\n"
fi fi
@ -249,9 +261,14 @@ function install_mod {
enableSensors=true enableSensors=true
if [[ "$enableSensors" == true ]]; then if [[ "$enableSensors" == true ]]; then
local sensorsCmd
if [ $DEBUG_REMOTE = true ]; then
sensorsCmd="cat \"$JSON_FILE\""
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")
local sensorsCmd="sensors -j" sensorsCmd="sensors -j"
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' "$nodespm" 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' "$nodespm"
msg "Sensors' output added to \"$nodespm\"." msg "Sensors' output added to \"$nodespm\"."
fi fi