Skip to content

Commit

Permalink
fix #245
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanotorresi committed Dec 16, 2024
1 parent 3b6d5aa commit a681a74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion collector/corosync/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func parseMembers(quorumToolOutput []byte) (members []Member, err error) {
/*
1 1 A,V,NMW 192.168.125.24 (local)
*/
linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s+(?P<qdevice>(\w,?)+)?\s+(?P<name>[\w-.]+)(?:\s(?P<local>\(local\)))?\n?`)
linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s+(?P<qdevice>(\w,?)+)?\s+(?P<name>[^\s]+)(?:\s(?P<local>\(local\)))?\n?`)
linesMatches := linesRE.FindAllSubmatch(sectionMatch[1], -1)
for _, match := range linesMatches {
matches := extractRENamedCaptureGroups(linesRE, match)
Expand Down
23 changes: 23 additions & 0 deletions collector/corosync/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,26 @@ Membership information
assert.True(t, members[1].Local)
assert.EqualValues(t, 1, members[1].Votes)
}

func TestParseMembersWithIpv6Hostnames(t *testing.T) {
quorumToolOutput := []byte(`Quorum information
Membership information
----------------------
Nodeid Votes Qdevice Name
1 1 NR fe80:00:000:0000:1234:5678:ABCD:EF
2 1 NR FE80:0:00:000:0000::1 (local)`)

members, err := parseMembers(quorumToolOutput)

assert.NoError(t, err)

assert.Len(t, members, 2)
assert.Exactly(t, "1", members[0].Id)
assert.Exactly(t, "fe80:00:000:0000:1234:5678:ABCD:EF", members[0].Name)
assert.False(t, members[0].Local)
assert.EqualValues(t, 1, members[0].Votes)
assert.Exactly(t, "2", members[1].Id)
assert.Exactly(t, "FE80:0:00:000:0000::1", members[1].Name)
assert.True(t, members[1].Local)
assert.EqualValues(t, 1, members[1].Votes)
}

0 comments on commit a681a74

Please sign in to comment.