469,304 Members | 2,018 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

Problem with loaded module Net::SNMP

6
I am trying to run a scrpt and I get an error indicating that the Perl Net::SNMP module may not be loaded.
Expand|Select|Wrap|Line Numbers
  1. #perl udpInOut.pl localhost 161 public 1 
  2. "Can't locate object method "session" via package "Net::SNMP" (perhaps you forgot to load "Net::SNMP"?) at udpInOut.pl line 35."
  3.  
Here are the relevant lines in the script

Expand|Select|Wrap|Line Numbers
  1. use Net::SNMP;
  2. ................
  3. my ($session, $error) = Net::SNMP->session(
  4.                         -hostname      => $in_hostname,
  5.                         -port          => $in_port,
  6.                         -version       => $in_version,
  7.                         -community     => $in_community,
  8.                         );
  9.  

I checked (below) and the Net::SNMP is definitely there

#perldoc perllocal
Thu Oct 18 22:49:42 2007: "Module" Net::SNMP

· "installed into: /usr/lib/perl5/site_perl/5.8.8"

· "LINKTYPE: dynamic"

· "VERSION: 5.2.0"

· "EXE_FILES: snmpkey"


Is this a versioning problem ? Appreciate any help. Cheers
Oct 19 '07 #1
11 6183
KevinADC
4,059 Expert 2GB
The usage looks correct. Try this:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #print "Content-type: text/html\n\n"; #uncomment if running from a browser
  3. print "$_\n" for @INC;
  4.  
see what directories are found in @INC
Oct 20 '07 #2
kr99
6
Good idea, Kevin but the correct path seems to be included

[root@chimds12 ~]# perl test.pl
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.6
/usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.6
/usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8
Oct 20 '07 #3
numberwhun
3,503 Expert Mod 2GB
Good idea, Kevin but the correct path seems to be included

[root@chimds12 ~]# perl test.pl
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.6
/usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.6
/usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8
I think that what Kevin was looking for, was to see if the Net::SNMP module was installed. Did you run the code that he gave you above?


Regards,

Jeff
Oct 20 '07 #4
kr99
6
Hi Jeff
Yes I did use Kevin's code . I copied his code into the test.pl script and that was the output I showed in my post.
Oct 21 '07 #5
numberwhun
3,503 Expert Mod 2GB
Hi Jeff
Yes I did use Kevin's code . I copied his code into the test.pl script and that was the output I showed in my post.
Ok, then this may be a stupid question, but do you have the Net::SNMP module installed on your machine?

Regards,

Jeff
Oct 21 '07 #6
kr99
6
Jeff

The message I am getting does suggest that the loading of the module is indeed the problem. CPAN FAQs told me to run 'perldoc' to see loaded modules and the output below indicates to me that the module is there.
Is there another command I can run ?
Rgds

#perldoc perllocal
Thu Oct 18 22:49:42 2007: "Module" Net::SNMP

· "installed into: /usr/lib/perl5/site_perl/5.8.8"

· "LINKTYPE: dynamic"

· "VERSION: 5.2.0"

· "EXE_FILES: snmpkey"
Oct 21 '07 #7
KevinADC
4,059 Expert 2GB
post the script that is generating the error:

udpInOut.pl

The usage of the module appears to be correct according to the documentation so unless there is a problem in the script I don't know what is causing the error.
Oct 21 '07 #8
KevinADC
4,059 Expert 2GB
Ok, then this may be a stupid question, but do you have the Net::SNMP module installed on your machine?

Regards,

Jeff

He would be getting a different error if the module was not installed:

Can't find foo in @INC, @INC includes......
Oct 21 '07 #9
kr99
6
post the script that is generating the error:

udpInOut.pl

The usage of the module appears to be correct according to the documentation so unless there is a problem in the script I don't know what is causing the error.

Kevin

