Skip to content

Commit

Permalink
fix: snmp byte conversion (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored May 16, 2024
1 parent 0eb9f8d commit e3a9135
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions inputs/snmp/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (t Table) Build(gs snmpConnection, walk bool, tr Translator) (*RTable, erro
log.Printf("E! snmp walk error:%s, oid:%s ", err, oid)
return nil, fmt.Errorf("performing bulk walk for field %s(%s): %w", f.Name, oid, err)
} else {
log.Printf("W! snmp walk error:%s, oid:%s", err, oid)
log.Printf("W! snmp walk error:%s(%s), oid:%s", err, walkErr.Unwrap, oid)
}
}
}
Expand Down Expand Up @@ -593,11 +593,13 @@ func fieldConvert(tr Translator, conv string, ent gosnmp.SnmpPDU) (v interface{}
return v, nil
}
if conv == "byte" {
val, ok := ent.Value.(string)
if !ok {
return nil, fmt.Errorf("invalid type (%T) for storage conversion", ent.Value)
if val, ok := ent.Value.([]byte); ok {
return byteConvert(string(val))
}
if val, ok := ent.Value.(string); ok {
return byteConvert(val)
}
return byteConvert(val)
return nil, fmt.Errorf("invalid type (%T) for byte conversion", ent.Value)
}

if conv == "int" {
Expand Down

0 comments on commit e3a9135

Please sign in to comment.