influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.51k stars 5.55k forks source link

MIB files named differently to the module identity are not discovered #10446

Open nward opened 2 years ago

nward commented 2 years ago

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:

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 callingBuildModule) 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).

nward commented 2 years ago

See #10444 and #10445 for what I believe are examples of this happening.

nward commented 2 years ago

Something else I have remembered - it is valid for multiple modules to be included in a single MIB file, so gosmi/telegraf will need to be fixed to allow this in order to retain compatibility with snmptranslate.

Hipska commented 2 years ago

FWIW telegraf does load all files in the MIB paths. The only problem is indeed when a MIB imports another one that not yet has been loaded and that one has a different naming. This is something that should be handled by telegraf: keep track if a MIB needs another one, and try to load it again when it finds that other one.

Figured this out also when debugging a strange thing: https://github.com/sleepinggenius2/gosmi/issues/34

reimda commented 2 years ago

10802 switches back to using netsnmp/snmptranslate by default. netsnmp doesn't require files to match the module name, so it should fix this issue for most users.

We should keep this issue open because users who configure telegraf to use gosmi will still hit this issue. We still need to either make changes to telegraf and/or gosmi upstream if we want it to work with the same file naming that netsnmp allows. We should also document the file naming requirements of telegraf's gosmi translator so people know that it's different than netsnmp.

Hipska commented 2 years ago

The file naming doesn't need to be correct when Telegraf would implement a better/smarter loading order. This is also what the maintainer of GoSMI explains.