diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 03549bcad7..667e482623 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-11-04 Ramon Novoa + + * lib/PandoraFMS/DB.pm, lib/PandoraFMS/Core.pm, + lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/WMIServer.pm, + bin/pandora_server, util/pandora_db.pl: Fixed all pending tracker + bugs. + 2009-11-04 Miguel de Dios * DEBIAN/make_deb_package.sh: move the script to make the deb package into the DEBIAN and change some things into the sourcecode for the directory diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 1212453625..74f17a18b6 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -19,6 +19,7 @@ use strict; use warnings; +use POSIX qw(strftime); # Pandora Modules use PandoraFMS::DB; @@ -176,6 +177,9 @@ while (1) { $server->update (); } + # Update fallen servers + db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ?", strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $Config{'keepalive'}))); + pandora_planned_downtime (\%Config, $DBH); pandora_exec_forced_alerts (\%Config, $DBH); pandora_module_keep_alive_nd (\%Config, $DBH); diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3511b0111c..3ed6385b86 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -214,7 +214,7 @@ sub pandora_process_alert ($$$$$$$) { pandora_event ($pa_config, "Alert ceased (" . $alert->{'name'} . ")", $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, $id, $alert->{'id_agent_module'}, - "alert_recovered", $dbh); + "alert_ceased", $dbh); return; } @@ -434,6 +434,8 @@ sub pandora_execute_action ($$$$$$$$) { _field2_ => $field2, _field3_ => $field3, _agent_ => (defined ($agent)) ? $agent->{'nombre'} : '', + _agentdescription_ => (defined ($agent)) ? $agent->{'comentarios'} : '', + _agentgroup_ => (defined ($agent)) ? get_group_name ($dbh, $agent->{'id_grupo'}) : '', _address_ => (defined ($agent)) ? $agent->{'direccion'} : '', _timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()), _data_ => $data, @@ -443,6 +445,7 @@ sub pandora_execute_action ($$$$$$$$) { _alert_times_fired_ => $alert->{'times_fired'}, _alert_priority_ => $alert->{'priority'}, _module_ => (defined ($module)) ? $module->{'nombre'} : '', + _moduledescription_ => (defined ($module)) ? $module->{'descripcion'} : '', _id_agent_ => (defined ($module)) ? $module->{'id_agente'} : '', ); @@ -451,6 +454,7 @@ sub pandora_execute_action ($$$$$$$$) { if ($action->{'internal'} == 0) { my $command = decode_entities(subst_alert_macros ($action->{'command'}, \%macros)); $command = subst_alert_macros ($command, \%macros); + logger($pa_config, "Executing command $command", 4); eval { system ($command); @@ -513,20 +517,27 @@ sub pandora_process_module ($$$$$$$$$) { # Get module type if ($module_type eq '') { $module_type = get_db_value ($dbh, 'SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?', $module->{'id_tipo_modulo'}); - return unless defined ($module_type); + if (! defined ($module_type)) { + pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); + return; + } } # Process data $data = process_data ($data, $module, $module_type, $utimestamp, $dbh); if (! defined ($data)) { logger($pa_config, "Received invalid data from module '" . $module->{'nombre'} . "'", 3); + pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); return; } # Get agent information if ($agent eq '') { $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); - return unless defined ($agent); + if (! defined ($agent)) { + pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); + return; + } } if ($timestamp eq '') { @@ -538,7 +549,10 @@ sub pandora_process_module ($$$$$$$$$) { # Get previous status my $agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'}); - return unless defined ($agent_status); + if (! defined ($agent_status)) { + pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); + return; + } # Get current status my $status = get_module_status ($data, $module, $module_type); @@ -563,7 +577,11 @@ sub pandora_process_module ($$$$$$$$$) { $agent_status->{'last_try'} = '0000-00-00 00:00:00' unless defined ($agent_status->{'last_try'}); # Do we have to save module data? - return unless ($agent_status->{'last_try'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/); + if ($agent_status->{'last_try'} !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) { + pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh); + return; + } + my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $data || $last_try < (time() - 86400))) ? 1 : 0; @@ -801,20 +819,21 @@ sub pandora_exec_forced_alerts { my ($pa_config, $dbh) = @_; # Get alerts marked for forced execution (even disabled alerts) - my @alerts = get_db_rows ($dbh, 'SELECT talert_template_modules.id as id_template_module, talert_template_modules.*, talert_templates.*, tagente.* - FROM talert_template_modules, talert_templates, tagente, tagente_modulo - WHERE talert_template_modules.id_alert_template = talert_templates.id - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND tagente_modulo.id_agente = tagente.id_agente - AND force_execution = 1'); + my @alerts = get_db_rows ($dbh, 'SELECT * FROM talert_template_modules WHERE force_execution = 1'); foreach my $alert (@alerts) { + + # Get the agent and module associated with the alert + my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); + next unless defined ($module); + my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); + next unless defined ($agent); # $alert already contains agent data! - pandora_execute_alert ($pa_config, 'N/A', $alert, undef, $alert, 1, $dbh); + pandora_execute_alert ($pa_config, 'N/A', $agent, $module, $alert, 1, $dbh); # Reset the force_execution flag, even if the alert could not be executed - db_do ($dbh, "UPDATE talert_template_modules SET force_execution = 0 WHERE id = " . $alert->{'id_template_module'}); + db_do ($dbh, "UPDATE talert_template_modules SET force_execution = 0 WHERE id = " . $alert->{'id'}); } } @@ -856,19 +875,23 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my ($times_fired, $internal_counter, $alert_type) = ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'}); - # OID only - if ($alert->{'alert_type'} == 0) { - my $oid = $alert->{'oid'}; - ($fire_alert, $alert_data) = (1, 'SNMP/OID:' . $oid) if ($trap_oid =~ m/$oid/i || - $trap_oid_text =~ m/$oid/i); + # OID + my $oid = $alert->{'oid'}; + if ($oid ne '' && $trap_oid =~ m/$oid/i || $trap_oid_text =~ m/$oid/i) { + $fire_alert = 1; + $alert_data) .= "OID: $oid "; + } # Custom OID/value - } elsif ($alert_type == 1){ # type 1 is custom value - my $custom_oid = $alert->{'custom_oid'}; - ($fire_alert, $alert_data) = (1, 'SNMP/VALUE:' . $custom_oid) if ($trap_custom_value =~ m/$custom_oid/i || $trap_custom_oid =~ m/$custom_oid/i); + my $custom_oid = $alert->{'custom_oid'}; + if ($custom_oid ne '' && $trap_custom_value =~ m/$custom_oid/i || $trap_custom_oid =~ m/$custom_oid/i) { + $fire_alert = 1; + $alert_data .= "CUSTOM OID: $custom_oid "; + } # Agent IP - } else { - my $agent = $alert->{'agent'}; - ($fire_alert, $alert_data) = (1, 'SNMP/SOURCE:' . $agent) if ($trap_agent =~ m/$agent/i ); + my $agent = $alert->{'agent'}; + if ($agent ne '' && $trap_agent =~ m/$agent/i ) { + $fire_alert = 1; + $alert_data .= "AGENT: $agent"; } next unless ($fire_alert == 1); diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 37ee47cbb2..7be2839213 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -36,6 +36,7 @@ our @EXPORT = qw( get_db_rows get_db_single_row get_db_value + get_group_name get_module_id get_nc_profile_name get_server_id @@ -124,7 +125,7 @@ sub get_module_id ($$) { } ########################################################################## -## Return a network component's profile name given it's ID. +## Return a network component's profile name given its ID. ########################################################################## sub get_nc_profile_name ($$) { my ($dbh, $nc_id) = @_; @@ -132,6 +133,15 @@ sub get_nc_profile_name ($$) { return get_db_value ($dbh, "SELECT * FROM tnetwork_profile WHERE id_np = ?", $nc_id); } +########################################################################## +## Return a group's name given its ID. +########################################################################## +sub get_group_name ($$) { + my ($dbh, $group_id) = @_; + + return get_db_value ($dbh, "SELECT nombre FROM tgrupo WHERE id_grupo = ?", $group_id); +} + ########################################################################## ## Get a single column returned by an SQL query as a hash reference. ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index c609a626dd..ce6fe348b9 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -253,6 +253,9 @@ sub process_module_data ($$$$$$$$$) { # Do not auto create modules return unless ($pa_config->{'autocreate'} == 1); + + # Is the agent learning? + return unless ($agent->{'modo'} eq '1'); # Get the module type my $module_id = get_module_id ($dbh, $module_type); diff --git a/pandora_server/lib/PandoraFMS/WMIServer.pm b/pandora_server/lib/PandoraFMS/WMIServer.pm index fae9803a35..c9bdaea608 100644 --- a/pandora_server/lib/PandoraFMS/WMIServer.pm +++ b/pandora_server/lib/PandoraFMS/WMIServer.pm @@ -168,7 +168,7 @@ sub data_consumer ($$) { } # Check for errors - if ($output[0] =~ /ERROR/) { + if ($output[0] =~ m/ERROR/) { pandora_update_module_on_error ($pa_config, $module_id, $dbh); return; } @@ -177,8 +177,12 @@ sub data_consumer ($$) { my @row = split(/\|/, $output[2]); # Get the specified column - $module_data = $row[$module->{'tcp_port'}]; - + $module_data = $row[$module->{'tcp_port'}] if defined ($row[$module->{'tcp_port'}]); + if ($module_data =~ m/^ERROR/) { + pandora_update_module_on_error ($pa_config, $module_id, $dbh); + return; + } + # Regexp if ($module->{'snmp_community'} ne ''){ my $filter = $module->{'snmp_community'}; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0a3b3d742c..b34aff13b9 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -342,7 +342,7 @@ sub pandora_loadconfig { # Open database to get days_purge days_compact values my $query; my $query_ready; my @data; my $rows_selected; - my $dbh = DBI->connect("DBI:mysql:pandora:$dbhost:3306",$dbuser, $dbpass, {RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost:3306",$dbuser, $dbpass, {RaiseError => 1, AutoCommit => 1 }); $query = "select * from tconfig where token = 'days_purge'"; $query_ready = $dbh->prepare($query); $query_ready ->execute();