melguin has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a script to retrive info via SNMP (which I am new to). I am able to start the session without errors but when I try to get information on a specific oid, I get a noSuchName(2) error. Here's the basis of my code:
my ($remote_snmp_session,$error); ($remote_snmp_session,$error) = Net::SNMP->session(Hostname=>"localhos +t",Community=>"public"); my ($value,$result); my $oid = "1.3.6.1.4.1.314.50.1.20.3.50.1"; ##here's the problem## $result = $remote_snmp_session->get_request($iod) || die "Problem:$!", + $remote_snmp_session->error;
I have used another utility called snmpget with the same hostname, community, and oid. It works successfully.

I've looked through as much documentation as I can get my hands on, but I think I'm missing something very fundimental here. Anyone care to enlighten me?

many thanks.

Replies are listed 'Best First'.
Re: Net::SNMP $session-get_request problem
by Kanji (Parson) on Aug 03, 2001 at 00:15 UTC

    If that snippet is cut n'pasted, then you have a typo ...

    my $oid = "1.3.6.1.4.1.314.50.1.20.3.50.1";
    ##here's the problem##
    $result = $remote_snmp_session->get_request($iod)

        --k.


Re: Net::SNMP $session-get_request problem
by VSarkiss (Monsignor) on Aug 02, 2001 at 23:54 UTC

    I've never used Net::SNMP, but this syntax looks a little odd to me (not wrong, just unusual). According to this: ($remote_snmp_session,$error) = Net::SNMP->session(...there is a (class) method session which returns an array of at least two elements; the first is an object (which you assign to $remote_snmp_session), and the second is some sort of error indicator ($error).

    Later you call an (instance) method called error off the returned object. Are you sure the module indicates errors both ways? TIMTOWTDI, but this is new to me.

    Your die looks unusual also. You're interpolating the system error, if any, into your die string ($!), and then calling the error method. If that method returns a string, try this instead:

    $result = $remote_snmp_session->get_request($iod) or die("Problem " . $remote_snmp_session->error);
    If that error method does something else, this code is probably wrong....

    HTH

Re: Net::SNMP $session-get_request problem
by dondelelcaro (Monk) on Aug 03, 2001 at 00:54 UTC
    Besides the typo that Kanji mentioned, if you are still having problems, it might be because you aren't using the right oid notation.

    oid's that are fully qualified need to start with a . so 1.3.6.1.4.1... would be .1.3.6.1.4.1...

    Now, not knowing which oid you mean to pull, I can't be of too much help. (On my default install of net-snmp, I can't get that oid to resolve to a name... but that's probably just because I'm missing the MIB that you're pulling from...)
      Thanks all for the help. I got if figured out. Just thought I'd give my findings for future generations.

      After correcting the typo mentioned by dondelecaro, it works (well, it would have worked except that someone elses program was messing up the SNMP stuff).

      A good reference for Net::SNMP is the module doc. I found a copy at here.

      thanks again.