diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 4d0648f19f..3ea2b67cb8 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2011-05-23 Sergio Martin + + * lib/PandoraFMS/DB.pm + lib/PandoraFMS/Core.pm + util/pandora_db.pl + util/pandora_manage.pl: Added minor functions and fixes to policy queue + and call to clean policy queue in maintenance script + 2011-05-12 Sergio Martin * util/pandora_manage.pl: Added check of the returning of add diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 96e01c46ec..4c9671e032 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1212,8 +1212,8 @@ sub pandora_create_module ($$$$$$$$$$) { ########################################################################## ## Delete a module given its id. ########################################################################## -sub pandora_delete_module ($$) { - my ($dbh, $module_id) = @_; +sub pandora_delete_module ($$;$) { + my ($dbh, $module_id, $conf) = @_; # Delete Graphs, layouts & reports db_do ($dbh, 'DELETE FROM tgraph_source WHERE id_agent_module = ?', $module_id); @@ -1228,6 +1228,15 @@ sub pandora_delete_module ($$) { # Set pending delete the module db_do ($dbh, 'UPDATE tagente_modulo SET disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ?', $module_id); + + my $agent_id = get_module_agent_id($dbh, $module_id); + + my $agent_name = get_agent_name($dbh, $agent_id); + my $module_name = get_module_name($dbh, $module_id); + + if ((-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') && (defined($conf))) { + enterprise_hook('pandora_delete_module_from_conf', [$conf,$agent_name,$module_name]); + } } ########################################################################## @@ -2102,8 +2111,8 @@ sub pandora_process_policy_queue ($) { $operation = @{$operation}[0]; if(defined($operation)) { - if($operation->{'operation'} eq 'apply') { - enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}]); + if($operation->{'operation'} eq 'apply' || $operation->{'operation'} eq 'apply_db') { + enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}, $operation->{'operation'}]); } elsif($operation->{'operation'} eq 'delete') { if($operation->{'id_agent'} == 0) { diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 941f322ad6..bd2d13a96d 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -49,6 +49,7 @@ our @EXPORT = qw( get_db_value get_group_id get_group_name + get_module_agent_id get_module_group_id get_module_id get_module_name @@ -178,6 +179,16 @@ sub get_agent_name ($$) { return get_db_value ($dbh, "SELECT nombre FROM tagente WHERE id_agente = ?", $agent_id); } +########################################################################## +## SUB get_module_agent_id (agent_module_id) +## Return agent id, given "agent_module_id" +########################################################################## +sub get_module_agent_id ($$) { + my ($dbh, $agent_module_id) = @_; + + return get_db_value ($dbh, "SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ?", $agent_module_id); +} + ########################################################################## ## SUB get_agent_address (id_agente) ## Return agent address, given "agent_id" @@ -204,7 +215,7 @@ sub get_module_name ($$) { sub get_agent_module_id ($$$) { my ($dbh, $module_name, $agent_id) = @_; - my $rc = get_db_value ($dbh, "SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = ? AND id_agente = ?", safe_input(safe_output($module_name)), $agent_id); + my $rc = get_db_value ($dbh, "SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0 AND nombre = ? AND id_agente = ?", safe_input(safe_output($module_name)), $agent_id); return defined ($rc) ? $rc : -1; } diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 5e76d92bac..53b6e7b93e 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -176,6 +176,9 @@ sub pandora_purgedb ($$) { my $trap_limit = time() - 86400 * $conf->{'_trap_purge'}; $trap_limit = strftime ("%Y-%m-%d %H:%M:%S", localtime($trap_limit)); db_do($dbh, "DELETE FROM ttrap WHERE timestamp < '$trap_limit'"); + + # Delete policy queue data + enterprise_hook("pandora_purge_policy_queue", [$dbh, $conf]); # Delete GIS data if (!defined($conf->{'_gis_purge'})){ diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 07cd2871bc..8a6270b9af 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -866,12 +866,7 @@ sub pandora_manage_main ($$$) { my $id_module = get_agent_module_id($dbh,$module_name,$id_agent); exist_check($id_module,'module',$module_name); - pandora_delete_module($dbh,$id_module); - - if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { - enterprise_hook('pandora_delete_module_from_conf', [$conf,$agent_name,$module_name]); - } - + pandora_delete_module($dbh,$id_module,$conf); } elsif ($param eq '--delete_not_policy_modules') { param_check($ltotal, 0);