* Changed to SNMP module insted of NET:SNMP, a better results and could get OID with names, not only numeric OID. Tested and works fine.
* Added a small tool to test SNMP functionality (a perl snmpget command using either NET:SNMP or SNMP module). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@53 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
cc98d9f2ed
commit
b9d1f3d466
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
#use Net::SNMP; # For query2 testing
|
||||
use SNMP '5.0.2.pre1' || die("Cannot load module\n");
|
||||
|
||||
##########################################################################################
|
||||
# SUB pandora_query_snmp (pa_config, oid, community, target, error, dbh)
|
||||
# Makes a call to SNMP modules to get a value,
|
||||
##########################################################################################
|
||||
sub pandora_query_snmp2 {
|
||||
my $snmp_oid = shift;
|
||||
my $snmp_community = shift;
|
||||
my $snmp_target = shift;
|
||||
|
||||
|
||||
print "DEBUG OID $snmp_oid comm $snmp_community target $snmp_target \n";
|
||||
my $output ="";
|
||||
|
||||
my ($session1, $error) = Net::SNMP->session(
|
||||
-hostname => $snmp_target,
|
||||
-community => $snmp_community,
|
||||
-port => 161 );
|
||||
|
||||
if (!defined($session1)) {
|
||||
printf("SNMP ERROR SESSION");
|
||||
}
|
||||
|
||||
my $result = $session1->get_request(
|
||||
-varbindlist => $snmp_oid
|
||||
);
|
||||
|
||||
if (!defined($result)) {
|
||||
printf("SNMP ERROR GET");
|
||||
$session1->close;
|
||||
} else {
|
||||
$output = $result->{$snmp_oid};
|
||||
$session1->close;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub pandora_query_snmp {
|
||||
my $snmp_oid = shift;
|
||||
my $snmp_community = shift;
|
||||
my $snmp_target = shift;
|
||||
|
||||
$ENV{'MIBS'}="ALL"; #Load all available MIBs
|
||||
$SNMP_TARGET = $snmp_target;
|
||||
$SNMP_COMMUNITY = $snmp_community;
|
||||
|
||||
$SESSION = new SNMP::Session (DestHost => $SNMP_TARGET,
|
||||
Community => $SNMP_COMMUNITY,
|
||||
Version => 1);
|
||||
|
||||
# Populate a VarList with OID values.
|
||||
$APC_VLIST = new SNMP::VarList([$snmp_oid]);
|
||||
|
||||
# Pass the VarList to getnext building an array of the output
|
||||
@APC_INFO = $SESSION->getnext($APC_VLIST);
|
||||
|
||||
print $APC_INFO[0];
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if ($#ARGV == -1 ){
|
||||
print "Syntax: snmptest community hostname oid\n";
|
||||
exit;
|
||||
}
|
||||
my $snmp_community = $ARGV[0];
|
||||
my $snmp_target = $ARGV[1];
|
||||
my $snmp_oid = $ARGV[2];
|
||||
|
||||
pandora_query_snmp($snmp_oid, $snmp_community, $snmp_target);
|
|
@ -18,7 +18,7 @@ use Net::Ping::External qw(ping); # For ICMP conectivity
|
|||
use Net::Ping; # For ICMP latency
|
||||
use Time::HiRes; # For high precission timedate functions (Net::Ping)
|
||||
use IO::Socket; # For TCP/UDP access
|
||||
use Net::SNMP; # For SNMP access
|
||||
use SNMP; # For SNMP access (libnet-snmp-perl package!
|
||||
|
||||
# Pandora Modules
|
||||
use pandora_config;
|
||||
|
@ -226,31 +226,24 @@ sub pandora_query_snmp {
|
|||
my $snmp_target = $_[3];
|
||||
# $_[4] contains error var.
|
||||
my $dbh = $_[5];
|
||||
|
||||
my $output ="";
|
||||
|
||||
my ($session1, $error) = Net::SNMP->session(
|
||||
-hostname => $snmp_target,
|
||||
-community => $snmp_community,
|
||||
-port => 161 );
|
||||
$ENV{'MIBS'}="ALL"; #Load all available MIBs
|
||||
my $SESSION = new SNMP::Session (DestHost => $snmp_target,
|
||||
Community => $snmp_community,
|
||||
Version => 1);
|
||||
|
||||
if (!defined($session1)) {
|
||||
if (!defined($SESSION)) {
|
||||
logger($pa_config, "SNMP ERROR SESSION", 4);
|
||||
}
|
||||
|
||||
my $result = $session1->get_request(
|
||||
-varbindlist => [$snmp_oid]
|
||||
);
|
||||
|
||||
if (!defined($result)) {
|
||||
logger($pa_config, "SNMP ERROR GET", 4);
|
||||
$session1->close;
|
||||
#$_[4]=1;
|
||||
$_[4]="1";
|
||||
} else {
|
||||
$output = $result->{$snmp_oid};
|
||||
$session1->close;
|
||||
$_[4]=0;
|
||||
}
|
||||
my $OIDLIST = new SNMP::VarList([$snmp_oid]);
|
||||
# Pass the VarList to getnext building an array of the output
|
||||
my @OIDINFO = $SESSION->getnext($OIDLIST);
|
||||
$output = $OIDINFO[0];
|
||||
$_[4]="0";
|
||||
}
|
||||
# Too much DEBUG for me :-)
|
||||
# logger($pa_config, "SNMP RESULT $snmp_oid $snmp_target - > $output \n",10);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ dbuser pandora
|
|||
dbpass pandora
|
||||
|
||||
# dbhost: Database hostname or IP address
|
||||
dbhost 192.168.5.21
|
||||
dbhost localhost
|
||||
|
||||
# verbosity: level of detail on errors/messages (0 default, 1 verbose, 2 debug.... 10 noisy)
|
||||
# -v in command line (verbose) or -d (debug)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue