@@ -56,7 +56,7 @@ function setupThresholdRoutes(app) {
56
56
// Set custom thresholds for VM/LXC
57
57
app . post ( '/api/thresholds/:endpointId/:nodeId/:vmid' , async ( req , res ) => {
58
58
try {
59
- const { endpointId, nodeId, vmid } = req . params ;
59
+ let { endpointId, nodeId, vmid } = req . params ;
60
60
const { thresholds } = req . body ;
61
61
62
62
if ( ! thresholds ) {
@@ -66,6 +66,25 @@ function setupThresholdRoutes(app) {
66
66
} ) ;
67
67
}
68
68
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
+
69
88
if ( ! customThresholdManager . initialized ) {
70
89
await customThresholdManager . init ( ) ;
71
90
}
@@ -84,7 +103,7 @@ function setupThresholdRoutes(app) {
84
103
// Update existing custom thresholds
85
104
app . put ( '/api/thresholds/:endpointId/:nodeId/:vmid' , async ( req , res ) => {
86
105
try {
87
- const { endpointId, nodeId, vmid } = req . params ;
106
+ let { endpointId, nodeId, vmid } = req . params ;
88
107
const { thresholds } = req . body ;
89
108
90
109
if ( ! thresholds ) {
@@ -94,6 +113,25 @@ function setupThresholdRoutes(app) {
94
113
} ) ;
95
114
}
96
115
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
+
97
135
if ( ! customThresholdManager . initialized ) {
98
136
await customThresholdManager . init ( ) ;
99
137
}
0 commit comments