diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 47c1c622ab..d1b4b6c66e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2011-12-12 Sergio Martin + + * lib/PandoraFMS/Tools.pm + util/pandora_db.pl: Moved is_policy_module function from + db script to Enteprise and call it through enterprise hook + 2011-12-05 Juan Manuel Ramon * pandora_server_upgrade: Removed rm of pandora_exec and diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index b8bfc3a18e..cbb1b7bd58 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -539,6 +539,8 @@ sub enterprise_hook ($$) { # Prepend the package name $func = 'PandoraFMS::Enterprise::' . $func; + + # undef is returned only if the enterprise function was not found return undef unless (defined (&$func)); # Try to call the function @@ -546,8 +548,6 @@ sub enterprise_hook ($$) { # Check for errors #return undef if ($@); - - # undef is returned only if the enterprise function was not found return '' unless defined ($output); return $output; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 14bfa19ac7..2ec86f6a2a 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -440,7 +440,8 @@ sub pandora_checkdb_consistency { my $id_agente_modulo = $module->{'id_agente_modulo'}; # Skip policy modules - next if (is_policy_module ($dbh, $id_agente_modulo)); + my $is_policy_module = enterprise_hook ('is_policy_module', [$dbh, $id_agente_modulo]); + next if (defined($is_policy_module) && $is_policy_module); # Delete the module db_do ($dbh, 'DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = ?', $id_agente_modulo);; @@ -456,7 +457,8 @@ sub pandora_checkdb_consistency { my $id_agente_modulo = $module->{'id_agente_modulo'}; # Skip policy modules - next if (is_policy_module ($dbh, $id_agente_modulo)); + my $is_policy_module = enterprise_hook ('is_policy_module', [$dbh, $id_agente_modulo]); + next if (defined($is_policy_module) && $is_policy_module); # Delete the module db_do ($dbh, 'DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = ?', $id_agente_modulo);; @@ -496,37 +498,6 @@ sub pandora_checkdb_consistency { } } -############################################################################### -# Returns undef if the given module is not a policy module. -############################################################################### -sub is_policy_module ($$) { - my ($dbh, $module_id) = @_; - - eval { - my $count = get_db_value ($dbh, 'SELECT COUNT(*) FROM tpolicies'); - }; - - # Not running Pandora FMS Enterprise - return undef if ($@); - - # Get agent id - my $agent_id = get_db_value ($dbh, 'SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ?', $module_id); - return undef unless defined ($agent_id); - - # Get module name - my $module_name = get_db_value ($dbh, 'SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ?', $module_id); - return undef unless defined ($module_name); - - # Search policies - my $policy_id = get_db_value ($dbh, '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 ?', $agent_id, $module_name); - - # Not a policy module - return undef unless defined ($policy_id); - - return $policy_id; -} - ############################################################################## # Print a help screen and exit. ##############################################################################