470,636 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

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 3498
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by WIWA | last post: by
reply views Thread by WIWA | last post: by
2 posts views Thread by Axel Scheepers | last post: by
4 posts views Thread by Roy Smith | last post: by
8 posts views Thread by Siemel Naran | last post: by
3 posts views Thread by rob.audenaerde | last post: by
5 posts views Thread by bearophileHUGS | last post: by
21 posts views Thread by Tom Gur | last post: by
1 post views Thread by Korara | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.