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 c92437517a
commit 54903089c9
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> 2011-05-12 Sergio Martin <sergio.martin@artica.es>
* util/pandora_manage.pl: Added check of the returning of add * 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. ## Delete a module given its id.
########################################################################## ##########################################################################
sub pandora_delete_module ($$) { sub pandora_delete_module ($$;$) {
my ($dbh, $module_id) = @_; my ($dbh, $module_id, $conf) = @_;
# Delete Graphs, layouts & reports # Delete Graphs, layouts & reports
db_do ($dbh, 'DELETE FROM tgraph_source WHERE id_agent_module = ?', $module_id); 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 # Set pending delete the module
db_do ($dbh, 'UPDATE tagente_modulo SET disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ?', $module_id); 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]; $operation = @{$operation}[0];
if(defined($operation)) { if(defined($operation)) {
if($operation->{'operation'} eq 'apply') { 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'}]); enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}, $operation->{'operation'}]);
} }
elsif($operation->{'operation'} eq 'delete') { elsif($operation->{'operation'} eq 'delete') {
if($operation->{'id_agent'} == 0) { if($operation->{'id_agent'} == 0) {

View File

@ -49,6 +49,7 @@ our @EXPORT = qw(
get_db_value get_db_value
get_group_id get_group_id
get_group_name get_group_name
get_module_agent_id
get_module_group_id get_module_group_id
get_module_id get_module_id
get_module_name 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); 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) ## SUB get_agent_address (id_agente)
## Return agent address, given "agent_id" ## Return agent address, given "agent_id"
@ -204,7 +215,7 @@ sub get_module_name ($$) {
sub get_agent_module_id ($$$) { sub get_agent_module_id ($$$) {
my ($dbh, $module_name, $agent_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; return defined ($rc) ? $rc : -1;
} }

View File

@ -176,6 +176,9 @@ sub pandora_purgedb ($$) {
my $trap_limit = time() - 86400 * $conf->{'_trap_purge'}; my $trap_limit = time() - 86400 * $conf->{'_trap_purge'};
$trap_limit = strftime ("%Y-%m-%d %H:%M:%S", localtime($trap_limit)); $trap_limit = strftime ("%Y-%m-%d %H:%M:%S", localtime($trap_limit));
db_do($dbh, "DELETE FROM ttrap WHERE timestamp < '$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 # Delete GIS data
if (!defined($conf->{'_gis_purge'})){ 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); my $id_module = get_agent_module_id($dbh,$module_name,$id_agent);
exist_check($id_module,'module',$module_name); exist_check($id_module,'module',$module_name);
pandora_delete_module($dbh,$id_module); pandora_delete_module($dbh,$id_module,$conf);
if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') {
enterprise_hook('pandora_delete_module_from_conf', [$conf,$agent_name,$module_name]);
}
} }
elsif ($param eq '--delete_not_policy_modules') { elsif ($param eq '--delete_not_policy_modules') {
param_check($ltotal, 0); param_check($ltotal, 0);