Hi Chris,
Thanks for guiding about the right style of perl coding & also for
resolving snmp session problem.
My system's snmpd was not enabled & SNMP5.0 was installed which was
giving the error as "Unknown Error Creating session"
I installed SNMP3.6 , started snmpd, httpd in my Linux system & now
there is no problem in creating an snmp session.
But I want to write this as a package/interface file .
Please could U guide/direct me to writing a simple/sample perl package
(sample.pm) & then testing it.
I got to know some of the aspects relating to bless(which are used to
make variables similar to java class variables).
If in a package file SNMP.pm, I need to define functions like
snmpcreatesession,
snmpget,
snmpgetnext .....
Can I write a perl package file following to OOP concepts ,i.e create an
instance of the SNMP
$snmpInstance = new SNMP(arguments)
SNMPgetResult = $snmpInstance->snmpget(arguments)
Please do guide
Thanks,
Geetha
On Tue, 2004-09-07 at 19:50, Chris Devers wrote:
> 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...