How to write simple netsnmp apps in Python
Here’s a couple of different ways you can use netsnmp in Python.
I had a hard time finding documentation, and what I did find was old and outdated. I figured most of it out just by playing around with the library.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#!/usr/bin/env python import netsnmp string = 'public' ver = 1 port = 161 host = '192.168.1.1' # uptime using method 1 bind1 = netsnmp.Varbind('sysUpTime.0') # 1 minute load using method 2 bind2 = netsnmp.Varbind('.1.3.6.1.4.1.2021.10.1.3.1') snmpget = netsnmp.snmpget(bind1, Version=ver, RemotePort=port, DestHost=host, Community=string) uptime_seconds = snmpget[0] print uptime_seconds list = ( bind1, bind2 ) x = netsnmp.Session(DestHost=host, Version=ver, RemotePort=port, Timeout=400000, Retries=5, Community=string) output_list = x.get(list) if not output_list: print "FAILED TO CONNECT!!!" sys.exit(1) if output_list[0]: uptime = output_list[0] if output_list[1]: load1 = output_list[1] |

Next i’ll write a class to do it right and wrap it up as an AWN applet. If you’ve never heard of AWN or haven’t tried the avant-window-navigator you should definitely check it out. I think it’s the best app bar available right now. It fits my needs at the least anyway.
I replaced the bottom gnome-panel with this. If you remove everything except the Launcher/Taskmanager applet and add the Show Desktop applet, it directly replaces gnome-panels functionality completely.