influxdata / influxdata/telegraf
MIB files named differently to the module identity are not discovered
- Dominant language
- Go
- Stars
- 17.8k
- Forks
- 5.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 161
Description
`LoadMibsFromPath` assumes that MIB files are all named exactly as the module name, and asks gosmi to load these modules. gosmi then attempts to load files named exactly as the module name.
This is a common way MIB files are named - however - this is not required by other SNMP software, and many vendors ship MIB files in different naming formats, for example:
- `MODULENAME.txt`
- `MODULENAME.mib`
- `mib-foo-bar.txt`
- `mib-foo`
etc.
In the above cases, telegraf asks gosmi to load modules named the same as the filename - i.e. `MODULENAME.txt` etc. - which is obviously not correct as `MODULENAME.txt` is not the module name - `MODULENAME` is. Extensions cannot be stripped to determine module names (this would not solve examples 3 and 4 above).
Adding the requirement for MIB files to be named as the module name is not compatible with `snmptranslate`.
There are 2 sub-problems to solve here:
1) File names should not be used to discover SMI modules - instead - *if* it is required to parse all MIBs, then all *files* in the MIB directory should be parsed.
2) gosmi's `LoadModule` also expects to find a file named exactly as the module name or with what it thinks are good common extensions (i.e. .txt, .mib, etc.) which solves examples 1 and 2 above, but not 3 and 4.
gosmi has a `parser.Parse` function which takes a filename, rather than an SNMP module - and is what gosmi uses internally when it has discovered the filename (see https://github.com/sleepinggenius2/gosmi/blob/d38face97ec784bf7044de0638c431e5fd6dd8b2/smi/internal/module.go#L326). This (and calling`BuildModule`) may be a valid alternative to calling `LoadModule` - but I am not certain what will happen if a file needs another parent module which has not yet been loaded - i.e. gosmi *may* need the filenames to still match (I have not yet read all the code).
Contributor guide
Research direction
Start with Telegraf's LoadMibsFromPath and inspect gosmi's LoadModule behavior, including parser.Parse and BuildModule and the referenced smi/internal/module.go code. Trace how module dependencies are resolved when filenames differ from module identities. Done means MIB files with names such as mib-foo-bar.txt or mib-foo can be discovered and loaded without breaking dependent modules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100