Added control for clean not initialized modules

This commit is contained in:
José González 2022-08-29 14:05:30 +02:00
parent 8b805e0ddf
commit b07a161fb0
4 changed files with 76 additions and 7 deletions

View File

@ -340,8 +340,19 @@ $table->data[8][1] = html_print_input_text(
true true
); );
$table->data[9][0] = __('Max. days before delete autodisabled agents');
$table->data[9][0] = __('Max. days before delete not initialized modules');
$table->data[9][1] = html_print_input_text( $table->data[9][1] = html_print_input_text(
'days_delete_not_initialized',
$config['days_delete_not_initialized'],
'',
5,
5,
true
);
$table->data[10][0] = __('Max. days before delete autodisabled agents');
$table->data[10][1] = html_print_input_text(
'days_autodisable_deletion', 'days_autodisable_deletion',
$config['days_autodisable_deletion'], $config['days_autodisable_deletion'],
'', '',
@ -350,8 +361,8 @@ $table->data[9][1] = html_print_input_text(
true true
); );
$table->data[10][0] = __('Retention period of past special days'); $table->data[11][0] = __('Retention period of past special days');
$table->data[10][1] = html_print_input_text( $table->data[11][1] = html_print_input_text(
'num_past_special_days', 'num_past_special_days',
$config['num_past_special_days'], $config['num_past_special_days'],
'', '',
@ -360,8 +371,8 @@ $table->data[10][1] = html_print_input_text(
true true
); );
$table->data[11][0] = __('Max. macro data fields'); $table->data[12][0] = __('Max. macro data fields');
$table->data[11][1] = html_print_input_text( $table->data[12][1] = html_print_input_text(
'max_macro_fields', 'max_macro_fields',
$config['max_macro_fields'], $config['max_macro_fields'],
'', '',
@ -374,8 +385,8 @@ $table->data[11][1] = html_print_input_text(
); );
if (enterprise_installed()) { if (enterprise_installed()) {
$table->data[12][0] = __('Max. days before delete inventory data'); $table->data[13][0] = __('Max. days before delete inventory data');
$table->data[12][1] = html_print_input_text( $table->data[13][1] = html_print_input_text(
'inventory_purge', 'inventory_purge',
$config['inventory_purge'], $config['inventory_purge'],
'', '',

View File

@ -816,6 +816,10 @@ function config_update_config()
$error_update[] = __('Max. days before delete unknown modules'); $error_update[] = __('Max. days before delete unknown modules');
} }
if (config_update_value('days_delete_not_initialized', (int) get_parameter('days_delete_not_initialized'), true) === false) {
$error_update[] = __('Max. days before delete not initialized modules');
}
if (config_update_value('days_compact', (int) get_parameter('days_compact'), true) === false) { if (config_update_value('days_compact', (int) get_parameter('days_compact'), true) === false) {
$error_update[] = __('Max. days before compact data'); $error_update[] = __('Max. days before compact data');
} }

View File

@ -37,6 +37,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('block_size','20'), ('block_size','20'),
('days_purge','45'), ('days_purge','45'),
('days_delete_unknown','0'), ('days_delete_unknown','0'),
('days_delete_not_initialized','0'),
('days_compact','0'), ('days_compact','0'),
('days_autodisable_deletion','30'), ('days_autodisable_deletion','30'),
('graph_res','5'), ('graph_res','5'),

View File

@ -648,6 +648,7 @@ sub pandora_load_config_pdb ($) {
$conf->{'_history_db_step'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_step'"); $conf->{'_history_db_step'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_step'");
$conf->{'_history_db_delay'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_delay'"); $conf->{'_history_db_delay'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_delay'");
$conf->{'_days_delete_unknown'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'days_delete_unknown'"); $conf->{'_days_delete_unknown'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'days_delete_unknown'");
$conf->{'_days_delete_not_initialized'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'days_delete_not_initialized'");
$conf->{'_inventory_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'inventory_purge'"); $conf->{'_inventory_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'inventory_purge'");
$conf->{'_delete_old_messages'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_old_messages'"); $conf->{'_delete_old_messages'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_old_messages'");
$conf->{'_delete_old_network_matrix'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_old_network_matrix'"); $conf->{'_delete_old_network_matrix'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_old_network_matrix'");
@ -836,6 +837,58 @@ sub pandora_checkdb_consistency {
usleep (100000); usleep (100000);
} }
} }
# Perform a clean of not initialized modules.
if (defined($conf{'_days_delete_not_initialized'}) && $conf{'_days_delete_not_initialized'} > 0) {
log_message ('CHECKDB',
"Deleting not initialized modules (More than " . $conf{'_days_delete_not_initialized'} . " days).");
my @modules = get_db_rows($dbh,
'SELECT tagente_modulo.id_agente_modulo, tagente_modulo.id_agente
FROM tagente_modulo, tagente_estado
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND (estado = 4 OR estado = 5)
AND utimestamp < UNIX_TIMESTAMP() - ?',
86400 * $conf{'_days_delete_not_initialized'});
foreach my $module (@modules) {
my $id_agente = $module->{'id_agente'};
my $id_agente_modulo = $module->{'id_agente_modulo'};
# Skip policy modules
my $is_policy_module = enterprise_hook('is_policy_module',
[$dbh, $id_agente_modulo]);
next if (defined($is_policy_module) && $is_policy_module);
# Mark the agent for module and alert counters update
db_do ($dbh,
'UPDATE tagente
SET update_module_count = 1, update_alert_count = 1
WHERE id_agente = ?', $id_agente);
# Delete the module
db_do ($dbh,
'DELETE FROM tagente_modulo
WHERE disabled = 0
AND id_agente_modulo = ?', $id_agente_modulo);
# Do a nanosleep here for 0,001 sec
usleep (100000);
# Delete any alerts associated to the module
db_do ($dbh, 'DELETE FROM talert_template_modules
WHERE id_agent_module = ?
AND NOT EXISTS (SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ?)',
$id_agente_modulo, $id_agente_modulo);
# Do a nanosleep here for 0,001 sec
usleep (100000);
}
}
log_message ('CHECKDB', log_message ('CHECKDB',
"Checking database consistency (Missing status)."); "Checking database consistency (Missing status).");