Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snmp marshal error #10322

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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