fix: snmp marshal error (#10322)
This commit is contained in:
parent
e906698bba
commit
8a9fbfda67
|
|
@ -39,6 +39,7 @@ func ClearCache() {
|
||||||
|
|
||||||
func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
|
func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
|
||||||
once.Do(gosmi.Init)
|
once.Do(gosmi.Init)
|
||||||
|
modules := []string{}
|
||||||
|
|
||||||
for _, mibPath := range paths {
|
for _, mibPath := range paths {
|
||||||
folders := []string{}
|
folders := []string{}
|
||||||
|
|
@ -79,9 +80,7 @@ func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
appendPath(path)
|
appendPath(path)
|
||||||
} else if info.Mode()&os.ModeSymlink == 0 {
|
} else if info.Mode()&os.ModeSymlink == 0 {
|
||||||
if err := loadModule(info.Name()); err != nil {
|
modules = append(modules, info.Name())
|
||||||
log.Warn(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
@ -90,6 +89,12 @@ func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, module := range modules {
|
||||||
|
err := loadModule(module)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("module %v could not be loaded", module)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +174,11 @@ func SnmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin
|
||||||
return oid, oid, oid, oid, out, err
|
return oid, oid, oid, oid, out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
oidNum = "." + out.RenderNumeric() + end
|
if oidNum = out.RenderNumeric(); oidNum == "" {
|
||||||
|
return oid, oid, oid, oid, out, fmt.Errorf("cannot make %v numeric, please ensure all imported mibs are in the path", oid)
|
||||||
|
}
|
||||||
|
|
||||||
|
oidNum = "." + oidNum + end
|
||||||
} else if strings.ContainsAny(oid, "abcdefghijklnmopqrstuvwxyz") {
|
} else if strings.ContainsAny(oid, "abcdefghijklnmopqrstuvwxyz") {
|
||||||
//handle mixed oid ex. .iso.2.3
|
//handle mixed oid ex. .iso.2.3
|
||||||
s := strings.Split(oid, ".")
|
s := strings.Split(oid, ".")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue