From 106067f3b61919cf3d5a19feb593d45c2d532fec Mon Sep 17 00:00:00 2001 From: slerena Date: Wed, 14 Jan 2009 18:33:00 +0000 Subject: [PATCH] 2009-01-14 Sancho Lerena * DB.pm: Solved an invalid reference to hash variable affecting to postprocess calculation. * pandora_recon: Now is compatible with the latest changes. Solved a problem in eval() block. Also fixed a old bug mixing network profiles. This fix will be ported to stable version ASAP. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1342 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 10 +++++ pandora_server/bin/pandora_recon | 60 ++++++++++++----------------- pandora_server/lib/PandoraFMS/DB.pm | 10 ++--- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 563eeee449..46ebf1265e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,13 @@ +2009-01-14 Sancho Lerena + + * DB.pm: Solved an invalid reference to hash variable affecting to + postprocess calculation. + + * pandora_recon: Now is compatible with the latest changes. Solved a + problem in eval() block. Also fixed a old bug mixing network profiles. + This fix will be ported to stable version ASAP. + + 2009-01-12 Sancho Lerena * Makefile.PL: Path to libs was wrong. Fixed. diff --git a/pandora_server/bin/pandora_recon b/pandora_server/bin/pandora_recon index 6de5ddf6d9..231f013d59 100755 --- a/pandora_server/bin/pandora_recon +++ b/pandora_server/bin/pandora_recon @@ -33,6 +33,7 @@ use NetAddr::IP; # To manage IP Addresses # Detect if Net:Traceroute::Pureperl is available. # If not, parent detection will be disabled my $traceroute_loaded = 1; + # Traceroute needs traceroute command unless ( eval "use Net::Traceroute::PurePerl; 1" ) { $traceroute_loaded = 0; @@ -48,6 +49,9 @@ use PandoraFMS::Config; use PandoraFMS::Tools; use PandoraFMS::DB; +# Alarm signal management +$SIG{ALRM} = sub { return 0; }; + # Queue management my @pending_task : shared; my %pending_task_hash : shared; @@ -168,7 +172,7 @@ sub pandora_recon_producer ($) { # Skip modules already queued if ((!defined($pending_task_hash{$data_id_task})) && (!defined($current_task_hash{$data_id_task}))) { - pandora_update_reconstatus ($pa_config, $dbh, $data_id_task, 0); + pandora_update_reconstatus ($pa_config, $dbh, $data_id_task, 0); # Locking scope, do not remove redundant { } { lock $queue_lock; @@ -296,6 +300,7 @@ sub pandora_recon_exec_task { my $target_network = $sql_data->{"subnet"}; my $task_name = $sql_data->{"name"}; my $task_ncprofile = $sql_data->{"id_network_profile"}; + my $task_group = $sql_data->{"id_group"}; my $task_create_incident = $sql_data->{"create_incident"}; my $task_id_os = $sql_data->{"id_os"}; @@ -313,7 +318,6 @@ sub pandora_recon_exec_task { if (!defined($space)){ logger ($pa_config, "Bad network $target_network for task $task_name", 2); pandora_update_reconstatus ($pa_config, $dbh, $id_task, -1); - pandora_task_set_utimestamp ($pa_config, $dbh, $id_task); return -1; } @@ -364,7 +368,6 @@ sub pandora_recon_exec_task { my $progress = ceil($position / ($total_hosts / 100)); pandora_update_reconstatus ($pa_config, $dbh, $id_task, $progress); - pandora_task_set_utimestamp ($pa_config, $dbh, $id_task); } while ($space < $space->broadcast); # fin del buclie principal de iteracion de Ips # Create incident @@ -379,7 +382,6 @@ sub pandora_recon_exec_task { } # Mark RECON TASK as done (-1) pandora_update_reconstatus ($pa_config, $dbh, $id_task, -1); - pandora_task_set_utimestamp ($pa_config, $dbh, $id_task); } @@ -490,6 +492,9 @@ sub pandora_get_agent_from_ip { my $pa_config = $_[0]; my $dbh = $_[1]; my $ip_address = $_[2]; + if ((!defined($ip_address)) || ($ip_address eq "")){ + return 0; + } return get_db_free_field ("SELECT id_agent FROM taddress, taddress_agent WHERE taddress_agent.id_a = taddress.id_a AND ip = '$ip_address'", $dbh); } @@ -504,22 +509,8 @@ sub pandora_update_reconstatus { my $id_task = $_[2]; my $status = $_[3]; - my $query_sql2 = "UPDATE trecon_task SET status = $status WHERE id_rt = $id_task"; - $dbh->do($query_sql2); -} - -########################################################################## -# SUB pandora_task_set_utimestamp (pa_config, dbh, id_task) -# Update utimestamp to current timestamp -########################################################################## -sub pandora_task_set_utimestamp { - my $pa_config = $_[0]; - my $dbh = $_[1]; - my $id_task = $_[2]; - my $my_timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); - my $my_utimestamp = &UnixDate($my_timestamp, "%s"); # convert from human to integer - - my $query_sql2 = "UPDATE trecon_task SET utimestamp = '$my_utimestamp' WHERE id_rt = $id_task"; + my $my_utimestamp = &UnixDate("today", "%s"); + my $query_sql2 = "UPDATE trecon_task SET utimestamp = $my_utimestamp, status = $status WHERE id_rt = $id_task"; $dbh->do($query_sql2); } @@ -567,15 +558,17 @@ sub pandora_task_create_agentmodules { my $agent_id = $_[2]; my $ncprofile_id = $_[3]; my $ip_adress = $_[4]; - my @sql_data; + my $sql_data; + # Search each network component that belongs to ncprofile_id - my $query_sql = "SELECT * FROM tnetwork_profile_component where id_np = $ncprofile_id "; + my $query_sql = "SELECT * FROM tnetwork_profile_component WHERE id_np = $ncprofile_id "; + my $exec_sql = $dbh->prepare($query_sql); $exec_sql ->execute; - while (@sql_data = $exec_sql->fetchrow_array()) { - my $id_nc = $sql_data[1]; - my $query_sql2 = "SELECT * FROM tnetwork_component where id_nc = $id_nc "; + while ($sql_data = $exec_sql->fetchrow_hashref()) { + my $query_sql2 = "SELECT * FROM tnetwork_component wHERE id_nc = ". $sql_data->{"id_nc"}; + my $exec_sql2 = $dbh->prepare($query_sql2); $exec_sql2 ->execute; if ($exec_sql2->rows != 0) { @@ -583,7 +576,6 @@ sub pandora_task_create_agentmodules { my $name = ""; $name = $sql_data2->{"name"}; - my $description = ""; $description = $sql_data2->{"description"}; @@ -634,17 +626,13 @@ sub pandora_task_create_agentmodules { my $query_sql3 = "INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, tcp_port, tcp_send, tcp_rcv, snmp_community, snmp_oid, ip_target, id_module_group, flag, disabled, plugin_user, plugin_pass, plugin_parameter, max_timeout, id_modulo ) VALUES ( $agent_id, $type, '$description', '$name', $max, $min, $interval, $tcp_port, '$tcp_send', '$tcp_rcv', '$snmp_community', '$snmp_oid', '$ip_adress', $id_module_group, 1, 0, $plugin_user, $plugin_pass, $plugin_parameter, $max_timeout, $id_module)"; + $dbh->do($query_sql3); my $last_id_agente_modulo = $dbh->{'mysql_insertid'}; logger($pa_config,"Recon Server: Creating module $name for agent $ip_adress",3); my $query_sql4; - if (($type == 2) || ($type == 6) || ($type == 21) || ($type == 9) || ($type == 18)) { - # for monitors - $query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 0, 0, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)"; - } else { - # not monitors - $query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 0, 100, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)"; - } + $query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 1, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)"; + $dbh->do($query_sql4); } $exec_sql2->finish(); @@ -673,12 +661,15 @@ sub pandora_getparent ($$){ ); my $success = 0; + eval { - local $SIG{ALRM} = sub { die "alarm" }; alarm($pa_config->{"networktimeout"}); $success = $t->traceroute(); alarm(0); }; + if ($@){ + return 0; + } if ($t->hops > 1){ if ($success){ @@ -686,7 +677,6 @@ sub pandora_getparent ($$){ return pandora_get_agent_from_ip ($pa_config, $dbh, $parent_ip); } } - return 0; } diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 82dd933546..10b26220c2 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -596,7 +596,6 @@ sub pandora_writestate (%$$$$$$$) { my $dbh = $_[5]; my $needs_update = $_[6]; - my @data; my $cambio = 0; # Get current timestamp / unix numeric time @@ -610,6 +609,7 @@ sub pandora_writestate (%$$$$$$$) { # Get id # BE CAREFUL: We don't verify the strings chains # TO DO: Verify errors + my $agent_data = get_db_free_row ("SELECT * FROM tagente WHERE nombre = '$nombre_agente'", $dbh); if ($agent_data == -1){ return -1; @@ -624,7 +624,7 @@ sub pandora_writestate (%$$$$$$$) { } my $module_data = get_db_free_row ("SELECT * FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo", $dbh); - + # Valid string data ? (not null) if (($id_modulo == 3) || ($id_modulo == 17) || ($id_modulo == 10) || ($id_modulo == 23)){ if ($datos eq "") { @@ -636,16 +636,16 @@ sub pandora_writestate (%$$$$$$$) { my $id_grupo = dame_grupo_agente($pa_config, $agent_data->{'id_agente'}, $dbh); # Postprocess management - if ( defined($data->{'post_process'}) && ($data->{'post_process'}> 0)) { + if ( defined($module_data->{'post_process'}) && ($module_data->{'post_process'}> 0)) { if (($id_modulo == 1) || ($id_modulo == 7) || ($id_modulo == 15) || ($id_modulo == 22) || ($id_modulo == 4) || ($id_modulo == 8) || ($id_modulo == 16) ){ - $datos = $datos * $data->{'post_process'}; + $datos = $datos * $module_data->{'post_process'}; } } # Status management my $estado = 0; # Normal (OK) by default - + # Only PROC modules have min_critical/max_critical default if ( $tipo_modulo =~ m/proc/ ){ if ($module_data->{'min_critical'} eq $module_data->{'max_critical'}){