2009-11-04 Ramon Novoa <rnovoa@artica.es>

* 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.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2081 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-11-04 17:49:42 +00:00
parent 8effb6d47f
commit dc9666c214
7 changed files with 80 additions and 29 deletions

View File

@ -1,3 +1,10 @@
2009-11-04 Ramon Novoa <rnovoa@artica.es>
* 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 <miguel.dedios@artica.es> 2009-11-04 Miguel de Dios <miguel.dedios@artica.es>
* DEBIAN/make_deb_package.sh: move the script to make the deb package into * 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 the DEBIAN and change some things into the sourcecode for the directory

View File

@ -19,6 +19,7 @@
use strict; use strict;
use warnings; use warnings;
use POSIX qw(strftime);
# Pandora Modules # Pandora Modules
use PandoraFMS::DB; use PandoraFMS::DB;
@ -176,6 +177,9 @@ while (1) {
$server->update (); $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_planned_downtime (\%Config, $DBH);
pandora_exec_forced_alerts (\%Config, $DBH); pandora_exec_forced_alerts (\%Config, $DBH);
pandora_module_keep_alive_nd (\%Config, $DBH); pandora_module_keep_alive_nd (\%Config, $DBH);

View File

@ -214,7 +214,7 @@ sub pandora_process_alert ($$$$$$$) {
pandora_event ($pa_config, "Alert ceased (" . pandora_event ($pa_config, "Alert ceased (" .
$alert->{'name'} . ")", $agent->{'id_grupo'}, $alert->{'name'} . ")", $agent->{'id_grupo'},
$agent->{'id_agente'}, $alert->{'priority'}, $id, $alert->{'id_agent_module'}, $agent->{'id_agente'}, $alert->{'priority'}, $id, $alert->{'id_agent_module'},
"alert_recovered", $dbh); "alert_ceased", $dbh);
return; return;
} }
@ -434,6 +434,8 @@ sub pandora_execute_action ($$$$$$$$) {
_field2_ => $field2, _field2_ => $field2,
_field3_ => $field3, _field3_ => $field3,
_agent_ => (defined ($agent)) ? $agent->{'nombre'} : '', _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'} : '', _address_ => (defined ($agent)) ? $agent->{'direccion'} : '',
_timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()), _timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()),
_data_ => $data, _data_ => $data,
@ -443,6 +445,7 @@ sub pandora_execute_action ($$$$$$$$) {
_alert_times_fired_ => $alert->{'times_fired'}, _alert_times_fired_ => $alert->{'times_fired'},
_alert_priority_ => $alert->{'priority'}, _alert_priority_ => $alert->{'priority'},
_module_ => (defined ($module)) ? $module->{'nombre'} : '', _module_ => (defined ($module)) ? $module->{'nombre'} : '',
_moduledescription_ => (defined ($module)) ? $module->{'descripcion'} : '',
_id_agent_ => (defined ($module)) ? $module->{'id_agente'} : '', _id_agent_ => (defined ($module)) ? $module->{'id_agente'} : '',
); );
@ -451,6 +454,7 @@ sub pandora_execute_action ($$$$$$$$) {
if ($action->{'internal'} == 0) { if ($action->{'internal'} == 0) {
my $command = decode_entities(subst_alert_macros ($action->{'command'}, \%macros)); my $command = decode_entities(subst_alert_macros ($action->{'command'}, \%macros));
$command = subst_alert_macros ($command, \%macros); $command = subst_alert_macros ($command, \%macros);
logger($pa_config, "Executing command $command", 4);
eval { eval {
system ($command); system ($command);
@ -513,20 +517,27 @@ sub pandora_process_module ($$$$$$$$$) {
# Get module type # Get module type
if ($module_type eq '') { if ($module_type eq '') {
$module_type = get_db_value ($dbh, 'SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?', $module->{'id_tipo_modulo'}); $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 # Process data
$data = process_data ($data, $module, $module_type, $utimestamp, $dbh); $data = process_data ($data, $module, $module_type, $utimestamp, $dbh);
if (! defined ($data)) { if (! defined ($data)) {
logger($pa_config, "Received invalid data from module '" . $module->{'nombre'} . "'", 3); logger($pa_config, "Received invalid data from module '" . $module->{'nombre'} . "'", 3);
pandora_update_module_on_error ($pa_config, $module->{'id_agente_modulo'}, $dbh);
return; return;
} }
# Get agent information # Get agent information
if ($agent eq '') { if ($agent eq '') {
$agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); $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 '') { if ($timestamp eq '') {
@ -538,7 +549,10 @@ sub pandora_process_module ($$$$$$$$$) {
# Get previous status # Get previous status
my $agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'}); 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 # Get current status
my $status = get_module_status ($data, $module, $module_type); 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'}); $agent_status->{'last_try'} = '0000-00-00 00:00:00' unless defined ($agent_status->{'last_try'});
# Do we have to save module data? # 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 $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; 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) = @_; my ($pa_config, $dbh) = @_;
# Get alerts marked for forced execution (even disabled alerts) # 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.* my @alerts = get_db_rows ($dbh, 'SELECT * FROM talert_template_modules WHERE force_execution = 1');
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');
foreach my $alert (@alerts) { 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! # $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 # 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) = my ($times_fired, $internal_counter, $alert_type) =
($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'}); ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'});
# OID only # OID
if ($alert->{'alert_type'} == 0) { my $oid = $alert->{'oid'};
my $oid = $alert->{'oid'}; if ($oid ne '' && $trap_oid =~ m/$oid/i || $trap_oid_text =~ m/$oid/i) {
($fire_alert, $alert_data) = (1, 'SNMP/OID:' . $oid) if ($trap_oid =~ m/$oid/i || $fire_alert = 1;
$trap_oid_text =~ m/$oid/i); $alert_data) .= "OID: $oid ";
}
# Custom OID/value # Custom OID/value
} elsif ($alert_type == 1){ # type 1 is custom value my $custom_oid = $alert->{'custom_oid'};
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, $alert_data) = (1, 'SNMP/VALUE:' . $custom_oid) if ($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 # Agent IP
} else { my $agent = $alert->{'agent'};
my $agent = $alert->{'agent'}; if ($agent ne '' && $trap_agent =~ m/$agent/i ) {
($fire_alert, $alert_data) = (1, 'SNMP/SOURCE:' . $agent) if ($trap_agent =~ m/$agent/i ); $fire_alert = 1;
$alert_data .= "AGENT: $agent";
} }
next unless ($fire_alert == 1); next unless ($fire_alert == 1);

View File

@ -36,6 +36,7 @@ our @EXPORT = qw(
get_db_rows get_db_rows
get_db_single_row get_db_single_row
get_db_value get_db_value
get_group_name
get_module_id get_module_id
get_nc_profile_name get_nc_profile_name
get_server_id 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 ($$) { sub get_nc_profile_name ($$) {
my ($dbh, $nc_id) = @_; 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 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. ## Get a single column returned by an SQL query as a hash reference.
########################################################################## ##########################################################################

View File

@ -254,6 +254,9 @@ sub process_module_data ($$$$$$$$$) {
# Do not auto create modules # Do not auto create modules
return unless ($pa_config->{'autocreate'} == 1); return unless ($pa_config->{'autocreate'} == 1);
# Is the agent learning?
return unless ($agent->{'modo'} eq '1');
# Get the module type # Get the module type
my $module_id = get_module_id ($dbh, $module_type); my $module_id = get_module_id ($dbh, $module_type);
return unless ($module_id > 0); return unless ($module_id > 0);

View File

@ -168,7 +168,7 @@ sub data_consumer ($$) {
} }
# Check for errors # Check for errors
if ($output[0] =~ /ERROR/) { if ($output[0] =~ m/ERROR/) {
pandora_update_module_on_error ($pa_config, $module_id, $dbh); pandora_update_module_on_error ($pa_config, $module_id, $dbh);
return; return;
} }
@ -177,7 +177,11 @@ sub data_consumer ($$) {
my @row = split(/\|/, $output[2]); my @row = split(/\|/, $output[2]);
# Get the specified column # 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 # Regexp
if ($module->{'snmp_community'} ne ''){ if ($module->{'snmp_community'} ne ''){

View File

@ -342,7 +342,7 @@ sub pandora_loadconfig {
# Open database to get days_purge days_compact values # Open database to get days_purge days_compact values
my $query; my $query_ready; my @data; my $rows_selected; 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 = "select * from tconfig where token = 'days_purge'";
$query_ready = $dbh->prepare($query); $query_ready = $dbh->prepare($query);
$query_ready ->execute(); $query_ready ->execute();