diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index d258a37cc9..574f8295bc 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,20 @@ +2012-04-19 Sancho Lerena + + (Merged from 4.0.x Branch) + + * util/pandora_xml_stress.conf: default path for default agentname list. + + * lib/PandoraFMS/DataServer.pm: Units are not overwrite by an empty XML + parameter. + + * lib/PandoraFMS/ReconServer.pm: Fixed creation of network components + with double encoding. + + * lib/PandoraFMS/Core.pm: Applied Junichi patch (from trunk) for detecting + keepalive in some newer SQL systems. Added a lot of safe_output in logfile. + Added aditional check for INC types on date collision (same date for different + data). Fixed generation of some events with double encoding. + 2012-04-18 Sancho Lerena * pandora_server_installer: Fixed version. diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d5b60014fc..cf355666c1 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -266,9 +266,9 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) { my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh, $last_data_value, $events, $event) = @_; if (defined ($agent)) { - logger ($pa_config, "Evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "'.", 10); + logger ($pa_config, "Evaluating alert '" . safe_output($alert->{'name'}) . "' for agent '" . safe_output ($agent->{'nombre'}) . "'.", 10); } else { - logger ($pa_config, "Evaluating alert '" . $alert->{'name'} . "'.", 10); + logger ($pa_config, "Evaluating alert '" . safe_output($alert->{'name'}) . "'.", 10); } # Value returned on valid data @@ -369,7 +369,7 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) { $data =~ m/$alert->{'value'}/i; }; if ($@) { - logger ($pa_config, "Error evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': '" . $alert->{'value'} . "' is not a valid regular expression.", 10); + logger ($pa_config, "Error evaluating alert '" . safe_output($alert->{'name'}) . "' for agent '" . safe_output($agent->{'nombre'}) . "': '" . $alert->{'value'} . "' is not a valid regular expression.", 10); return $status; } @@ -411,9 +411,9 @@ sub pandora_process_alert ($$$$$$$$;$) { my ($pa_config, $data, $agent, $module, $alert, $rc, $dbh, $timestamp, $extra_macros) = @_; if (defined ($agent)) { - logger ($pa_config, "Processing alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10); + logger ($pa_config, "Processing alert '" . safe_output($alert->{'name'}) . "' for agent '" . safe_output($agent->{'nombre'}) . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10); } else { - logger ($pa_config, "Processing alert '" . $alert->{'name'} . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10); + logger ($pa_config, "Processing alert '" . safe_output($alert->{'name'}) . "': " . (defined ($AlertStatus[$rc]) ? $AlertStatus[$rc] : 'Unknown status') . ".", 10); } # Simple, event or compound alert? @@ -524,7 +524,7 @@ fired, 0 if not. sub pandora_evaluate_compound_alert ($$$$) { my ($pa_config, $id, $name, $dbh) = @_; - logger ($pa_config, "Evaluating compound alert '$name'.", 10); + logger ($pa_config, "Evaluating compound alert '".safe_output($name)."'.", 10); # Return value my $status = 0; @@ -617,17 +617,17 @@ sub pandora_execute_alert ($$$$$$$$;$) { # Alerts in stand-by are not executed if ($alert->{'standby'} == 1) { if (defined ($module)) { - logger ($pa_config, "Alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "' is in stand-by. Not executing.", 10); + logger ($pa_config, "Alert '" . safe_output($alert->{'name'}) . "' for module '" . safe_output($module->{'nombre'}) . "' is in stand-by. Not executing.", 10); } else { - logger ($pa_config, "Alert '" . $alert->{'name'} . "' is in stand-by. Not executing.", 10); + logger ($pa_config, "Alert '" . safe_output($alert->{'name'}) . "' is in stand-by. Not executing.", 10); } return; } if (defined ($module)) { - logger ($pa_config, "Executing alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "'.", 10); + logger ($pa_config, "Executing alert '" . safe_output($alert->{'name'}) . "' for module '" . safe_output($module->{'nombre'}) . "'.", 10); } else { - logger ($pa_config, "Executing alert '" . $alert->{'name'} . "'.", 10); + logger ($pa_config, "Executing alert '" . safe_output($alert->{'name'}) . "'.", 10); } # Get active actions/commands @@ -683,9 +683,9 @@ sub pandora_execute_alert ($$$$$$$$;$) { # No actions defined if ($#actions < 0) { if (defined ($module)) { - logger ($pa_config, "No actions defined for alert '" . $alert->{'name'} . "' module '" . $module->{'nombre'} . "'.", 10); + logger ($pa_config, "No actions defined for alert '" . safe_output($alert->{'name'}) . "' module '" . safe_output($module->{'nombre'}) . "'.", 10); } else { - logger ($pa_config, "No actions defined for alert '" . $alert->{'name'} . "'.", 10); + logger ($pa_config, "No actions defined for alert '" . safe_output($alert->{'name'}) . "'.", 10); } return; } @@ -702,9 +702,9 @@ sub pandora_execute_alert ($$$$$$$$;$) { pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh, $timestamp, $extra_macros); } else { if (defined ($module)) { - logger ($pa_config, "Skipping action " . $action->{'name'} . " for alert '" . $alert->{'name'} . "' module '" . $module->{'nombre'} . "'.", 10); + logger ($pa_config, "Skipping action " . safe_output($action->{'name'}) . " for alert '" . safe_output($alert->{'name'}) . "' module '" . safe_output($module->{'nombre'}) . "'.", 10); } else { - logger ($pa_config, "Skipping action " . $action->{'name'} . " for alert '" . $alert->{'name'} . "'.", 10); + logger ($pa_config, "Skipping action " . safe_output($action->{'name'}) . " for alert '" . safe_output($alert->{'name'}) . "'.", 10); } } } @@ -728,7 +728,7 @@ sub pandora_execute_action ($$$$$$$$$;$) { my ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh, $timestamp, $extra_macros) = @_; - logger($pa_config, "Executing action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 10); + logger($pa_config, "Executing action '" . safe_output($action->{'name'}) . "' for alert '". safe_output($alert->{'name'}) . "' agent '" . (defined ($agent) ? safe_output($agent->{'nombre'}) : 'N/A') . "'.", 10); my $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; my $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'}; @@ -786,21 +786,21 @@ sub pandora_execute_action ($$$$$$$$$;$) { $macros{_field2_} = subst_alert_macros ($field2, \%macros); $macros{_field3_} = subst_alert_macros ($field3, \%macros); my $command = subst_alert_macros (decode_entities ($action->{'command'}), \%macros); - logger($pa_config, "Executing command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 8); + logger($pa_config, "Executing command '$command' for action '" . safe_output($action->{'name'}) . "' alert '". safe_output($alert->{'name'}) . "' agent '" . (defined ($agent) ? safe_output($agent->{'nombre'}) : 'N/A') . "'.", 8); eval { system ($command); - logger($pa_config, "Command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "' returned with errorlevel " . ($? >> 8), 8); + logger($pa_config, "Command '$command' for action '" . safe_output($action->{'name'}) . "' alert '". safe_output($alert->{'name'}) . "' agent '" . (defined ($agent) ? safe_output($agent->{'nombre'}) : 'N/A') . "' returned with errorlevel " . ($? >> 8), 8); }; if ($@){ - logger($pa_config, "Error $@ executing command '$command' for action '" . $action->{'name'} . "' alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') ."'.", 8); + logger($pa_config, "Error $@ executing command '$command' for action '" . safe_output($action->{'name'}) . "' alert '". safe_output($alert->{'name'}) . "' agent '" . (defined ($agent) ? safe_output($agent->{'nombre'}) : 'N/A') ."'.", 8); } # Internal Audit } elsif ($action->{'name'} eq "Internal Audit") { $field1 = subst_alert_macros ($field1, \%macros); - pandora_audit ($pa_config, $field1, defined ($agent) ? $agent->{'nombre'} : 'N/A', 'Alert (' . $alert->{'description'} . ')', $dbh); + pandora_audit ($pa_config, $field1, defined ($agent) ? safe_output($agent->{'nombre'}) : 'N/A', 'Alert (' . safe_output($alert->{'description'}) . ')', $dbh); # Email } elsif ($action->{'name'} eq "eMail") { @@ -858,13 +858,13 @@ sub pandora_process_module ($$$$$$$$$;$) { my ($pa_config, $data_object, $agent, $module, $module_type, $timestamp, $utimestamp, $server_id, $dbh, $extra_macros) = @_; - logger($pa_config, "Processing module '" . $module->{'nombre'} . "' for agent " . (defined ($agent) && $agent ne '' ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10); + logger($pa_config, "Processing module '" . safe_output($module->{'nombre'}) . "' for agent " . (defined ($agent) && $agent ne '' ? "'" . safe_output($agent->{'nombre'}) . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10); # Get agent information if (! defined ($agent) || $agent eq '') { $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); if (! defined ($agent)) { - logger($pa_config, "Agent ID " . $module->{'id_agente'} . " not found while processing module '" . $module->{'nombre'} . "'.", 3); + logger($pa_config, "Agent ID " . $module->{'id_agente'} . " not found while processing module '" . safe_output($module->{'nombre'}) . "'.", 3); pandora_update_module_on_error ($pa_config, $module, $dbh); return; } @@ -1278,7 +1278,7 @@ Updates the keep_alive module for the given agent. sub pandora_module_keep_alive ($$$$$) { my ($pa_config, $id_agent, $agent_name, $server_id, $dbh) = @_; - logger($pa_config, "Updating keep_alive module for agent '" . $agent_name . "'.", 10); + logger($pa_config, "Updating keep_alive module for agent '" . safe_output($agent_name) . "'.", 10); # Update keepalive module my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND delete_pending = 0 AND id_tipo_modulo = 100', $id_agent); @@ -1595,7 +1595,7 @@ sub pandora_update_module_on_error ($$$) { # Set tagente_estado.current_interval to make sure it is not 0 my $current_interval = ($module->{'module_interval'} == 0 ? 300 : $module->{'module_interval'}); - logger($pa_config, "Updating module " . $module->{'nombre'} . " (ID " . $module->{'id_agente_modulo'} . ") on error.", 10); + logger($pa_config, "Updating module " . safe_output($module->{'nombre'}) . " (ID " . $module->{'id_agente_modulo'} . ") on error.", 10); # Update last_execution_try db_do ($dbh, 'UPDATE tagente_estado SET last_execution_try = ?, current_interval = ? @@ -2082,7 +2082,7 @@ sub pandora_validate_event ($$$) { sub generate_status_event ($$$$$$$) { my ($pa_config, $data, $agent, $module, $status, $last_status, $dbh) = @_; my ($event_type, $severity); - my $description = "Module " . $module->{'nombre'} . " ($data) is "; + my $description = "Module " . safe_output($module->{'nombre'}) . " (".safe_output($data).") is "; # Mark as "validated" any previous event for this module pandora_validate_event ($pa_config, $module->{'id_agente_modulo'}, $dbh); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 11dce5b950..22cad0f29c 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -539,11 +539,13 @@ sub process_module_data ($$$$$$$$$) { # Control NULL columns $module->{'descripcion'} = '' unless defined ($module->{'descripcion'}); $module->{'extended_info'} = '' unless defined ($module->{'extended_info'}); + $module->{'unit'} = '' unless defined ($module->{'unit'}); # Set default values $module_conf->{'max'} = $module->{'max'} unless defined ($module_conf->{'max'}); $module_conf->{'min'} = $module->{'min'} unless defined ($module_conf->{'min'}); $module_conf->{'descripcion'} = $module->{'descripcion'} unless defined ($module_conf->{'descripcion'}); + $module_conf->{'unit'} = $module->{'unit'} unless defined ($module_conf->{'unit'}); $module_conf->{'post_process'} = $module->{'post_process'} unless defined ($module_conf->{'post_process'}); $module_conf->{'module_interval'} = $module->{'module_interval'} unless defined ($module_conf->{'module_interval'}); $module_conf->{'min_critical'} = $module->{'min_critical'} unless defined ($module_conf->{'min_critical'}); @@ -553,7 +555,6 @@ sub process_module_data ($$$$$$$$$) { $module_conf->{'disabled'} = $module->{'disabled'} unless defined ($module_conf->{'disabled'}); $module_conf->{'min_ff_event'} = $module->{'min_ff_event'} unless defined ($module_conf->{'min_ff_event'}); $module_conf->{'extended_info'} = $module->{'extended_info'} unless defined ($module_conf->{'extended_info'}); - $module_conf->{'unit'} = '' unless defined ($module_conf->{'unit'}); # The group name has to be translated to a group ID my $conf_group_id = -1; @@ -646,7 +647,8 @@ sub update_module_configuration ($$$$) { # Update if at least one of the configuration tokens has changed foreach my $conf_token ('min', 'max', 'descripcion', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info', 'unit') { if ($module->{$conf_token} ne $module_conf->{$conf_token}) { - logger ($pa_config, "Updating configuration for module '" . $module->{'nombre'} . "'.", 10); + logger ($pa_config, "Updating configuration for module '" . safe_output($module->{'nombre'}) . "'.", 10); + db_do ($dbh, 'UPDATE tagente_modulo SET unit = ?, min = ?, max = ?, descripcion = ?, post_process = ?, module_interval = ?, min_critical = ?, max_critical = ?, min_warning = ?, max_warning = ?, disabled = ?, min_ff_event = ?, extended_info = ? WHERE id_agente_modulo = ?', $module_conf->{'unit'}, $module_conf->{'min'}, $module_conf->{'max'}, $module_conf->{'descripcion'} eq '' ? $module->{'descripcion'} : $module_conf->{'descripcion'}, $module_conf->{'post_process'}, $module_conf->{'module_interval'}, $module_conf->{'min_critical'}, $module_conf->{'max_critical'}, $module_conf->{'min_warning'}, $module_conf->{'max_warning'}, $module_conf->{'disabled'}, $module_conf->{'min_ff_event'}, $module_conf->{'extended_info'}, $module->{'id_agente_modulo'}); @@ -658,6 +660,7 @@ sub update_module_configuration ($$$$) { foreach my $conf_token ('min', 'max', 'post_process', 'module_interval', 'min_critical', 'max_critical', 'min_warning', 'max_warning', 'disabled', 'min_ff_event', 'extended_info', 'unit') { $module->{$conf_token} = $module_conf->{$conf_token}; } + $module->{'unit'} = ($module_conf->{'unit'} eq '') ? $module->{'unit'} : $module_conf->{'unit'}; $module->{'descripcion'} = ($module_conf->{'descripcion'} eq '') ? $module->{'descripcion'} : $module_conf->{'descripcion'}; } diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index 91b7a0aaaa..5e4dc7f977 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -152,30 +152,19 @@ sub data_consumer ($$) { # Get agent address my $addr = $host->addr(); next unless ($addr ne '0'); - + # Update the recon task or break if it does not exist anymore last if (update_recon_task ($dbh, $task_id, ceil ($progress / ($total_up / 100))) eq '0E0'); - - # Resolve hostnames - my $host_name = undef; - if ($task->{'resolve_names'} == 1){ - $host_name = gethostbyaddr (inet_aton($addr), AF_INET); - } - $host_name = $addr unless defined ($host_name); - + # Does the host already exist? my $agent = get_agent_from_addr ($dbh, $addr); - if (! defined ($agent)) { - $agent = get_agent_from_name ($dbh, $host_name); - } - my $agent_id = defined ($agent) ? $agent->{'id_agente'} : 0; if ($agent_id > 0) { - # Skip if not in learning mode - next if ($agent->{'modo'} != 1); + # Skip if not in learning mode or parent detection is disabled + next if ($agent->{'modo'} != 1 || $task->{'parent_detection'} == 0); } - + # Filter by TCP port if ((defined ($task->{'recon_ports'})) && ($task->{'recon_ports'} ne "")) { next unless (tcp_scan ($pa_config, $addr, $task->{'recon_ports'}) > 0); @@ -193,22 +182,7 @@ sub data_consumer ($$) { if ($task->{'parent_detection'} == 1) { $parent_id = get_host_parent ($pa_config, $addr, $dbh, $task->{'id_group'}, $task->{'parent_recursion'}, $task->{'resolve_names'}, $task->{'os_detect'}); } - - # Add the new address if it does not exist - my $addr_id = get_addr_id ($dbh, $addr); - $addr_id = add_address ($dbh, $addr) unless ($addr_id > 0); - if ($addr_id <= 0) { - logger($pa_config, "Could not add address '$addr' for host '$host_name'.", 3); - next; - } - - # Assign the new address to the agent - my $agent_addr_id = get_agent_addr_id ($dbh, $addr_id, $agent_id); - if ($agent_addr_id <= 0) { - db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`) - VALUES (?, ?)', $addr_id, $agent_id); - } - + # If the agent already exists update parent and continue if ($agent_id > 0) { if ($parent_id > 0) { @@ -217,6 +191,21 @@ sub data_consumer ($$) { next; } + # Resolve hostnames + my $host_name = undef; + if ($task->{'resolve_names'} == 1){ + $host_name = gethostbyaddr (inet_aton($addr), AF_INET); + } + $host_name = $addr unless defined ($host_name); + + # Add the new address if it does not exist + my $addr_id = get_addr_id ($dbh, $addr); + $addr_id = add_address ($dbh, $addr) unless ($addr_id > 0); + if ($addr_id <= 0) { + logger($pa_config, "Could not add address '$addr' for host '".safe_output($host_name)."'.", 3); + next; + } + # GIS Code ----------------------------- # If GIS is activated try to geolocate the ip address of the agent @@ -280,6 +269,10 @@ sub data_consumer ($$) { next; } + # Assign the new address to the agent + db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`) + VALUES (?, ?)', $addr_id, $agent_id); + # Create network profile modules for the agent create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'}); @@ -451,10 +444,10 @@ sub create_network_profile_modules { next; } - logger($pa_config, "Processing network component '" . $component->{'name'} . "' for agent $addr.", 10); + logger($pa_config, "Processing network component '" . safe_output ($component->{'name'}) . "' for agent $addr.", 10); # Use snmp_community from network task instead the component snmp_community - $component->{'snmp_community'} = $snmp_community; + $component->{'snmp_community'} = safe_output ($snmp_community); # Create the module my $module_id = db_insert ($dbh, 'id_agente_modulo', '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, min_warning, max_warning, str_warning, min_critical, max_critical, str_critical, min_ff_event, id_plugin, post_process) @@ -465,7 +458,7 @@ sub create_network_profile_modules { # An entry in tagente_estado is necessary for the module to work db_do ($dbh, 'INSERT INTO tagente_estado (`id_agente_modulo`, `id_agente`, `last_try`, current_interval) VALUES (?, ?, \'1970-01-01 00:00:00\', ?)', $module_id, $agent_id, $component->{'module_interval'}); - logger($pa_config, 'Creating module ' . $component->{'name'} . " for agent $addr from network component '" . $component->{'name'} . "'.", 10); + logger($pa_config, 'Creating module ' . safe_output ($component->{'name'}) . " for agent $addr from network component.", 10); } } diff --git a/pandora_server/util/pandora_xml_stress.conf b/pandora_server/util/pandora_xml_stress.conf index 7292d80b76..6cb2be235d 100644 --- a/pandora_server/util/pandora_xml_stress.conf +++ b/pandora_server/util/pandora_xml_stress.conf @@ -6,7 +6,7 @@ max_threads 5 # File containing a list of agent names (one per line). -agent_file pandora_xml_stress.agents +agent_file /usr/share/pandora_server/util/pandora_xml_stress.agents # Directory where XML data files will be placed, by default /tmp. # When sending files to a local Tentacle server make sure this directory