I’m using net-snmp’s python libraries to do some long queries on various switches. I would like to be able to load new mibs — but I cannot find any documentation on how to do this.
PySNMP appears to be rather complicated and requires me to create Python objects for each mib (which doesn’t scale for me); so I’m stuck with net-snmp’s libraries (which aren’t bad except for the loading mib thing).
I know I can use the -m and -M options with the net-snmp command-line tools, and there’s documentation on pre-compiling the net-snmp suite (./configure, make etc.) with all the mibs (and I assume into the libraries too); if the Python libraries do not offer the ability to load mibs, can I at least configure net-snmp to provide my python libraries access to the mibs without having to recompile?
I found an answer after all. From the
snmpcmd(1)man page:The key part here is that you can use the
MIBSenvironment variable the same way you use the-mcommand line option…and that support for this is implemented at the library level. This means that if you define theMIBSenvironment variable prior to starting Python, it will affect the behavior of thenetsnmplibrary:Note that you must set
os.environ['MIBS']before calling any of thenetsnmpmodule functions (because this will load the library and any environment changes after this will have no affect).You can (obviously) also set the environment variable outside of Python: