473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

pysnmp/shell

Hi All,

Python is so great. I've been creating a small set of objects to get some
stats from our adsl routers. So far it works great and fast. However, in the
shell script I created over a year ago to gather stats I do:

mib_lp=`$snmpwalk $ip_address public
ip.ipAddrTable.ipAddrEntry.ipAdEntIf
Index 2>/dev/null | $grep " = $lan_iface" | $head -1 | $sed -E
's/^ip.ipAddrTabl
e.ipAddrEntry.ipAdEntIfIndex.(.+) = .*/\1/g'`
if [ "$mib_lp" != "" ]; then
lan_ip=`$snmpget $ip_address public
ip.ipAddrTable.ipAddrEntry.ipAdEntA
ddr.$mib_lp 2>/dev/null | $sed -E 's/.+IpAddress: //g'`
lan_netmask=`$snmpget $ip_address public
ip.ipAddrTable.ipAddrEntry.ipA
dEntNetMask.$mib_lp 2>/dev/null| $sed -E 's/.+IpAddress: //g'`
else
lan_ip="ERROR"
lan_netmask="ERROR"
fi

To retrieve the lan settings for the router. I don't know the (lan)ip
address of it but do know the interface number, that's why I check for that
and then use a part of the mib to get to the netmask.

This seems to be quite difficult with pysnmp (took me half an hour to write
Router.SNMPQuery(self, noid) ;-)), so before I get started I wanted to ask
if somebody might have better idea for this.

Thanks!
Kind regards,
Axel Scheepers
Jul 18 '05 #1
2 3667
I find the pysnmp API non-intuitive, but maybe that's just me. I've
been thinking about writing a wrapper for it that makes it look more
like the SNMP++ object model, which I'm much more comfortable with.

That said, I did manage to use it to get stats from an ADSL
router. This is a fragment that retrieves and returns the value of a
single OID.

def getVal(s, oid):
encOid = s.encode_oid(s.str2nums(oid))
req = s.encode_request('GETREQUEST', [encOid], [])
answer = s.send_and_receive(req)
i, v = s.decode_response(answer)
val = map(s.decode_value, v)
return val[0]

The pysnmp examples directory has a snmpwalk.py that shows you how to
do a MIB walk, using GETNEXT requests.
Jul 18 '05 #2
Les Smithson <ls******@nohare.spam.demon.co.uk> wrote:
I find the pysnmp API non-intuitive, but maybe that's just me. I've
been thinking about writing a wrapper for it that makes it look more
like the SNMP++ object model, which I'm much more comfortable with.


Well, current pysnmp API deals with rather low-level SNMP protocol
details. That's probably the basic cause of API complexity. From
the other hand, adding another layer of abstraction over current
(rather protocol bound) API might make the whole thing even less
efficient (mainly in CPU terms)...

Anyway, I'm currently working on complete SNMP engine implementation
(on top of current protocol API) that would include RFC-compliant API
to SNMP engine, support for SNMP agent instrumentation and manager
access to MIB information. I hope this would significantly reduce
API complexity.

-ilya

ps. BTW, there are some rather strightforward examples at:
http://pysnmp.sourceforge.net/examples/3.4.x/index.html
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WIWA | last post by:
I have recently installed pySNMP 3.3.2 and use Python 2.2.2. Thanks to Peter Hansen, I succeeded to install pySNMP properly. I'm not completely new to SNMP (I know the basics), but I'm new to...
0
by: WIWA | last post by:
Hi, I have installed pySNMP. I want to make an application where I read out all the OIDs of a MIB of a particular device. In other words, I want to do an SNMPwalk for a certain MIB. I can do...
2
by: Axel Scheepers | last post by:
Hi All, Python is so great. I've been creating a small set of objects to get some stats from our adsl routers. So far it works great and fast. However, in the shell script I created over a year...
4
by: Roy Smith | last post by:
There's been some talk recently about the relative speeds of the various python SNMP libraries. I just did a little benchmarking, and got some surprising results. I downloaded pysnmp-3.4.2 and...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
3
by: rob.audenaerde | last post by:
I'm trying to monitor about 250 devices with SNMP, using PySNMP version 4. I use the threading.Thread to create a threadpool of 10 threads, so devices not responding won't slow down the monitoring...
5
by: bearophileHUGS | last post by:
For array.array "B" means unsigned char, and such arrays accept to be initialized from (str) strings too, this is quite useful: But it seems such capability isn't shared with the append: ...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.