traps history
This commit is contained in:
parent
230494ffca
commit
9343796ae1
|
@ -1590,6 +1590,14 @@ function config_update_config()
|
|||
$error_update[] = __('Trap Days');
|
||||
}
|
||||
|
||||
$trap_history_purge = get_parameter('history_traps_days_purge');
|
||||
if (is_numeric($trap_history_purge) === false
|
||||
|| $trap_history_purge <= 0
|
||||
|| config_update_value('trap_history_purge', $trap_history_purge) === false
|
||||
) {
|
||||
$error_update[] = __('Trap history purge');
|
||||
}
|
||||
|
||||
$history_db_step = get_parameter('history_db_step');
|
||||
if (!is_numeric($history_db_step)
|
||||
|| $history_db_step <= 0
|
||||
|
@ -1655,8 +1663,8 @@ function config_update_config()
|
|||
}
|
||||
|
||||
if ($dbm->setConfigToken(
|
||||
'trap_purge',
|
||||
get_parameter('history_dbh_traps_purge')
|
||||
'trap_history_purge',
|
||||
get_parameter('history_traps_days_purge')
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database traps purge');
|
||||
|
@ -2532,6 +2540,10 @@ function config_process_config()
|
|||
config_update_value('history_trap_days', 90);
|
||||
}
|
||||
|
||||
if (!isset($config['trap_history_purge'])) {
|
||||
config_update_value('trap_history_purge', 180);
|
||||
}
|
||||
|
||||
if (!isset($config['history_db_step'])) {
|
||||
config_update_value('history_db_step', 0);
|
||||
}
|
||||
|
|
|
@ -628,6 +628,7 @@ sub pandora_load_config_pdb ($) {
|
|||
|
||||
$conf->{'_event_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'event_purge'");
|
||||
$conf->{'_trap_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'trap_purge'");
|
||||
$conf->{'_trap_history_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'trap_purge'");
|
||||
$conf->{'_audit_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'audit_purge'");
|
||||
$conf->{'_string_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'string_purge'");
|
||||
$conf->{'_gis_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'gis_purge'");
|
||||
|
@ -1104,6 +1105,26 @@ sub pandoradb_history ($$) {
|
|||
log_message ('', "\n");
|
||||
}
|
||||
|
||||
# Delete old traps.
|
||||
if ($conf->{'_trap_history_purge'} > 0) {
|
||||
log_message ('PURGE', "Deleting traps older than " . $conf->{'_trap_history_purge'} . " days from ttrap (history).", '');
|
||||
|
||||
my $trap_limit = strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - 86400 * $conf->{'_trap_history_purge'}));
|
||||
|
||||
my $traps_to_delete = get_db_value ($dbh, "SELECT COUNT(*) FROM ttrap WHERE timestamp < ?", $trap_limit);
|
||||
while($traps_to_delete > 0) {
|
||||
db_delete_limit($dbh, 'ttrap', "timestamp < ?", $BIG_OPERATION_STEP, $trap_limit);
|
||||
$traps_to_delete = $traps_to_delete - $BIG_OPERATION_STEP;
|
||||
|
||||
# Mark the progress.
|
||||
log_message ('', ".");
|
||||
|
||||
# Do not overload the MySQL server.
|
||||
usleep (10000);
|
||||
}
|
||||
log_message ('', "\n");
|
||||
}
|
||||
|
||||
# Update tconfig with last time of database maintance time (now)
|
||||
db_do ($dbh, "DELETE FROM tconfig WHERE token = 'db_maintance'");
|
||||
db_do ($dbh, "INSERT INTO tconfig (token, value) VALUES ('db_maintance', '".time()."')");
|
||||
|
|
Loading…
Reference in New Issue