Merge branch 'ent-8745-Tiempo_no_inicializados_entorno' into 'develop'
Added control for clean not initialized modules See merge request artica/pandorafms!5073
This commit is contained in:
commit
56f5001541
|
@ -340,8 +340,19 @@ $table->data[8][1] = html_print_input_text(
|
|||
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(
|
||||
'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',
|
||||
$config['days_autodisable_deletion'],
|
||||
'',
|
||||
|
@ -350,8 +361,8 @@ $table->data[9][1] = html_print_input_text(
|
|||
true
|
||||
);
|
||||
|
||||
$table->data[10][0] = __('Retention period of past special days');
|
||||
$table->data[10][1] = html_print_input_text(
|
||||
$table->data[11][0] = __('Retention period of past special days');
|
||||
$table->data[11][1] = html_print_input_text(
|
||||
'num_past_special_days',
|
||||
$config['num_past_special_days'],
|
||||
'',
|
||||
|
@ -360,8 +371,8 @@ $table->data[10][1] = html_print_input_text(
|
|||
true
|
||||
);
|
||||
|
||||
$table->data[11][0] = __('Max. macro data fields');
|
||||
$table->data[11][1] = html_print_input_text(
|
||||
$table->data[12][0] = __('Max. macro data fields');
|
||||
$table->data[12][1] = html_print_input_text(
|
||||
'max_macro_fields',
|
||||
$config['max_macro_fields'],
|
||||
'',
|
||||
|
@ -374,8 +385,8 @@ $table->data[11][1] = html_print_input_text(
|
|||
);
|
||||
|
||||
if (enterprise_installed()) {
|
||||
$table->data[12][0] = __('Max. days before delete inventory data');
|
||||
$table->data[12][1] = html_print_input_text(
|
||||
$table->data[13][0] = __('Max. days before delete inventory data');
|
||||
$table->data[13][1] = html_print_input_text(
|
||||
'inventory_purge',
|
||||
$config['inventory_purge'],
|
||||
'',
|
||||
|
|
|
@ -816,6 +816,10 @@ function config_update_config()
|
|||
$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) {
|
||||
$error_update[] = __('Max. days before compact data');
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
|
|||
('block_size','20'),
|
||||
('days_purge','45'),
|
||||
('days_delete_unknown','0'),
|
||||
('days_delete_not_initialized','0'),
|
||||
('days_compact','0'),
|
||||
('days_autodisable_deletion','30'),
|
||||
('graph_res','5'),
|
||||
|
|
|
@ -648,6 +648,8 @@ 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_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_not_initialized'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'days_delete_not_initialized'");
|
||||
$conf->{'_delete_notinit'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_notinit'");
|
||||
$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_network_matrix'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_old_network_matrix'");
|
||||
|
@ -836,6 +838,58 @@ sub pandora_checkdb_consistency {
|
|||
usleep (100000);
|
||||
}
|
||||
}
|
||||
|
||||
# Perform a clean of not initialized modules.
|
||||
if (defined($conf{'_days_delete_not_initialized'}) && $conf{'_days_delete_not_initialized'} > 0 && $conf->{'_delete_notinit'} eq "1") {
|
||||
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',
|
||||
"Checking database consistency (Missing status).");
|
||||
|
||||
|
|
Loading…
Reference in New Issue