From 8d39ad6884ee9f6238abda44a0f250e4b10cfcdd Mon Sep 17 00:00:00 2001 From: koichirok Date: Tue, 29 May 2012 07:12:09 +0000 Subject: [PATCH] 2012-05-29 Koichiro Kikuchi * util/pandora_db.pl: Don't delete non-initialized modules which belong to disabled agent. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6353 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/util/pandora_db.pl | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 974a7a8436..d3bc6284a1 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2012-05-29 Koichiro Kikuchi + + * util/pandora_db.pl: Don't delete non-initialized modules which + belong to disabled agent. + 2012-05-21 Sergio Martin * lib/PandoraFMS/Core.pm: Added new Internal Command for diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index cb4ae42213..be627b0ab0 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -457,7 +457,7 @@ sub pandora_checkdb_consistency { # 1. Check for modules that do not have tagente_estado but have tagente_module print "[CHECKDB] Deleting non-init data... \n"; - my @modules = get_db_rows ($dbh, 'SELECT id_agente_modulo FROM tagente_estado WHERE utimestamp = 0'); + my @modules = get_db_rows ($dbh, 'SELECT id_agente_modulo,id_agente FROM tagente_estado WHERE utimestamp = 0'); foreach my $module (@modules) { my $id_agente_modulo = $module->{'id_agente_modulo'}; @@ -465,11 +465,19 @@ sub pandora_checkdb_consistency { my $is_policy_module = enterprise_hook ('is_policy_module', [$dbh, $id_agente_modulo]); next if (defined($is_policy_module) && $is_policy_module); + # Skip if agent is disabled + my $is_agent_disabled = get_db_value ($dbh, 'SELECT disabled FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); + next if (defined($is_agent_disabled) && $is_agent_disabled); + + # Skip if module is disabled + my $is_module_disabled = get_db_value ($dbh, 'SELECT disabled FROM tagente_modulo WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'}); + next if (defined($is_module_disabled) && $is_module_disabled); + # Delete the module - db_do ($dbh, 'DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = ?', $id_agente_modulo);; + db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agente_modulo); # Delete any alerts associated to the module - db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ? AND NOT EXISTS (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente_modulo = ?)', $id_agente_modulo, $id_agente_modulo); + db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $id_agente_modulo); } print "[CHECKDB] Deleting unknown data (More than " . $conf{'_days_delete_unknown'} . " days)... \n";