From dcb04a64ee06c24503354f8f13e7f769658fda62 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 29 Nov 2023 14:30:45 +0100 Subject: [PATCH] fix delete conf agents pandora_enterprise#12293 --- pandora_server/util/pandora_db.pl | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index c7be6a3e1c..44b6d7d695 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -330,14 +330,22 @@ sub pandora_purgedb ($$$) { AND id_rc NOT IN (SELECT id_report_content FROM treport_content_sla_combined)"); } - - # Delete disabled autodisable agents after some period - log_message ('PURGE', 'Delete autodisabled agents where last contact is bigger than ' . $conf->{'_days_autodisable_deletion'} . ' days.'); - db_do ($dbh, "DELETE FROM tagente - WHERE UNIX_TIMESTAMP(ultimo_contacto) + ? < UNIX_TIMESTAMP(NOW()) - AND disabled=1 - AND modo=2", $conf->{'_days_autodisable_deletion'}*8600); - + # Delete disabled autodisable agents after some period + if (defined ($conf->{'_days_autodisable_deletion'}) && $conf->{'_days_autodisable_deletion'} > 0) { + log_message ('PURGE', 'Delete autodisabled agents where last contact is bigger than ' . $conf->{'_days_autodisable_deletion'} . ' days.'); + my @agents_autodisable_to_delete = get_db_rows ( + $dbh, + "SELECT id_agente FROM tagente + WHERE UNIX_TIMESTAMP(ultimo_contacto) + ? < UNIX_TIMESTAMP(NOW()) + AND disabled = 1 + AND modo = 2", + $conf->{'_days_autodisable_deletion'} * 8600 + ); + + foreach my $agents_autodisable_to_delete (@agents_to_delete) { + pandora_delete_agent($dbh, $agent_to_delete->{'id_agente'}); + } + } # Delete old netflow data if (!defined($conf->{'_netflow_max_lifetime'})){