Skip to content

Commit

Permalink
fix: snmp marshal error (#10322)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8a9fbfd)
  • Loading branch information
MyaLongmire authored and powersj committed Jan 5, 2022
1 parent ff4cc03 commit b797d01
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/snmp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func ClearCache() {

func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
once.Do(gosmi.Init)
modules := []string{}

for _, mibPath := range paths {
folders := []string{}
Expand Down Expand Up @@ -79,9 +80,7 @@ func LoadMibsFromPath(paths []string, log telegraf.Logger) error {
if info.IsDir() {
appendPath(path)
} else if info.Mode()&os.ModeSymlink == 0 {
if err := loadModule(info.Name()); err != nil {
log.Warn(err)
}
modules = append(modules, info.Name())
}
return nil
})
Expand All @@ -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
}

Expand Down Expand Up @@ -169,7 +174,11 @@ func SnmpTranslateCall(oid string) (mibName string, oidNum string, oidText strin
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") {
//handle mixed oid ex. .iso.2.3
s := strings.Split(oid, ".")
Expand Down

0 comments on commit b797d01

Please sign in to comment.