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.

#!/usr/bin/env python
import netsnmp

string = 'public'
ver = 1
port = 161
host = ''

# uptime using method 1
bind1 = netsnmp.Varbind('sysUpTime.0')
# 1 minute load using method 2
bind2 = netsnmp.Varbind('.')

snmpget = netsnmp.snmpget(bind1,
uptime_seconds = snmpget[0]
print uptime_seconds

list = ( bind1, bind2 )
x = netsnmp.Session(DestHost=host,
output_list = x.get(list)
if not output_list:
    print "FAILED TO CONNECT!!!"

if output_list[0]:
    uptime = output_list[0]

if output_list[1]:
    load1 = output_list[1]

python blue and yellow logoNext I wrote a class to 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 and consider continuing development on it. It was the best app bar available; very pretty. It fit my needs at the time anyway.

I replaced the bottom gnome-panel with it. If you remove everything except the Launcher/Taskmanager applet and add the Show Desktop applet, it directly replaces gnome-panels functionality completely.

Leave a Reply

Your email address will not be published. Required fields are marked *