Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pySNMP: SNMPget example

Reply
Thread Tools

pySNMP: SNMPget example

 
 
WIWA
Guest
Posts: n/a
 
      07-10-2003
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 Python and
pysnmp. While experimenting, I find some strange things. When using
pySNMP:

1) I can type: 'import pysnmp' or 'from pysnmp import *'

2) when using: 'from pysnmp import role' (found on
http://pysnmp.sourceforge
..net/examples/2.x/snmpget.html), I get the message 'ImportError:
cannot
import name role'. The same applies for 'from pysnmp import session'
or 'from pysnmp import v1' , but 'from pysnmp import proto' seems to
work.

3) A general question: how can I get a list of what I can type after
the 'from
pysnmp import ...'

4) How can I use: 'from snmpget import snmpget'. It does not accept
this.

5) Anyone has a simple example for the following application: I have a
cable
modem (which has an SNMP agent inside). I want to make a script where
I can
do SNMPgets (and later SNMPSet and SNMPwalk).

6) Where can I find a simple description on how to use 'snmpget'. I
cannot find
anything. I would like to write sth like snmpget(IP, OID)

7) What is the difference between snmpget and getrequest in pysnmp?

Any input is appreciated...

Thanks in advance,

Wim
 
Reply With Quote
 
 
 
 
Ilya Etingof
Guest
Posts: n/a
 
      07-14-2003
> 2) when using: 'from pysnmp import role' (found on
> http://pysnmp.sourceforge
> .net/examples/2.x/snmpget.html), I get the message 'ImportError:


You seems to use pysnmp 2.x API which differs from the latest 3.x branch
(though, a compatibility layer exists in 3.x distribution). That's why
I suggest you looking at the 3.x docs and examples at:

http://pysnmp.sourceforge.net/docs/3.x/index.html

> 3) A general question: how can I get a list of what I can type after
> the 'from
> pysnmp import ...'


dir(<module>) may help but in this case I'd better see an example.

> 4) How can I use: 'from snmpget import snmpget'. It does not accept
> this.


There is no such module as snmpget in pysnmp.

> 5) Anyone has a simple example for the following application: I have a
> cable
> modem (which has an SNMP agent inside). I want to make a script where
> I can
> do SNMPgets (and later SNMPSet and SNMPwalk).


Python 1.5.2 (#3, Aug 25 1999, 19:14:24) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from pysnmp.proto import v1
>>> from pysnmp.proto.api import generic
>>> from pysnmp.mapping.udp import role
>>> req = v1.GetRequest()
>>> req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)])
>>> tr = role.manager(('router-1.glas.net', 161))
>>> (answer, src) = tr.send_and_receive(req.encode())
>>> rsp = v1.GetResponse()
>>> rsp.decode(answer)
>>> vars = rsp.apiGetPdu().apiGetVarBind()
>>> print vars

[('.1.3.6.1.2.1.1.1.0', OctetString('Cisco Internetwork Operating System
Software\015\012IOS (tm) 5400 Software(C5400-JS-M), Version 12.2(11.8b),
MAINTENANCE INTERIM SOFTWARE\015\012 Copyright (c) 1986-2002 by cisco
Systems, Inc.\015\012 Compiled Tue 30-Jul-02 19:02 by pwade'))]
>>>


> 7) What is the difference between snmpget and getrequest in pysnmp?


The only difference is the SNMP request object (GetRequest vs GetNextRequest)
you create when building SNMP message.

-ilya
 
Reply With Quote
 
 
 
 
Ilya Etingof
Guest
Posts: n/a
 
      07-15-2003
I'd suggest you to refer to "high-level" API documentation at
http://pysnmp.sourceforge.net/docs/3.x/ for getting used to
basic operations on SNMP objects (such as apiGetPdu(), apiSetVarBind()).

Also, note, that pysnmp s/w (the third branch) has been closely aligned
with the APIs introduced by SNMP RFCs, so reading these RFCs may be
helpful too.

If you got more specific questions, please, let me know.

-ilya

WIWA <(E-Mail Removed)> wrote:
> Thanks Ilya,


> This has been very helpful. I'm able to get data out of my 'device
> under test'.


> I must be honnest and say that I understand the sample code, but could
> not write or produce it myself.


> How do you know e.g that
> req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)]) can be
> written? I've read through the documentation and could not find
> anything similar. Of course, I could overlook it.


