pysnmp/shell

A

Axel Scheepers

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
 
L

Les Smithson

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.
 
I

Ilya Etingof

Les Smithson said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top