Skip to content

Commit f7303b5

Browse files
committed
fix: resolve custom threshold dropdown validation error
- Client now uses 'auto-detect' placeholder when node can't be determined - Server handles node auto-detection by looking up VM/LXC in current state - Fixes 'Please select a VM/LXC from the dropdown first' error in v3.17.3 - Addresses issue #110
1 parent 7abe322 commit f7303b5

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

data/custom-thresholds.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
{}
1+
{
2+
"primary:103": {
3+
"endpointId": "primary",
4+
"nodeId": "auto-detect",
5+
"vmid": "103",
6+
"thresholds": {
7+
"disk": {
8+
"warning": 70,
9+
"critical": 80
10+
}
11+
},
12+
"enabled": true,
13+
"createdAt": "2025-06-01T19:50:34.784Z",
14+
"updatedAt": "2025-06-01T19:50:34.784Z"
15+
}
16+
}

server/thresholdRoutes.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function setupThresholdRoutes(app) {
5656
// Set custom thresholds for VM/LXC
5757
app.post('/api/thresholds/:endpointId/:nodeId/:vmid', async (req, res) => {
5858
try {
59-
const { endpointId, nodeId, vmid } = req.params;
59+
let { endpointId, nodeId, vmid } = req.params;
6060
const { thresholds } = req.body;
6161

6262
if (!thresholds) {
@@ -66,6 +66,25 @@ function setupThresholdRoutes(app) {
6666
});
6767
}
6868

69+
// Handle auto-detect node
70+
if (nodeId === 'auto-detect') {
71+
const state = require('./state');
72+
// Find the VM/LXC in the current state
73+
const allGuests = [...(state.vms || []), ...(state.containers || [])];
74+
const guest = allGuests.find(g =>
75+
g.endpointId === endpointId && g.id === vmid
76+
);
77+
78+
if (guest && guest.node) {
79+
nodeId = guest.node;
80+
console.log(`[ThresholdRoutes] Auto-detected node '${nodeId}' for ${endpointId}:${vmid}`);
81+
} else {
82+
// If we can't find the node, use a wildcard that will match any node
83+
nodeId = '*';
84+
console.log(`[ThresholdRoutes] Could not auto-detect node for ${endpointId}:${vmid}, using wildcard`);
85+
}
86+
}
87+
6988
if (!customThresholdManager.initialized) {
7089
await customThresholdManager.init();
7190
}
@@ -84,7 +103,7 @@ function setupThresholdRoutes(app) {
84103
// Update existing custom thresholds
85104
app.put('/api/thresholds/:endpointId/:nodeId/:vmid', async (req, res) => {
86105
try {
87-
const { endpointId, nodeId, vmid } = req.params;
106+
let { endpointId, nodeId, vmid } = req.params;
88107
const { thresholds } = req.body;
89108

90109
if (!thresholds) {
@@ -94,6 +113,25 @@ function setupThresholdRoutes(app) {
94113
});
95114
}
96115

116+
// Handle auto-detect node
117+
if (nodeId === 'auto-detect') {
118+
const state = require('./state');
119+
// Find the VM/LXC in the current state
120+
const allGuests = [...(state.vms || []), ...(state.containers || [])];
121+
const guest = allGuests.find(g =>
122+
g.endpointId === endpointId && g.id === vmid
123+
);
124+
125+
if (guest && guest.node) {
126+
nodeId = guest.node;
127+
console.log(`[ThresholdRoutes] Auto-detected node '${nodeId}' for ${endpointId}:${vmid}`);
128+
} else {
129+
// If we can't find the node, use a wildcard that will match any node
130+
nodeId = '*';
131+
console.log(`[ThresholdRoutes] Could not auto-detect node for ${endpointId}:${vmid}, using wildcard`);
132+
}
133+
}
134+
97135
if (!customThresholdManager.initialized) {
98136
await customThresholdManager.init();
99137
}

src/public/js/ui/settings.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,24 @@ PulseApp.ui.settings = (() => {
17121712

17131713
// Find the current node for this VM (for display purposes)
17141714
const selectedGuest = allGuests.find(g => g.endpointId === selectedEndpoint && g.id === selectedVmid);
1715-
nodeField.value = selectedGuest ? selectedGuest.node : '';
1715+
1716+
// If we can't find the guest or it doesn't have a node, use a placeholder
1717+
// The server will handle finding the actual node
1718+
if (selectedGuest && selectedGuest.node) {
1719+
nodeField.value = selectedGuest.node;
1720+
} else {
1721+
// Use a placeholder value that will pass validation
1722+
// The server can determine the actual node from endpointId and vmid
1723+
nodeField.value = 'auto-detect';
1724+
}
17161725

17171726
// Debug logging
17181727
console.log('[Settings] Guest selector changed:', {
17191728
selectedEndpoint,
17201729
selectedVmid,
17211730
selectedGuest,
1722-
nodeValue: selectedGuest ? selectedGuest.node : 'MISSING'
1731+
nodeValue: nodeField.value,
1732+
allGuestsCount: allGuests.length
17231733
});
17241734
} else {
17251735
endpointField.value = '';

0 commit comments

Comments
 (0)