Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions collector/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ func processStatusVersion(output []byte) (string, string, error) {
}
version := versionMatch[1]

// Extract OS using regex: on OS.
// Extract OS using regex: on OS. OS is optional as not all FRR
// distributions include it (e.g. Cumulus).
var os string
osRegex := regexp.MustCompile(`on (.+)\.$`)
osMatch := osRegex.FindStringSubmatch(firstLine)
if len(osMatch) < 2 {
return "", "", fmt.Errorf("could not extract OS from: %s", firstLine)
if len(osMatch) >= 2 {
os = osMatch[1]
}
os := osMatch[1]

return version, os, nil
}
18 changes: 18 additions & 0 deletions collector/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ func TestProcessStatusVersionWithMetrics(t *testing.T) {
compareMetrics(t, gotMetrics, expectedStatusMetrics)
}

func TestProcessStatusVersionNoOS(t *testing.T) {
fixture := readTestFixture(t, "show_version_no_os.txt")

version, os, err := processStatusVersion(fixture)
if err != nil {
t.Errorf("error calling processStatusVersion: %s", err)
}

expectedVersion := "7.5+cl5.2.0u0"
if version != expectedVersion {
t.Errorf("expected version %s, got %s", expectedVersion, version)
}

if os != "" {
t.Errorf("expected empty os, got %s", os)
}
}

func TestProcessStatusVersionEmpty(t *testing.T) {
_, _, err := processStatusVersion([]byte(""))
if err == nil {
Expand Down
2 changes: 2 additions & 0 deletions collector/testdata/show_version_no_os.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FRRouting 7.5+cl5.2.0u0 (router).
Copyright 1996-2005 Kunihiro Ishiguro, et al.
Loading