problems with net-snmp's SNMP OID and perl

problems with net-snmp's SNMP OID and perl

Post by gabriell » Thu, 15 May 2003 03:03:40




> Hello all,

> I seem to be misunderstanding the SNMP module's documentation as I have
> been unable to get a simple value using their example.   It doesn't even
> get to contacting the server as it is not recognizing my OID!

<snip>

Quote:> #!/usr/local/bin/perl -w
> use strict;
> use SNMP;
> SNMP::addMibDirs(</usr/local/share/snmp/mibs>);
> SNMP::loadModules(</usr/local/share/snmp/mibs/SQUID-MIB.txt>); #[also
> just tried SQUID-MIB.txt since I have the dir added above] my $value; my
> $key;

<snip>

Quote:> $ ./snmp.pl
> error: get: unknown object ID (cacheUptime) at

This is J. Marzot's SNMP module, right?

I have found that this sort of thing works to load MIBs: (not very useful
example, but you get the idea):

#-----begin
#!/usr/local/bin/perl -w

use strict;
use SNMP;

# ---- Set variables ---- #
my ($hostname, $community);
$hostname=$ARGV[0];
$community=$ARGV[1];

# ---- set up snmp ---- #
my ($sess, $vars);
$SNMP::debugging = 0;   #set to 1 if you're having a problem.
SNMP::initMib();
SNMP::addMibFiles(</usr/local/share/snmp/mibs/CISCO-STACK-MIB.txt>);

$sess = new SNMP::Session(
        'DestHost'      => $hostname,
        'Community'     => $community,
        'Version'    => '2c',
);

# ---- get data ---- #
my $moduleType = $sess->get('moduleType.1');

my $moduleModel = $sess->get('moduleModel.1');

print ("type: $moduleType; model: $moduleModel\n");

exit 0;

#-----end

HTH
gabrielle

 
 
 

problems with net-snmp's SNMP OID and perl

Post by Dave Shiel » Thu, 15 May 2003 21:01:56



> SNMP::addMibDirs(</usr/local/share/snmp/mibs>);
> SNMP::loadModules(</usr/local/share/snmp/mibs/SQUID-MIB.txt>);
> #[also just tried SQUID-MIB.txt since I have the dir added above]

Not quite.
The call "loadModules" takes the name of a MIB *module* rather
than a MIB *file*.    In other words, the name that precedes
the DEFINITIONS token.

Typically, this should probably read

    SNMP::loadModules("SQUID-MIB");

i.e. without the '.txt' filename extension.

But if the module name and the filename are totally different
(which is confusing, but perfectly valid), then you need to
go with the name of the *module*.

Dave

 
 
 

problems with net-snmp's SNMP OID and perl

Post by gabriell » Sat, 17 May 2003 17:06:50




>>This is J. Marzot's SNMP module, right?

> That's right, is there some other SNMP module you would suggest?

There is a Net::SNMP module, which, despite the name, is actually
unrelated to Net-SNMP's SNMP module.  When I was trying to figure out how
to load MIBs into SNMP.pm, I came across a lot of posts in
comp.lang.perl.modules for Net::SNMP. Confused?  I sure was! :D  I'd stick
with the one you're using, personally.

Quote:> As I wrote to Dave, adding the loadModules call fixed my script and now
> I can at least move forward.

Excellent!  I guess I need to do some research myself to figure out why
one would use loadModules over loadMibs. Hrm.

  I do need to learn more about SNMP since

Quote:> the SNMP man page assumes a lot of knowledge, but at least I am getting
> back real numbers.   I next need to read the man page for bulkwalk so I
> can emulate an snmpwalk of the whole tree (easy with snmpwalk, I just
> feed it enterprise.nlanr.squid but that returned nothing with a simple
> get so I imagine I have to do a bulkwalk).

This might seem really silly, but one of the best things I did as far as
understanding how the cli snmp utilities work was to try them (snmpget,
snmpgetnext, snmpwalk, etc--there's a whole slew of them) with different
OIDs, eg 'system' vs 'system.sysDescr.0' and see what happened.  It was
quite enlightening.

  If you know of any pointers,

Quote:> threads or sites with code that already does this or has examples that
> would be much appreciated.

Just here, comp.lang.perl.modules, Net-SNMP list, and the examples that
come with the module.  If it's any consolation, I had a really hard time
understanding the SNMP.pm documentation too, and ended up coming up with
my own example scripts, one of which you saw in my previous post.

The module comes with a decent example of a bulkwalk, which I played with
extensively and eventually got to do what I needed.

A couple of my own tips:
- For a bulkwalk you need to specify version 2c.

- There is a limit to how much info you can get back from a bulkwalk--if
you seem to be missing data, try splitting your request up into more than
one piece.

If you're still stuck after dinking with the example, post back.

HTH
gabrielle