From 66c639668c610cc05732da87cb5a0fe502acc6f4 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Tue, 30 Mar 2021 21:08:14 +0200 Subject: [PATCH] Fix inputs.snmp init when no mibs installed (#9050) --- plugins/inputs/snmp/snmp.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index 35d00629acc4c..8f88211d56924 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -255,20 +255,22 @@ func (f *Field) init() error { return nil } - _, oidNum, oidText, conversion, err := SnmpTranslate(f.Oid) - if err != nil { - return fmt.Errorf("translating: %w", err) - } - f.Oid = oidNum - if f.Name == "" { - f.Name = oidText - } - if f.Conversion == "" { - f.Conversion = conversion + // check if oid needs translation or name is not set + if strings.ContainsAny(f.Oid, ":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") || f.Name == "" { + _, oidNum, oidText, conversion, err := SnmpTranslate(f.Oid) + if err != nil { + return fmt.Errorf("translating: %w", err) + } + f.Oid = oidNum + if f.Name == "" { + f.Name = oidText + } + if f.Conversion == "" { + f.Conversion = conversion + } + //TODO use textual convention conversion from the MIB } - //TODO use textual convention conversion from the MIB - f.initialized = true return nil }