Skip to content

Commit

Permalink
Expect a string from gosnmp PDUs of type OctetString (#12)
Browse files Browse the repository at this point in the history
* gosnmp now returns a string for PDU type OctetString

* Updates unit tests to use string type for OctetString PDU types.
  • Loading branch information
nkinkade authored Aug 5, 2020
1 parent 223d20f commit 993cb69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func mustGetIfaces(client snmp.Client, machine string) map[string]map[string]str
oidParts := strings.Split(pdu.Name, ".")
iface := oidParts[len(oidParts)-1]

b := pdu.Value.([]byte)
val := strings.TrimSpace(string(b))
val := strings.TrimSpace(pdu.Value.(string))
if val == machine {
ifDescrOid := createOID(ifDescrOidStub, iface)
oidMap, err := getOidsString(client, []string{ifDescrOid})
Expand Down Expand Up @@ -110,7 +109,7 @@ func getOidsString(client snmp.Client, oids []string) (map[string]string, error)
oidMap := make(map[string]string)
result, err := client.Get(oids)
for _, pdu := range result.Variables {
oidMap[pdu.Name] = string(pdu.Value.([]byte))
oidMap[pdu.Name] = pdu.Value.(string)
}
return oidMap, err
}
Expand Down
8 changes: 4 additions & 4 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var snmpPacketMachine = gosnmp.SnmpPacket{
{
Name: ifDescrMachineOID,
Type: gosnmp.OctetString,
Value: []byte("xe-0/0/12"),
Value: "xe-0/0/12",
},
},
}
Expand All @@ -66,7 +66,7 @@ var snmpPacketUplink = gosnmp.SnmpPacket{
{
Name: ifDescrUplinkOID,
Type: gosnmp.OctetString,
Value: []byte("xe-0/0/45"),
Value: "xe-0/0/45",
},
},
}
Expand Down Expand Up @@ -141,12 +141,12 @@ func (m *mockSwitchClient) BulkWalkAll(rootOid string) (results []gosnmp.SnmpPDU
{
Name: ifDescrMachineOID,
Type: gosnmp.OctetString,
Value: []byte("mlab2"),
Value: "mlab2",
},
{
Name: ifDescrUplinkOID,
Type: gosnmp.OctetString,
Value: []byte("uplink-10g"),
Value: "uplink-10g",
},
}, nil
}
Expand Down

0 comments on commit 993cb69

Please sign in to comment.