Till last week we were using an heavy modified version of the old and unmaintained yapsnmp module to interface the Devil Framework with the cool Net-SNMP library. It was a real PITA to maintain it and to make it work on all the platforms we currently support (Linux, Windows and OS X). So I've begun a search for an alternative and (in examination order) found and discarded (for various reasons) the Python wrapper included into the Net-SNMP library itself, the pysnmp pure Python implementation and the ctypes-based pynetsnmp that comes with Zenoss.
I than decided to write my own version. Trying to avoid the "not invented here" syndrome I've started modifying the work already done by the cool people at Zenoss. It took only a full work day to (re)implement:
Synchronous and asynchronous "get", "getbulk", "walk" and "set" operations.
Complete MIBs management: set/get MIBs paths, load new MIBs, get OID descriptions from MIBs, oid to name (and vice versa) translation tools.
Session management, internal asynchronous events management, pluggable logger and meaningful error reporting.
I was quite impressed and satisfied till I've tested the code on Windows where I've found that:
some SNMP functions are missing in the "netsnmp.dll" (shutdown_mib, netsnmp_get_mib_directory, netsnmp_set_mib_directory, snprint_description at least)
the "netsnmp.dll" could not resolve any kind of network address (!!!!)
the asynchronous stuff could not work because the select function used to wait on SNMP sockets was receiving non-socket file descriptors (!!)
After 2 (two !!!) days of C code analysis and (useless) debugging (now I know quite well the network section of the Net-SNMP lib :-) ) I've learned that:
The WinSock2 library (used by Net-SNMP) needs to be initialized by hand calling WSAStartup or all networking stuff does not work (this is part my fault as I'd know from my Direct-X 1/2 programming days...but was a long time ago).
Under Linux (and OS X) the snmp_select_info function fills the provided fd_set list with all file descriptors opened for SNMP OR'd in, but under Windows the fd_set list has in the first item the number of file descriptors used, and than the file plain descriptors. Anyone can explain this?
Then was time to test the lib under OS X, but been Unix no problems should occur....WRONG! Under OS X ctypes (or the Net-SNMP lib) does not like to receive a statically nested scope function as a session callback. Anyone can explain this either? A hack was required.
Final notes before the code:
I've developed and tested the lib using Python 2.4.4, ctypes 1.0.1 and Net-SNMP 5.4.1.
I've not written the usual setup stuff, as you must change a couple of (simple) things before you can use the library outside of the Devil Framework source tree (read the comments at the beginning of the "DLNetSNMP.py" file).
You can find some simple tests and usage patters at the end of the "DLNetSNMP.py" file.
If you find bugs or have suggestions or comments or usage notes or anything related do not hesitate to contact me.
The code can be found at the DLNetSNMP home page.