Skip to content

Commit

Permalink
fixing a case where some oid values do not get matched in disco (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 authored Nov 6, 2024
1 parent bf80b7a commit bc719c5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions pkg/inputs/snmp/metadata/device_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ func (dm *DeviceMetadata) poll(ctx context.Context, server *gosnmp.GoSNMP) (*kt.
case SNMP_sysDescr:
md.SysDescr = string(value.([]byte))
case SNMP_sysObjectID:
if s, ok := value.(string); ok {
md.SysObjectID = s
} else if s, ok := value.([]byte); ok {
md.SysObjectID = string(s)
switch sd := value.(type) {
case string:
md.SysObjectID = sd
case []byte:
md.SysObjectID = string(sd)
default:
if wrapper.variable.Type == gosnmp.ObjectIdentifier {
md.SysObjectID = string(sd.(string))
} else {
dm.log.Warnf("Unknown type for sysoid: %v %T", value, value)
}
}
case SNMP_sysContact:
md.SysContact = string(value.([]byte))
Expand Down Expand Up @@ -319,10 +326,17 @@ func GetBasicDeviceMetadata(log logger.ContextL, server *gosnmp.GoSNMP) (*kt.Dev
case SNMP_sysDescr:
md.SysDescr = string(value.([]byte))
case SNMP_sysObjectID:
if s, ok := value.(string); ok {
md.SysObjectID = s
} else if s, ok := value.([]byte); ok {
md.SysObjectID = string(s)
switch sd := value.(type) {
case string:
md.SysObjectID = sd
case []byte:
md.SysObjectID = string(sd)
default:
if pdu.Type == gosnmp.ObjectIdentifier {
md.SysObjectID = string(sd.(string))
} else {
log.Warnf("Unknown type for sysoid: %v %T", value, value)
}
}
case SNMP_sysContact:
md.SysContact = string(value.([]byte))
Expand Down

0 comments on commit bc719c5

Please sign in to comment.