Here's the code. Appreciate any pointers/help as I really want to extend this code to build a Network Management System.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. # --------------------------------------------------
  4. # ARGV[0] = <hostname>     required
  5. # ARGV[1] = <snmp port>    required
  6. # ARGV[2] = <community>    required
  7. # ARGV[3] = <version>      required
  8. # --------------------------------------------------
  9. use Net::SNMP;
  10.  
  11. # verify input parameters
  12. my $in_hostname         = $ARGV[0] if defined $ARGV[0];
  13. my $in_port             = $ARGV[1] if defined $ARGV[1];
  14. my $in_community        = $ARGV[2] if defined $ARGV[2];
  15. my $in_version          = $ARGV[3] if defined $ARGV[3];
  16.  
  17. # usage notes
  18. if (
  19.         ( ! defined $in_hostname ) ||
  20.         ( ! defined $in_port ) ||
  21.         ( ! defined $in_community ) ||
  22.         ( ! defined $in_version )
  23.         ) {
  24.         print   "usage:\n\n
  25.                 $0 <host> <port> <community> <version>\n\n";
  26.         exit;
  27. }
  28.  
  29. # list all OIDs to be queried
  30. my $udpInDatagrams      = ".1.3.6.1.2.1.7.1.0";
  31. my $udpOutDatagrams     = ".1.3.6.1.2.1.7.4.0";
  32.  
  33. # get information via SNMP
  34. # create session object
  35. my ($session, $error) = Net::SNMP->session(
  36.                         -hostname      => $in_hostname,
  37.                         -port          => $in_port,
  38.                         -version       => $in_version,
  39.                         -community     => $in_community,
  40.                         # please add more parameters if there's a need for them:
  41.                         #   [-localaddr     => $localaddr,]
  42.                         #   [-localport     => $localport,]
  43.                         #   [-nonblocking   => $boolean,]
  44.                         #   [-domain        => $domain,]
  45.                         #   [-timeout       => $seconds,]
  46.                         #   [-retries       => $count,]
  47.                         #   [-maxmsgsize    => $octets,]
  48.                         #   [-translate     => $translate,]
  49.                         #   [-debug         => $bitmask,]
  50.                         #   [-username      => $username,]    # v3
  51.                         #   [-authkey       => $authkey,]     # v3
  52.                         #   [-authpassword  => $authpasswd,]  # v3
  53.                         #   [-authprotocol  => $authproto,]   # v3
  54.                         #   [-privkey       => $privkey,]     # v3
  55.                         #   [-privpassword  => $privpasswd,]  # v3
  56.                         #   [-privprotocol  => $privproto,]   # v3
  57.                         );
  58.  
  59. # on error: exit
  60. if (!defined($session)) {
  61.         printf("ERROR: %s.\n", $error);
  62.         exit 1;
  63.         }
  64.  
  65. # perform get requests for all wanted OIDs
  66. my $result = $session->get_request(
  67.                          -varbindlist      => [$udpInDatagrams, $udpOutDatagrams]
  68.                        );
  69.  
  70. # on error: exit
  71. if (!defined($result)) {
  72.         printf("ERROR: %s.\n", $session->error);
  73.         $session->close;
  74.         exit 1;
  75.         }
  76.  
  77. # print results
  78. printf("udpInDatagrams:%s udpOutDatagrams:%s", # <<< cacti requires this format!
  79.         $result->{$udpInDatagrams},
  80.         $result->{$udpOutDatagrams},
  81.         );
  82.  
  83. $session->close;
Oct 21 '07 #10
kr99
6
Kevin/Jeff
Thanks for your help. I ran out of things to do so I tried removing the whole 5.8.8 directory and reinstalling the Net::SNMP module and , surprise , surprise , the script worked first time! No idea why the reinstallation was required but what the heck... Thanks anyway.
Oct 22 '07 #11
numberwhun
3,503 Expert Mod 2GB
Kevin/Jeff
Thanks for your help. I ran out of things to do so I tried removing the whole 5.8.8 directory and reinstalling the Net::SNMP module and , surprise , surprise , the script worked first time! No idea why the reinstallation was required but what the heck... Thanks anyway.
Well, you know what they say. When all else fails and all normal avenue's have been exhausted, you must sometimes go to extremes.

Glad the re-install worked for you.

Regards,

Jeff
Oct 22 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Michael Kochendoerfer | last post: by
10 posts views Thread by Matthew Bell | last post: by
5 posts views Thread by mony | last post: by
reply views Thread by Bill | last post: by
3 posts views Thread by David T. Ashley | last post: by
1 post views Thread by rinku | last post: by
1 post views Thread by Dirk Van de moortel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.