473,406 Members | 2,217 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,406 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 3669
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.