Working a whole device with Net::SNMP with Perl

This is a discussion on Working a whole device with Net::SNMP with Perl within the SNMP Users forums, part of the Networking and Network Related category; Hi, I'm trying to figure out how to walk a whole device using Net::SNMP in perl. I have ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Users

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-10-2008
Thomas Bonham
 
Posts: n/a
Default Working a whole device with Net::SNMP with Perl

Hi,

I'm trying to figure out how to walk a whole device using Net::SNMP in
perl. I have done a few other just basic gets with it and I can't figure
out how to do a walk with it.

Thank you for the help.

Thomas

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #2 (permalink)  
Old 06-10-2008
Dave Shield
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

2008/6/10 Thomas Bonham <thomasbonham@bonhamlinux.org>:
> I'm trying to figure out how to walk a whole device using
> Net::SNMP in perl.


$ man SNMP

$vb = new SNMP::Varbind();
do {
$val = $sess->getnext($vb);
print "@{$vb}\n";
} until ($sess->{ErrorNum});



Dave

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #3 (permalink)  
Old 06-10-2008
Ron Rader
 
Posts: n/a
Default RE: Working a whole device with Net::SNMP with Perl

> From: Thomas Bonham [mailto:thomasbonham@bonhamlinux.org]

> I'm trying to figure out how to walk a whole device using Net::SNMP in
> perl


Can't help you with Perl scripts, but if you just want to verify
instrumented MIBs:

<command line>

snmpwalk -c public -v 2c <10.10.10.10> iso

This will walk the SNMP agent at IP address 10.10.10.10 using v2c
protocol and community string "public," starting at the top MIB node.

Ron



The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting all copies. Thank you.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #4 (permalink)  
Old 06-10-2008
Wes Hardaker
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

>>>>> On Tue, 10 Jun 2008 05:08:11 -0700, Thomas Bonham <thomasbonham@bonhamlinux.org> said:

TB> I'm trying to figure out how to walk a whole device using Net::SNMP in
TB> perl.

We aren't affiliated with the Net::SNMP perl module; the module that
binds to the Net-SNMP package is "SNMP" instead (in which case, Dave's
answer is spot on)
--
Wes Hardaker
Sparta, Inc.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #5 (permalink)  
Old 06-10-2008
Thomas Bonham
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

Wes Hardaker wrote:
>>>>>> On Tue, 10 Jun 2008 05:08:11 -0700, Thomas Bonham <thomasbonham@bonhamlinux.org> said:
>>>>>>

>
> TB> I'm trying to figure out how to walk a whole device using Net::SNMP in
> TB> perl.
>
> We aren't affiliated with the Net::SNMP perl module; the module that
> binds to the Net-SNMP package is "SNMP" instead (in which case, Dave's
> answer is spot on)
>

I didn't know that.

Maybe someone can tell me why I'm getting a error here with this little
bit of perl.

Code:
#/usr/bin/perl -w
$host = "localhost";
$st="public";
$sess = new SNMP::Session(DestHost=>$host,Community=>$st);
$val = $sess->get("sysDescr.0");
die $sess->{ErrroStr} if($sess->{ErrorStr});

Error: Unknow user name at test.pl line 7.

Thank you,

Thomas

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #6 (permalink)  
Old 06-10-2008
Mike Ayers
 
Posts: n/a
Default RE: Working a whole device with Net::SNMP with Perl

> From: net-snmp-users-bounces@lists.sourceforge.net
> [mailto:net-snmp-users-bounces@lists.sourceforge.net] On
> Behalf Of Thomas Bonham
> Sent: Tuesday, June 10, 2008 10:17 AM


> Wes Hardaker wrote:
> >>>>>> On Tue, 10 Jun 2008 05:08:11 -0700, Thomas Bonham

> <thomasbonham@bonhamlinux.org> said:
> >>>>>>

> >
> > TB> I'm trying to figure out how to walk a whole device

> using Net::SNMP in
> > TB> perl.
> >
> > We aren't affiliated with the Net::SNMP perl module; the module that
> > binds to the Net-SNMP package is "SNMP" instead (in which

> case, Dave's
> > answer is spot on)
> >

> I didn't know that.


Details, originally from Dave:

http://www.net-snmp.org/wiki/index.p...e_should_I_use

> Maybe someone can tell me why I'm getting a error here with
> this little
> bit of perl.
>
> Code:
> #/usr/bin/perl -w
> $host = "localhost";
> $st="public";
> $sess = new SNMP::Session(DestHost=>$host,Community=>$st);
> $val = $sess->get("sysDescr.0");
> die $sess->{ErrroStr} if($sess->{ErrorStr});
>
> Error: Unknow user name at test.pl line 7.


