2011-05-23 Sergio Martin <sergio.martin@artica.es>

* 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



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4374 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2011-05-23 11:55:08 +00:00
parent 5bc819eaeb
commit 8c9c68cd84
5 changed files with 37 additions and 11 deletions

View File

@ -1,3 +1,11 @@
2011-05-23 Sergio Martin <sergio.martin@artica.es>
* 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 <sergio.martin@artica.es>
* util/pandora_manage.pl: Added check of the returning of add

View File

@ -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) {

View File

@ -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;
}

View File

@ -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'})){

View File

@ -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);