From 071bf227bf04e8f1195677076e5a0516a42d3760 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 6 Nov 2009 15:57:06 +0000 Subject: [PATCH] 2009-11-06 Ramon Novoa * lib/PandoraFMS/Tools.pm: Fixed bug #2893302. * util/pandora_db.pl: Fixed bug #2893303. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2090 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 +++ pandora_server/lib/PandoraFMS/Tools.pm | 4 +- pandora_server/util/pandora_db.pl | 60 +++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 242abf31e7..21d490619c 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2009-11-06 Ramon Novoa + + * lib/PandoraFMS/Tools.pm: Fixed bug #2893302. + + * util/pandora_db.pl: Fixed bug #2893303. + 2009-11-04 Ramon Novoa * lib/PandoraFMS/Core.pm: Fixed a typo. diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 011f314a60..b5f7ac6769 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -21,7 +21,7 @@ use warnings; use Time::Local; use POSIX qw(setsid strftime); use Mail::Sendmail; # New in 2.0. Used to sendmail internally, without external scripts -use Module::Loaded; +#use Module::Loaded; require Exporter; @@ -339,7 +339,7 @@ sub float_equal { sub enterprise_load () { # Already loaded - return 1 if (is_loaded ('PandoraFMS::Enterprise')); + #return 1 if (is_loaded ('PandoraFMS::Enterprise')); # Try to load the module eval 'local $SIG{__DIE__}; require PandoraFMS::Enterprise;'; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index b34aff13b9..f926dcd7cf 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -171,8 +171,8 @@ sub pandora_compactdb { } # Calculate the start date - my $start_date = DateCalc("today","-$days days",\$err); - my $start_utime = &UnixDate($start_date,"%s"); + my $start_utime = time() - $days * 24 * 60 * 60; + my $start_date = strftime ("%Y-%m-%d %H:%M:%S", localtime($start_utime)); my $stop_date; my $stop_utime; @@ -413,10 +413,21 @@ sub pandora_checkdb_consistency { # for each record in tagente_modulo while (@datarow4 = $prep4->fetchrow_array()) { my $id_agente_modulo = $datarow4[1]; + + # Skip policy modules + next if (is_policy_module ($dbh, $id_agente_modulo)); + + # Delete the module my $query0 = "DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = $id_agente_modulo"; my $prep0 = $dbh->prepare($query0); $prep0 ->execute; $prep0->finish(); + + # Delete any alerts associated to the module + $query0 = "DELETE FROM talert_template_modules WHERE id_agent_module = $id_agente_modulo"; + $prep0 = $dbh->prepare($query0); + $prep0 ->execute; + $prep0->finish(); } } $prep4->finish(); @@ -480,6 +491,51 @@ sub pandora_checkdb_consistency { } +############################################################################### +# Returns undef if the module is not a policy module. +############################################################################### +sub is_policy_module ($$) { + my ($dbh, $module_id) = @_; + my ($agent_id, $module_name, $policy_id) = (undef, undef, undef); + + # Get agent id + my $sth = $dbh->prepare('SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ?'); + $sth->execute ($module_id); + while (my @row = $sth->fetchrow_array()) { + $agent_id = $row[0]; + last; + } + $sth->finish(); + return unless defined ($agent_id); + + # Get module name + $sth = $dbh->prepare('SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ?'); + $sth->execute ($module_id); + while (my @row = $sth->fetchrow_array()) { + $module_name = $row[0]; + last; + } + $sth->finish(); + return unless defined ($module_name); + + # Search policies + $sth = $dbh->prepare('SELECT t3.id FROM tpolicy_agents AS t1 + INNER JOIN tpolicy_modules AS t2 ON t1.id_policy = t2.id_policy + INNER JOIN tpolicies AS t3 ON t1.id_policy = t3.id + WHERE t1.id_agent = ? AND t2.name LIKE ?'); + $sth->execute ($agent_id, $module_name); + while (my @row = $sth->fetchrow_array()) { + $policy_id = $row[0]; + last; + } + $sth->finish(); + + # Not a policy module + return undef unless defined ($policy_id); + + return $policy_id; +} + ############################################################################## # SUB help_screen() # Show a help screen an exits