"User name" is an SNMP v3 concept, but you are setting a community, which implies v1/v2c operation. You need to find and set the thingy that determines the SNMP version. Sorry I can't give more detail, but I gleefully discarded perl years ago...


HTH,

Mike

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #7 (permalink)  
Old 06-11-2008
Thomas Bonham
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

Wes Hardaker wrote:
>>>>>> On Tue, 10 Jun 2008 10:16:20 -0700, Thomas Bonham <thomasbonham@bonhamlinux.org> said:
>>>>>>

>
> TB> Error: Unknow user name at test.pl line 7.
>
> That indicates it's defaulting to SNMPv3 (which is the standard default)
> and the remote agent doesn't have a user matching what you sent.
>
> Use Version => 2c or Version => 1 instead if you want SNMPv2c or SNMPv1.
>

Okay now everything is working.

The only other big thing that I need to figure out how to do is tell it
to just work one little part of something. As a example just have it
work "system" I can't seem to figure that out. Right now I'm working on
one function that will walk "ipAdEntAddr" to get all of the ip address
on the system then from there I will pull then index's of them to I can
then go look it up with the device index.

Thanks for all of the help.

Thomas

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #8 (permalink)  
Old 06-11-2008
Dave Shield
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

2008/6/11 Thomas Bonham <thomasbonham@bonhamlinux.org>:
> The only other big thing that I need to figure out how to do is tell it
> to just work one little part of something. As a example just have it
> work "system"


There are two aspects to this:
- how to tell it where to start
- how to tell it where to stop


You can specify a starting point when you create the initial
Varbind object. Instead of simply

$vb = new SNMP::Varbind();
try
$vb = new SNMP::Varbind(["system"]);

Telling it where to stop is handled by the termination condition
at the end of the look. The initial code fragment I posted used

do {
...
} until ($sess->{ErrorNum});

which keeps going until it reaches the end.
Try something like:

do {
...
} until (${$vb}[0] !~ /^sys/ );

which will print the system group only.

That's not exactly right, since it will actually print
the first entry *after* the system group as well,
before realising that it should have finished.
This might be better re-worked to use a while loop
instead.
And you might find a different test works
better for you. But that shows the basic idea.

Dave

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
  #9 (permalink)  
Old 06-12-2008
Dave Shield
 
Posts: n/a
Default Re: Working a whole device with Net::SNMP with Perl

[ First - *please* don't mail me privately, without copying
any responses to the mailing list. I don't have the time
or inclination to offer private, unpaid, SNMP consultancy.
Keep discussions to the list, where others can both learn
and offer advice. Thanks. ]


2008/6/11 Thomas Bonham <thomasbonham@bonhamlinux.org>:
>>> The only other big thing that I need to figure out how to do is tell it
>>> to just work one little part of something. As a example just have it
>>> work "system"
>>>

>>
>> There are two aspects to this:
>> - how to tell it where to start
>> - how to tell it where to stop
>>
>>
>> You can specify a starting point when you create the initial
>> Varbind object. Instead of simply
>>
>> $vb = new SNMP::Varbind();
>> try
>> $vb = new SNMP::Varbind(["system"]);
>>
>> Telling it where to stop is handled by the termination condition
>> at the end of the look. The initial code fragment I posted used
>>
>>

>
> This part I don't get. I does it matter if I put the "system" mib in the
> "[]" because of the fact it will still go on after the system mib is out.


Yes - because the ["system"] bit is concerned with where the
walk *starts*, not where it stops.

Try running this script with ["system"] and look at the first two or
three lines of output. Then change the script to use ["ifTable"]
and run it again. You should see that the output begins at
(or shortly after) the specified point.

But this is *only* concerned with the starting point.
It has no effect on when the walk ends.
That's covered by the next bit of my earlier response:

>> do {
>> ...
>> } until ($sess->{ErrorNum});
>>
>> which keeps going until it reaches the end.
>> Try something like:
>>
>> do {
>> ...
>> } until (${$vb}[0] !~ /^sys/ );
>>
>> which will print the system group only.


Note the change to the exit condition here.



> So say to walk "ipAdEntAddr" to get the ip address on my computers. What I
> would have to do is to look for where it start and where it ends?



You would specify where it starts using

$vb = new SNMP::Varbind(["ipAdEntAddr"]);

You would specify where it ends by putting a suitable test
in the "until" check above.



> I do just the basic idea and I will problem try and rework it into a while
> loop because I think it will be simply easer to look for the start and the
> stop of some of the "mib" that I'm going to be using.
>
> Also I do plain on sharing this function when I get it done.
>
> Thanks for all of the help and know that this isn't like most question that
> I see through this group.


Dave

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users

Reply With Quote
Reply


Thread Tools
Display Modes

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

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



All times are GMT +1. The time now is 01:05 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0