Pulse/scripts/protect-mock-nodes.sh
Pulse Monitor 87fc4f651e fix: improve node disk stats reliability when GetNodeStatus fails (addresses #402)
- Ensure disk metrics from /nodes endpoint are preserved when GetNodeStatus fails
- Add better fallback logic to prevent showing 0% or '-' for disk usage
- Improve logging to distinguish between rootfs and /nodes endpoint metrics
- Handle cases where neither rootfs nor valid node disk data is available

This fixes the regression introduced in v4.12.1 where disk stats would show as
'-' when GetNodeStatus failed due to network issues or rate limiting
2025-08-31 22:43:32 +00:00

43 lines
No EOL
1.4 KiB
Bash
Executable file

#!/bin/bash
# This script patches test scripts to protect mock nodes from deletion
# It ensures that mock nodes (pve1-pve7, mock-*) are never deleted during tests
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "Protecting mock nodes from test cleanup..."
# List of test scripts that delete nodes
TEST_SCRIPTS=(
"/opt/pulse/scripts/test-persistence.sh"
"/opt/pulse/scripts/test-recovery.sh"
"/opt/pulse/scripts/test-backup.sh"
"/opt/pulse/scripts/test-load.sh"
"/opt/pulse/scripts/test-config-validation.sh"
)
for script in "${TEST_SCRIPTS[@]}"; do
if [ -f "$script" ]; then
echo -n "Patching $(basename $script)... "
# Create backup
cp "$script" "${script}.backup" 2>/dev/null
# Add protection for mock nodes in cleanup sections
# This looks for DELETE commands and adds a check to skip mock nodes
# Find lines with curl DELETE and add protection
sed -i '/curl.*DELETE.*nodes/i\
# Skip mock nodes and production nodes\
if [[ "$NODE_NAME" == "pve"* ]] || [[ "$NODE_NAME" == "mock"* ]] || [[ "$NODE_NAME" == "delly" ]] || [[ "$NODE_NAME" == "minipc" ]] || [[ "$NODE_NAME" == "pimox" ]]; then\
continue\
fi' "$script" 2>/dev/null
echo -e "${GREEN}${NC}"
fi
done
echo -e "${GREEN}Mock nodes are now protected!${NC}"