> Isn't there a tutorial out there that summarizes pysnmpv3 and gives
> examples of snmpget, snmpset, snmpwalk, etc...


> Thanks in advance for helping me out.


> Regards,


> Wim






> Ilya Etingof <(E-Mail Removed)> wrote in message news:<betnfr$dqj$(E-Mail Removed)>...
>> > 2) when using: 'from pysnmp import role' (found on
>> > http://pysnmp.sourceforge
>> > .net/examples/2.x/snmpget.html), I get the message 'ImportError:

>>
>> You seems to use pysnmp 2.x API which differs from the latest 3.x branch
>> (though, a compatibility layer exists in 3.x distribution). That's why
>> I suggest you looking at the 3.x docs and examples at:
>>
>> http://pysnmp.sourceforge.net/docs/3.x/index.html
>>
>> > 3) A general question: how can I get a list of what I can type after
>> > the 'from
>> > pysnmp import ...'

>>
>> dir(<module>) may help but in this case I'd better see an example.
>>
>> > 4) How can I use: 'from snmpget import snmpget'. It does not accept
>> > this.

>>
>> There is no such module as snmpget in pysnmp.
>>
>> > 5) Anyone has a simple example for the following application: I have a
>> > cable
>> > modem (which has an SNMP agent inside). I want to make a script where
>> > I can
>> > do SNMPgets (and later SNMPSet and SNMPwalk).

>>
>> Python 1.5.2 (#3, Aug 25 1999, 19:14:24) [GCC 2.8.1] on sunos5
>> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>> >>> from pysnmp.proto import v1
>> >>> from pysnmp.proto.api import generic
>> >>> from pysnmp.mapping.udp import role
>> >>> req = v1.GetRequest()
>> >>> req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)])
>> >>> tr = role.manager(('router-1.glas.net', 161))
>> >>> (answer, src) = tr.send_and_receive(req.encode())
>> >>> rsp = v1.GetResponse()
>> >>> rsp.decode(answer)
>> >>> vars = rsp.apiGetPdu().apiGetVarBind()
>> >>> print vars

>> [('.1.3.6.1.2.1.1.1.0', OctetString('Cisco Internetwork Operating System
>> Software\015\012IOS (tm) 5400 Software(C5400-JS-M), Version 12.2(11.8b),
>> MAINTENANCE INTERIM SOFTWARE\015\012 Copyright (c) 1986-2002 by cisco
>> Systems, Inc.\015\012 Compiled Tue 30-Jul-02 19:02 by pwade'))]
>> >>>

>>
>> > 7) What is the difference between snmpget and getrequest in pysnmp?

>>
>> The only difference is the SNMP request object (GetRequest vs GetNextRequest)
>> you create when building SNMP message.
>>
>> -ilya

 
Reply With Quote
 
Ilya Etingof
Guest
Posts: n/a
 
      07-16-2003
> 1) Instead of writing '1.3.6.1.2.1.69.1.3.1', I would also like to be
> able to write 'docsDevSwServer'. Any idea how I can do that?


The right way is to use a MIB parser (for labels-to-oids translation) which
is not a part of pysnmp. Try looking at Python backend to libsmi. If you
expect to query just a small and definite set of OIDs, an alternative would be
to hardcode labels-to-oid mapping somewhere in your script.

-ilya
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looking to snmpget to find errdisabled ports ab Cisco 1 09-04-2006 04:47 AM
can't execute @SNMPGET@ on os/x box? Evan Platt Perl Misc 1 08-17-2006 02:19 AM
Installer example in northwind or duwamish7? Bright ASP .Net 1 07-18-2005 05:50 PM
'example.com' == 'example.com.' => false... is this intended? Sam Roberts Ruby 15 02-07-2005 04:36 PM
example designs for Xilinx System Generator ? Timo Dammes VHDL 2 06-11-2004 04:45 PM



Advertisments