From e6c15f620a86b34453bfdbdbfb29b07a589cdd3f Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Fri, 29 Aug 2025 10:58:23 +0000 Subject: [PATCH] feat: add version column to node tables - Shows PVE/PBS version in node summary tables - Helps quickly identify nodes needing updates - Extracts just version number from PVE (e.g. 9.0.5) - Also improved mock mode system for local development --- .gitignore | 3 + .../src/components/shared/PBSNodeTable.tsx | 14 +- .../src/components/shared/PVENodeTable.tsx | 10 ++ internal/monitoring/monitor.go | 10 +- scripts/toggle-mock-pure.sh | 143 +++++++++++------- 5 files changed, 119 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index c2ab80c7d..b184d2277 100644 --- a/.gitignore +++ b/.gitignore @@ -94,5 +94,8 @@ scripts/TEST_*.md mock.env internal/mock/ internal/monitoring/mock_integration.go +internal/monitoring/mock_stub.go scripts/mock-dev.sh +scripts/toggle-mock.sh +scripts/toggle-mock-pure.sh MOCK_MODE_GUIDE.md diff --git a/frontend-modern/src/components/shared/PBSNodeTable.tsx b/frontend-modern/src/components/shared/PBSNodeTable.tsx index 7eb9b3bfa..0539e7f2a 100644 --- a/frontend-modern/src/components/shared/PBSNodeTable.tsx +++ b/frontend-modern/src/components/shared/PBSNodeTable.tsx @@ -75,6 +75,9 @@ export const PBSNodeTable: Component = (props) => { Status + + Version + Datastores @@ -180,6 +183,13 @@ export const PBSNodeTable: Component = (props) => { {pbs.status} + + + + {pbs.version} + + + {pbs.datastores?.length || 0} @@ -235,7 +245,7 @@ export const PBSNodeTable: Component = (props) => { <> {/* Datastore row */} - +
@@ -286,7 +296,7 @@ export const PBSNodeTable: Component = (props) => { } }} > - +
= (props) => { Cluster + + Version + {(header) => ( @@ -195,6 +198,13 @@ export const PVENodeTable: Component = (props) => { {node.clusterName || '-'} + + + + {node.pveVersion.split('/')[1] || node.pveVersion} + + + {(count) => ( diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index d8ddf0dc8..24e0ac875 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -2116,18 +2116,12 @@ func (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, clie } } -// getMockState returns mock data when mock mode is enabled -func getMockState() *models.StateSnapshot { - // Mock support removed from production builds - return nil -} - // GetState returns the current state func (m *Monitor) GetState() models.StateSnapshot { // Check if mock mode is enabled if os.Getenv("PULSE_MOCK_MODE") == "true" { - // Import mock package and return mock data - if mockData := getMockState(); mockData != nil { + // Try to get mock data if compiled with mock support + if mockData := tryGetMockState(); mockData != nil { return *mockData } } diff --git a/scripts/toggle-mock-pure.sh b/scripts/toggle-mock-pure.sh index e4a78f635..065cfe572 100755 --- a/scripts/toggle-mock-pure.sh +++ b/scripts/toggle-mock-pure.sh @@ -1,64 +1,105 @@ #!/bin/bash -# Pure mock mode toggle - disables real nodes completely -# This is a workaround until we properly integrate mock mode to skip node initialization +# Pure mock mode toggle - completely disables real nodes when mock is enabled +# This ensures no mixing of real and mock data -RED='\033[0;31m' -GREEN='\033[0;32m' +MODE="${1:-status}" +MOCK_ENV="/opt/pulse/mock.env" +SERVICE_DIR="/etc/systemd/system/pulse-backend.service.d" +MOCK_CONF="$SERVICE_DIR/mock.conf" + +# Colors for output +GREEN='\033[1;32m' YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color +RESET='\033[0m' -NODES_FILE="/etc/pulse/nodes.enc" -NODES_BACKUP="/etc/pulse/nodes.enc.real" - -enable_pure_mock() { - echo -e "${YELLOW}Enabling PURE mock mode (no real nodes)...${NC}" - - # Backup real nodes if they exist - if [ -f "$NODES_FILE" ]; then - sudo mv "$NODES_FILE" "$NODES_BACKUP" - echo -e "${GREEN}Real nodes config backed up${NC}" - fi - - # Enable mock mode - /opt/pulse/scripts/toggle-mock.sh on - - echo -e "${GREEN}✓ Pure mock mode enabled!${NC}" - echo -e "${YELLOW}Real nodes are completely disabled${NC}" -} - -disable_pure_mock() { - echo -e "${YELLOW}Restoring real nodes...${NC}" - - # Restore real nodes - if [ -f "$NODES_BACKUP" ]; then - sudo mv "$NODES_BACKUP" "$NODES_FILE" - echo -e "${GREEN}Real nodes config restored${NC}" - fi - - # Disable mock mode - /opt/pulse/scripts/toggle-mock.sh off - - echo -e "${GREEN}✓ Back to real nodes!${NC}" -} - -case "$1" in +case "$MODE" in on) - enable_pure_mock + echo -e "${YELLOW}Enabling PURE mock mode (disabling all real nodes)...${RESET}" + + # Create the service override directory if it doesn't exist + sudo mkdir -p "$SERVICE_DIR" + + # Create override to set mock mode and disable real nodes + sudo tee "$MOCK_CONF" > /dev/null < "$MOCK_ENV" <<'EOF' +# Mock Mode Configuration +PULSE_MOCK_MODE=true +PULSE_MOCK_NODES=7 +PULSE_MOCK_VMS_PER_NODE=5 +PULSE_MOCK_LXCS_PER_NODE=8 +PULSE_MOCK_RANDOM_METRICS=true +PULSE_MOCK_STOPPED_PERCENT=20 +EOF + else + # Ensure mock mode is enabled in the file + sed -i 's/PULSE_MOCK_MODE=false/PULSE_MOCK_MODE=true/' "$MOCK_ENV" + fi + + # Build with mock support + echo -e "${YELLOW}Building Pulse with mock support...${RESET}" + cd /opt/pulse + go build -tags "mock" -o bin/pulse ./cmd/pulse + + # Reload and restart + sudo systemctl daemon-reload + sudo systemctl restart pulse-backend + + echo -e "${GREEN}✓ PURE mock mode enabled!${RESET}" + echo -e "Real nodes are completely disabled." + echo -e "Access Pulse at: ${GREEN}http://localhost:7655${RESET}" ;; + off) - disable_pure_mock + echo -e "${YELLOW}Disabling mock mode (restoring real nodes)...${RESET}" + + # Remove the mock override + sudo rm -f "$MOCK_CONF" + + # Update mock.env to disable mock mode + if [ -f "$MOCK_ENV" ]; then + sed -i 's/PULSE_MOCK_MODE=true/PULSE_MOCK_MODE=false/' "$MOCK_ENV" + fi + + # Build without mock support for production + echo -e "${YELLOW}Building Pulse for production...${RESET}" + cd /opt/pulse + go build -o bin/pulse ./cmd/pulse + + # Reload and restart + sudo systemctl daemon-reload + sudo systemctl restart pulse-backend + + echo -e "${GREEN}✓ Mock mode disabled!${RESET}" + echo -e "Real nodes are now active." ;; + + status) + if [ -f "$MOCK_CONF" ] && grep -q "PULSE_MOCK_MODE=true" "$MOCK_CONF" 2>/dev/null; then + echo -e "${GREEN}Mock mode: ENABLED (Pure mode - real nodes disabled)${RESET}" + if [ -f "$MOCK_ENV" ]; then + echo "Mock configuration:" + grep -E "PULSE_MOCK" "$MOCK_ENV" | grep -v "^#" + fi + else + echo -e "${YELLOW}Mock mode: DISABLED (using real nodes)${RESET}" + fi + ;; + *) - echo "Pure Mock Mode Toggle" - echo "=====================" + echo "Usage: $0 {on|off|status}" echo "" - echo "This completely disables real nodes for pure mock testing" - echo "" - echo "Usage: $0 {on|off}" - echo "" - echo " on - Enable pure mock mode (no real nodes)" - echo " off - Restore real nodes" + echo " on - Enable PURE mock mode (no real nodes)" + echo " off - Disable mock mode (use real nodes)" + echo " status - Show current mode" + exit 1 ;; esac \ No newline at end of file