mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
2007-07-19 Sancho Lerena <slerena@artica.es>
* pandora_network.pl: Added concurrency locking for ICMP and removed previos method (repeating tests). This sould work fine and faster. ICMP Latency added as independent function. This sould go on a new library for 1.4 or 2.0 version. Removed some debug commented code. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@569 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
cd3b587a86
commit
f6fb9a2567
@ -1,3 +1,11 @@
|
|||||||
|
2007-07-19 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
|
* pandora_network.pl: Added concurrency locking for ICMP and
|
||||||
|
removed previos method (repeating tests). This sould work fine and
|
||||||
|
faster. ICMP Latency added as independent function. This sould go
|
||||||
|
on a new library for 1.4 or 2.0 version. Removed some debug
|
||||||
|
commented code.
|
||||||
|
|
||||||
2007-07-18 Sancho Lerena <slerena@artica.es>
|
2007-07-18 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
* pandora_network.pl: BugFix: SNMP calls that was causing segfauls was
|
* pandora_network.pl: BugFix: SNMP calls that was causing segfauls was
|
||||||
|
@ -44,6 +44,7 @@ my @pending_task : shared;
|
|||||||
my %pending_task_hash : shared;
|
my %pending_task_hash : shared;
|
||||||
my %current_task_hash : shared;
|
my %current_task_hash : shared;
|
||||||
my $snmp_lock : shared;
|
my $snmp_lock : shared;
|
||||||
|
my $icmp_lock : shared;
|
||||||
|
|
||||||
$ENV{'MIBS'}="ALL"; #Load all available MIBs only once
|
$ENV{'MIBS'}="ALL"; #Load all available MIBs only once
|
||||||
$SIG{'TERM'} = 'pandora_shutdown';
|
$SIG{'TERM'} = 'pandora_shutdown';
|
||||||
@ -143,7 +144,6 @@ sub pandora_network_consumer ($$) {
|
|||||||
$current_task_hash{$data_id_agent_module}=1;
|
$current_task_hash{$data_id_agent_module}=1;
|
||||||
}
|
}
|
||||||
# Call network execution process
|
# Call network execution process
|
||||||
#print "[D] EXECUTING $data_id_agent_module MODULE FROM CONSUMER $thread_id \n";
|
|
||||||
exec_network_module ( $pa_config, $data_id_agent_module, $dbh);
|
exec_network_module ( $pa_config, $data_id_agent_module, $dbh);
|
||||||
{
|
{
|
||||||
lock %current_task_hash;
|
lock %current_task_hash;
|
||||||
@ -203,14 +203,12 @@ sub pandora_network_producer ($) {
|
|||||||
}
|
}
|
||||||
$exec_sql1 = $dbh->prepare($query1);
|
$exec_sql1 = $dbh->prepare($query1);
|
||||||
$exec_sql1 ->execute;
|
$exec_sql1 ->execute;
|
||||||
#print "[D] Total number of items in this query ".$exec_sql1->rows." \n";
|
|
||||||
while (@sql_data1 = $exec_sql1->fetchrow_array()) {
|
while (@sql_data1 = $exec_sql1->fetchrow_array()) {
|
||||||
$data_id_agente_modulo = $sql_data1[0];
|
$data_id_agente_modulo = $sql_data1[0];
|
||||||
$data_flag = $sql_data1[1];
|
$data_flag = $sql_data1[1];
|
||||||
# Skip modules already queued
|
# Skip modules already queued
|
||||||
if ((!defined($pending_task_hash{$data_id_agente_modulo})) &&
|
if ((!defined($pending_task_hash{$data_id_agente_modulo})) &&
|
||||||
(!defined($current_task_hash{$data_id_agente_modulo}))) {
|
(!defined($current_task_hash{$data_id_agente_modulo}))) {
|
||||||
#print "[D] PRODUCER IS INSERTING MODULE $data_id_agente_modulo \n";
|
|
||||||
if ($data_flag == 1){
|
if ($data_flag == 1){
|
||||||
$dbh->do("UPDATE tagente_modulo SET flag = 0 WHERE id_agente_modulo = $data_id_agente_modulo")
|
$dbh->do("UPDATE tagente_modulo SET flag = 0 WHERE id_agente_modulo = $data_id_agente_modulo")
|
||||||
}
|
}
|
||||||
@ -224,7 +222,6 @@ sub pandora_network_producer ($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$exec_sql1->finish();
|
$exec_sql1->finish();
|
||||||
#print "[D] Items in pending task queue [ ".scalar(@pending_task)." ]\n";
|
|
||||||
sleep($pa_config->{"server_threshold"});
|
sleep($pa_config->{"server_threshold"});
|
||||||
} # Main loop
|
} # Main loop
|
||||||
}
|
}
|
||||||
@ -245,32 +242,47 @@ sub pandora_ping_icmp {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
|
# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
|
||||||
$p = Net::Ping->new("icmp", $l_timeout, 16);
|
{
|
||||||
$result = $p->ping($dest);
|
lock $icmp_lock;
|
||||||
|
$p = Net::Ping->new("icmp", $l_timeout, 16);
|
||||||
|
$result = $p->ping($dest);
|
||||||
|
}
|
||||||
|
|
||||||
# If first PING get valid and 1, let's exit (faster)
|
|
||||||
if (defined($result)){
|
if (defined($result)){
|
||||||
|
$p->close();
|
||||||
if ($result == 1){
|
if ($result == 1){
|
||||||
$p->close();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
# If not, makes a second one to be sure
|
##############################################################################
|
||||||
$result2 = $p->ping($dest);
|
# pandora_ping_latency (destination, timeout, data, result) - Do a ICMP latency check
|
||||||
# Check for valid result
|
##############################################################################
|
||||||
if ((!defined($result)) || (!defined($result2))) {
|
sub pandora_ping_latency {
|
||||||
return 0;
|
my $dest = $_[0];
|
||||||
}
|
my $l_timeout = $_[1];
|
||||||
|
my $module_data = $_[2];
|
||||||
|
my $module_result = $_[3];
|
||||||
|
|
||||||
# Lets see the result
|
my $icmp_return;
|
||||||
if (($result == 1) && ($result2 == 1)) {
|
my $icmp_reply;
|
||||||
$p->close();
|
my $icmp_ip;
|
||||||
return 1;
|
my $nm = Net::Ping->new("icmp", $l_timeout, 32);
|
||||||
} else {
|
{
|
||||||
$p->close();
|
lock $icmp_lock;
|
||||||
return 0;
|
$nm->hires();
|
||||||
}
|
($icmp_return, $icmp_reply, $icmp_ip) = $nm->ping ($dest,$l_timeout);
|
||||||
|
}
|
||||||
|
if ($icmp_return) {
|
||||||
|
$$module_data = $icmp_reply * 1000; # milliseconds
|
||||||
|
$$module_result = 0; # Successful
|
||||||
|
} else {
|
||||||
|
$$module_result = 1; # Error.
|
||||||
|
$$module_data = 0;
|
||||||
|
}
|
||||||
|
$nm->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -485,20 +497,7 @@ sub exec_network_module {
|
|||||||
} elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms)
|
} elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms)
|
||||||
# This module only could be executed if executed as root
|
# This module only could be executed if executed as root
|
||||||
if ($> == 0){
|
if ($> == 0){
|
||||||
my $nm = Net::Ping->new("icmp", $pa_config->{'networktimeout'}, 32);
|
pandora_ping_latency ($ip_target, $pa_config->{"networktimeout"}, \$module_data, $module_result);
|
||||||
my $icmp_return;
|
|
||||||
my $icmp_reply;
|
|
||||||
my $icmp_ip;
|
|
||||||
$nm->hires();
|
|
||||||
($icmp_return, $icmp_reply, $icmp_ip) = $nm->ping ($ip_target,$pa_config->{"networktimeout"});
|
|
||||||
if ($icmp_return) {
|
|
||||||
$module_data = $icmp_reply * 1000; # milliseconds
|
|
||||||
$module_result = 0; # Successful
|
|
||||||
} else {
|
|
||||||
$module_result = 1; # Error.
|
|
||||||
$module_data = 0;
|
|
||||||
}
|
|
||||||
$nm->close();
|
|
||||||
} else {
|
} else {
|
||||||
$module_result = 0; # Done but, with zero value
|
$module_result = 0; # Done but, with zero value
|
||||||
$module_data = 0; # This should don't happen
|
$module_data = 0; # This should don't happen
|
||||||
|
Loading…
x
Reference in New Issue
Block a user