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

gosmi Load modules not loading mib files properly and giving oid's as blank #41

Open
tanujashinde0405 opened this issue Mar 22, 2023 · 4 comments

Comments

@tanujashinde0405
Copy link

tanujashinde0405 commented Mar 22, 2023

I have been trying to use gosmi for parsing mib's in my code. I have few mib's with me from which 2 mib's are parsing properly and giving proper parsed modules with all the data. but there are few mib's which are getting loaded without any error but when I try to print the nodes from loded module, i see oid's are coming as blank. it is a valid mib but still failing to get parsed in gosmi.
below is the code as well as output :
`package main

import (
"fmt"
"os"
"path/filepath"

"github.com/sleepinggenius2/gosmi"

)

func main() {

var folder string = "/root/testgosmi/mibs"
// Initialize the parser
gosmi.Init()
gosmi.SetPath(folder)
var files []string

err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
	if info.IsDir() {
		return nil
	}
	files = append(files, path)
	return nil
})
if err != nil {
	fmt.Println(err)
}

for _, file := range files {
	filename := filepath.Base(file)
	modulename, err := gosmi.LoadModule(filename)
	if err != nil {
		fmt.Printf("Failed to load MIB module: %v\n", err)
		return
	}
	fmt.Println(modulename)
}

loadedModules := gosmi.GetLoadedModules()
fmt.Println("Loaded modules:")
for _, loadedModule := range loadedModules {
	fmt.Println(loadedModule.Name, loadedModule.Path)
	nodes := loadedModule.GetNodes()
	for _, node := range nodes {
		fmt.Println(node.Name)
		fmt.Println(node.Oid)
	}
}

}
`

output for a successfully parsed mib:
Loaded modules: <well-known> TRIMBLE-MIB /root/testgosmi/mibs/TRIMBLE-MIB.mib trimble 1.3.6.1.4.1.46285 trimbleTiming 1.3.6.1.4.1.46285.1 trimbleTBlt 1.3.6.1.4.1.46285.1.1

output for mib which is giving error:
`TRAP-MIB /root/dummytrap/mibs/test.mib
Traps

MIBNotifObjects

TrapTimeStamp

TrapSeverity

TrapFunctionalArea

`

if you see in above output only node names are getting printed and oid's are coming as blank. so I want able to use GetNodeByOID function in order to fetch node data from above parsed mib.
It would be helpful to know if there is anything i am doing wrong. I tried to parse the same mib using Parser and it works for both mib files but as it dosent have GetNodeByOID i wanted to continue with smi parser.

@tanujashinde0405
Copy link
Author

Tried Parsing few mib's from internet and same issue facing there also.

@sleepinggenius2
Copy link
Owner

I don't have a copy of the referenced MIB, but the most common reason for this is missing dependencies. You need to make sure that every MIB that is being imported is either manually loaded or in the search path to be auto-loaded. Otherwise, you end up with an isolated subtree and no path to it from the root.

@tanujashinde0405
Copy link
Author

I don't have a copy of the referenced MIB, but the most common reason for this is missing dependencies. You need to make sure that every MIB that is being imported is either manually loaded or in the search path to be auto-loaded. Otherwise, you end up with an isolated subtree and no path to it from the root.

Thank you for reaching out so quickly. I wont be able to share the mib's which I am using , but could you please provide few valid mib's which you used during testing gosmi, so that I can confirm the code is working properly with valid mib's. It would be a great help.

@srebhan
Copy link

srebhan commented Apr 12, 2024

@sleepinggenius2 we do have the same issue in Telegraf (influxdata/telegraf#10446) even though we are explicitly import all required MIB files.

I prepared some runnable code showing the issue. It turns out that the loading order of the files is important if we cannot rely on auto-loading due to the naming differences. So if you load the files in the import-hierarchy order everything works, but if a user specifies a bunch of files in arbitrary order (e.g. by specifying a directory) things break...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants