add remote debug option of json file
This commit is contained in:
parent
f00005385e
commit
efc87581c8
@ -26,7 +26,11 @@ BACKUP_DIR="$SCRIPT_CWD/backup"
|
|||||||
pvemanagerlibjs="/usr/share/pve-manager/js/pvemanagerlib.js"
|
pvemanagerlibjs="/usr/share/pve-manager/js/pvemanagerlib.js"
|
||||||
nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
|
nodespm="/usr/share/perl5/PVE/API2/Nodes.pm"
|
||||||
|
|
||||||
###############################################
|
##################### DO NOT EDIT BELOW #######################
|
||||||
|
# Only to be used to debug on other systems. Add the "sensor -j" into the 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 {
|
||||||
@ -85,7 +89,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. Information from $JSON_FILE is loaded."
|
||||||
|
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
|
||||||
@ -219,10 +231,14 @@ function install_mod {
|
|||||||
cp "$nodespm" "$BACKUP_DIR/Nodes.pm.$timestamp"
|
cp "$nodespm" "$BACKUP_DIR/Nodes.pm.$timestamp"
|
||||||
msg "Backup of \"$nodespm\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
|
msg "Backup of \"$nodespm\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
|
||||||
|
|
||||||
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
|
if [[ $DEBUG_REMOTE == "TRUE" ]]; then
|
||||||
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j")
|
sed -i '/my \$dinfo = df('\''\/'\'', 1);/i\'$'\t''my $json_file_path = '"'$JSON_FILE'"';\n\topen my $fh, '\''<'\'', $json_file_path or die "Cannot open $json_file_path: $!";\n\tmy $json_text = do { local $/; <$fh> };\n\tclose $fh;\n\t$res->{sensorsOutput} = $json_text;\n' "$nodespm"
|
||||||
local sensorsCmd="sensors -j"
|
else
|
||||||
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"
|
# WTF: sensors -f used for Fahrenheit breaks the fan speeds :|
|
||||||
|
#local sensorsCmd=$([[ "$TEMP_UNIT" = "F" ]] && echo "sensors -j -f" || echo "sensors -j")
|
||||||
|
local sensorsCmd="sensors -j"
|
||||||
|
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"
|
||||||
|
fi
|
||||||
msg "Sensors' output added to \"$nodespm\"."
|
msg "Sensors' output added to \"$nodespm\"."
|
||||||
else
|
else
|
||||||
warn "Sensors' output already integrated in in \"$nodespm\"."
|
warn "Sensors' output already integrated in in \"$nodespm\"."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user