fix(sensor-proxy): relax pvecm status parsing to support decimal node IDs

Fixes an issue where pvecm status output using decimal node IDs (e.g. '1' instead of '0x1') caused node discovery to fail. Added test case for this format.
This commit is contained in:
courtmanr@gmail.com 2025-11-23 08:21:58 +00:00
parent dedce8796b
commit 53836ea9b0
2 changed files with 10 additions and 12 deletions

View file

@ -740,24 +740,14 @@ func parseClusterNodes(output string) ([]string, error) {
var nodes []string
lines := strings.Split(output, "\n")
for _, line := range lines {
// Look for lines with hex ID and IP address
if !strings.Contains(line, "0x") {
continue
}
fields := strings.Fields(line)
// Need at least 3 fields: hex_id votes ip [optional:(local)]
if len(fields) < 3 {
// Need at least 2 fields to be a valid node line (id + ip/name)
if len(fields) < 2 {
continue
}
// Iterate through fields to find the IP address
for _, field := range fields {
// Skip hex ID
if strings.HasPrefix(field, "0x") {
continue
}
// Check if it's a valid IP
if ip := net.ParseIP(field); ip != nil {
nodes = append(nodes, field)

View file

@ -52,6 +52,14 @@ func TestParseClusterNodes(t *testing.T) {
output: "some random text",
wantErr: true,
},
{
name: "numeric node id format",
output: `Membership information
----------------------
Nodeid Votes Name
1 10.0.0.5 2`,
want: []string{"10.0.0.5"},
},
}
for _, tt := range tests {