On Tue, 7 Sep 2004, Geetha B wrote:

 ($session, $error) = Net::SNMP->session(
    -hostname  => shift || 'localhost',
    -community => shift || 'public',
    -port      => shift || 161
 );

It may be a dead end, but it may help to define these items as temp variables, and then throw in a print statement that confirms that you're actually using the values you meant to use.


This is, admittedly, grasping, but it's worth a shot.

My favorite debugging technique is to throw in lots of print statements to show what data is being used at key sections of the program, as in most cases this can help pin down where things are going wrong. This seems like an example where doing that may help.

If nothing else, can you hard-code the values that you're `shift`ing so that you know this should work ? If the script fails when you're sure you're using the right data, the problem may be in the module itself.

Also, why are you coding your test handler like this?

    if (!defined($session)) {
        printf("ERROR: %s.\n", $error);
        exit 1;
    }

Why a printf? Why `exit` instead of `die`? This seems more idiomatic:

    defined($session) or die "ERROR: $error\n$!\n";

Wouldn't something like the above line work ?

Anyway, I tried your script as a one-liner on a Debian machine with their version of Net::SNMP installed, and it seems like everything works fine:

    $ perl -MNet::SNMP -e '($session, $error) = Net::SNMP->session( -hostname => "localhost", -community => 
"public", -port => 161); defined($session) or die "ERROR: $error\n$!\n";'
    $

This suggests that the module is probably working, and the line that calls the session(...) may not be getting the needed data...


-- Chris Devers

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to