From 663b7e9854a8622bb1c95ad3bd4dd8377f3044f0 Mon Sep 17 00:00:00 2001 From: slerena Date: Tue, 10 Feb 2009 18:58:05 +0000 Subject: [PATCH] 2009-02-10 Sancho Lerena * bin/pandora_network: An important BUG discovered in SNMP call locking mechanism. Now calls to SNMP are using exec to snmpget command. Much faster due solved locking problems. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1440 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 ++++ pandora_server/bin/pandora_network | 49 +++++------------------------- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 89e4e538a9..0153ba1805 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2009-02-10 Sancho Lerena + + * bin/pandora_network: An important BUG discovered in SNMP call locking + mechanism. Now calls to SNMP are using exec to snmpget command. Much + faster due solved locking problems. + 2009-02-06 Sancho Lerena * util/plugin/multicast.pl: Multicast check plugin. diff --git a/pandora_server/bin/pandora_network b/pandora_server/bin/pandora_network index 7da471af0f..5432fbc209 100755 --- a/pandora_server/bin/pandora_network +++ b/pandora_server/bin/pandora_network @@ -29,7 +29,6 @@ use Time::Local; # DateTime basic manipulation use Net::Ping; # For ICMP latency use Time::HiRes; # For high precission timedate functions (Net::Ping) use IO::Socket; # For TCP/UDP access -use SNMP; # For SNMP access (libsnmp-perl PACKAGE!) use threads; use threads::shared; @@ -48,13 +47,9 @@ my %pa_config; my @pending_task : shared; my %pending_task_hash : shared; my %current_task_hash : shared; -my $snmp_lock : shared; my $icmp_lock : shared; my $queue_lock : shared; -$ENV{'MIBS'}="ALL"; #Load all available MIBs only once -&SNMP::initMib(); - $SIG{'TERM'} = 'pandora_shutdown'; $SIG{'INT'} = 'pandora_shutdown'; @@ -204,7 +199,7 @@ sub pandora_network_producer ($) { while (1) { if ($pa_config->{"pandora_master"} != 1) { # Query for normal server, not MASTER server - $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left + $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -306,7 +301,7 @@ sub pandora_ping_icmp { my $p; # Some hosts don't accept ICMP with too small payload. Use 16 Bytes min { - lock $icmp_lock; + #lock $icmp_lock; $p = Net::Ping->new("icmp", $l_timeout, 32); $result = $p->ping($dest); } @@ -478,42 +473,14 @@ sub pandora_query_snmp (%$$$$$) { $snmp_version = '1'; } - my $output =""; - my $snmp_timeout = 1000 * 1000 * $pa_config->{"snmp_timeout"}; - my $snmp_retries = $pa_config->{'snmp_checks'}; - my $SESSION; - # Locking for SNMP call. SNMP is not thread safe !! - { - lock $snmp_lock; - $SESSION = new SNMP::Session (DestHost => $snmp_target, - Timeout => $snmp_timeout, - Retries => $snmp_retries, - Community => $snmp_community, - Version => $snmp_version); - } + my $snmp_timeout = $pa_config->{"snmp_timeout"}; + my $snmp_retries = $pa_config->{'snmp_checks'}; - if ((!defined($SESSION)) || ($SESSION->{ErrorStr})) { - logger($pa_config, "SNMP ERROR SESSION for Target $snmp_target ".$SESSION->{ErrorStr}, 2); - $_[5] = "1"; - if (defined($SESSION)){ - undef ($SESSION); - } - return 0; - } - my $oid = SNMP::translateObj($snmp_oid); - # Locking for SNMP call. SNMP is not thread safe !! - { - lock $snmp_lock; - $output = $SESSION->get($oid); + $_[5] = 0; + my $output = `snmpget -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid`; + if ($output eq ""){ + $_[5] = 1; } - if ((!defined($output)) || ($output eq "")) { - logger($pa_config, "SNMP ERROR SNMPGET for Target $snmp_target ".$SESSION->{ErrorStr}, 2); - $_[5] = "1"; - undef ($SESSION); - return 0; - } - $_[5] = "0"; - undef ($SESSION); return $output; }