I am trying to run a scrpt and I get an error indicating that the Perl Net::SNMP module may not be loaded. -
#perl udpInOut.pl localhost 161 public 1
-
"Can't locate object method "session" via package "Net::SNMP" (perhaps you forgot to load "Net::SNMP"?) at udpInOut.pl line 35."
-
Here are the relevant lines in the script -
use Net::SNMP;
-
................
-
my ($session, $error) = Net::SNMP->session(
-
-hostname => $in_hostname,
-
-port => $in_port,
-
-version => $in_version,
-
-community => $in_community,
-
);
-
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
11 6536
The usage looks correct. Try this: -
#!/usr/bin/perl
-
#print "Content-type: text/html\n\n"; #uncomment if running from a browser
-
print "$_\n" for @INC;
-
see what directories are found in @INC
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
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
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.
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
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"
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.
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......
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. - #!/usr/bin/perl -w
-
-
# --------------------------------------------------
-
# ARGV[0] = <hostname> required
-
# ARGV[1] = <snmp port> required
-
# ARGV[2] = <community> required
-
# ARGV[3] = <version> required
-
# --------------------------------------------------
-
use Net::SNMP;
-
-
# verify input parameters
-
my $in_hostname = $ARGV[0] if defined $ARGV[0];
-
my $in_port = $ARGV[1] if defined $ARGV[1];
-
my $in_community = $ARGV[2] if defined $ARGV[2];
-
my $in_version = $ARGV[3] if defined $ARGV[3];
-
-
# usage notes
-
if (
-
( ! defined $in_hostname ) ||
-
( ! defined $in_port ) ||
-
( ! defined $in_community ) ||
-
( ! defined $in_version )
-
) {
-
print "usage:\n\n
-
$0 <host> <port> <community> <version>\n\n";
-
exit;
-
}
-
-
# list all OIDs to be queried
-
my $udpInDatagrams = ".1.3.6.1.2.1.7.1.0";
-
my $udpOutDatagrams = ".1.3.6.1.2.1.7.4.0";
-
-
# get information via SNMP
-
# create session object
-
my ($session, $error) = Net::SNMP->session(
-
-hostname => $in_hostname,
-
-port => $in_port,
-
-version => $in_version,
-
-community => $in_community,
-
# please add more parameters if there's a need for them:
-
# [-localaddr => $localaddr,]
-
# [-localport => $localport,]
-
# [-nonblocking => $boolean,]
-
# [-domain => $domain,]
-
# [-timeout => $seconds,]
-
# [-retries => $count,]
-
# [-maxmsgsize => $octets,]
-
# [-translate => $translate,]
-
# [-debug => $bitmask,]
-
# [-username => $username,] # v3
-
# [-authkey => $authkey,] # v3
-
# [-authpassword => $authpasswd,] # v3
-
# [-authprotocol => $authproto,] # v3
-
# [-privkey => $privkey,] # v3
-
# [-privpassword => $privpasswd,] # v3
-
# [-privprotocol => $privproto,] # v3
-
);
-
-
# on error: exit
-
if (!defined($session)) {
-
printf("ERROR: %s.\n", $error);
-
exit 1;
-
}
-
-
# perform get requests for all wanted OIDs
-
my $result = $session->get_request(
-
-varbindlist => [$udpInDatagrams, $udpOutDatagrams]
-
);
-
-
# on error: exit
-
if (!defined($result)) {
-
printf("ERROR: %s.\n", $session->error);
-
$session->close;
-
exit 1;
-
}
-
-
# print results
-
printf("udpInDatagrams:%s udpOutDatagrams:%s", # <<< cacti requires this format!
-
$result->{$udpInDatagrams},
-
$result->{$udpOutDatagrams},
-
);
-
-
$session->close;
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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#...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |