Skip to content

Commit

Permalink
Merge pull request #95 from B0go/improve-nic-metric
Browse files Browse the repository at this point in the history
  • Loading branch information
galexrt authored Feb 6, 2024
2 parents 64cb5e0 + 7736351 commit ae2caff
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/omreport/omreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (or *OMReport) Nics(nicList ...string) ([]Value, error) {
id := strings.Replace(fields[0], ":", "_", -1)
ts := map[string]string{"id": id, "device": fields[1]}
var ret string
if fields[4] == "Connected" || fields[4] == "Full" {
if fields[4] == "Connected" || fields[4] == "Full" || fields[4] == "Not Applicable" {
ret = "0"
} else {
ret = "1"
Expand Down
81 changes: 81 additions & 0 deletions pkg/omreport/omreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,87 @@ func TestMemory(t *testing.T) {
}
}

var nicTests = []testResultOMReport{
{
Input: `Network Interfaces Information
Physical NIC Interface(s)
Index;Interface Name;Vendor;Description;Connection Status;Slot
0;eno1;Manufacturer;Device Spec;Connected;Embedded
1;eno2;Manufacturer;Device Spec;Connected;Embedded
2;eno3;Manufacturer;Device Spec;Disabled;Embedded
3;eno4;Manufacturer;Device Spec;Disabled;Embedded
Team Interface(s)
Index;Interface Name;Vendor;Description;Redundancy Status
0;bond0;Linux;Ethernet Channel Bonding;Full
1;br0;Linux;Network Bridge;Not Applicable
`,
Values: []Value{
{
Name: "nic_status",
Value: "0",
Labels: map[string]string{
"device": "eno1",
"id": "0",
},
},
{
Name: "nic_status",
Value: "0",
Labels: map[string]string{
"device": "eno2",
"id": "1",
},
},
{
Name: "nic_status",
Value: "1",
Labels: map[string]string{
"device": "eno3",
"id": "2",
},
},
{
Name: "nic_status",
Value: "1",
Labels: map[string]string{
"device": "eno4",
"id": "3",
},
},
{
Name: "nic_status",
Value: "0",
Labels: map[string]string{
"device": "bond0",
"id": "0",
},
},
{
Name: "nic_status",
Value: "0",
Labels: map[string]string{
"device": "br0",
"id": "1",
},
},
},
},
}

func TestNic(t *testing.T) {
input := ""
report := getOMReport(&input)
for _, result := range nicTests {
input = result.Input
values, _ := report.Nics()
assert.Equal(t, result.Values, values)
}
}

var systemTests = []testResultOMReport{
{
Input: `Health
Expand Down

0 comments on commit ae2caff

Please sign in to comment.