From e3a91354853c7132f6e90be7c5ae6f769ef8ac9e Mon Sep 17 00:00:00 2001 From: kongfei605 Date: Thu, 16 May 2024 16:51:57 +0800 Subject: [PATCH] fix: snmp byte conversion (#936) --- inputs/snmp/table.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inputs/snmp/table.go b/inputs/snmp/table.go index 9eb69a70..e1e1caa1 100644 --- a/inputs/snmp/table.go +++ b/inputs/snmp/table.go @@ -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) } } } @@ -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" {