473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 6536
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,509 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,509 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,509 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

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

Similar topics

2
by: Michael Kochendoerfer | last post by:
Hi, what the heck is this? After installing PHP 4.3.7 on W2K/SP4 and IIS5, PHP creates the following output below my footer line (in fact, after the last </body></html>, when I review the source...
10
by: Matthew Bell | last post by:
Hi, I'm looking for a high-performance SNMP manager toolkit (SNMPv1 / v2, GET / GETNEXT / GETBULK) I can use with Python on Windows2K/XP. I wonder if anyone has got any suggestions? Commercial...
1
by: dan byers | last post by:
hey everyone, i'm working on a system to monitor devices through SNMP. i'm using the Net::SNMP modules by D.Town. i try to load the snmp session request with a set of OIDs to make the system...
5
by: mony | last post by:
I am looking a VB.NET example on how to reference the SNMP API information. I am unable to add references to SNMPAPI.LIB or SNMPAPI.DLL. My goal is to write a 100% VB.NET example (no C or C#...
0
by: Bill | last post by:
I've recently built a new server on which I've tried to configure and install PHP5 (I've now tried 5.0.4, 5.0.5, and 5.1.0RC1) along with Apache 1.3.33 and net-snmp 5.2.1.2. (Building PHP5 as an...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
1
by: rinku | last post by:
hi guys, i m new in asp.net i m facing one problem tht i want to read snmp protocol to show on my webpage, i want to show route errors which we can find through snmp.so please help me how can i...
1
by: Dirk Van de moortel | last post by:
{ OOPS, posted this to moderated group perl.cpan.discuss as well, so it can take a while to get through, if it gets through at all Otherwise sorry for duplicate posting } We need to set up a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.