How to write simple netsnmp apps in Python

Posted in apps , howto , 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 = '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]

avant

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.

Posted by admica   @   29 April 2011

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

*

Previous Post
«
Next Post
»
Powered by Wordpress   |   Lunated designed by ZenVerse

Valid XHTML 1.0 Transitional