diff --git a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php index 72578868e7..e03cfa9bb9 100755 --- a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php +++ b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php @@ -76,6 +76,7 @@ if ($generate_trap) { ); } +$table = new stdClass(); $traps_generator = '
'; $table->width = '100%'; $table->class = 'databox filters'; diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 866a023f26..6870f9ae30 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1567,6 +1567,10 @@ function config_update_config() $error_update[] = __('Enable history event'); } + if (config_update_value('history_trap_enabled', get_parameter('history_trap_enabled'), true) === false) { + $error_update[] = __('Enable history trap'); + } + if (config_update_value('history_db_user', get_parameter('history_db_user'), true) === false) { $error_update[] = __('Database user'); } @@ -1604,6 +1608,22 @@ function config_update_config() $error_update[] = __('Event Days'); } + $history_trap_days = get_parameter('history_trap_days'); + if (is_numeric($history_trap_days) === false + || $history_trap_days <= 0 + || config_update_value('history_trap_days', $history_trap_days) === false + ) { + $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 @@ -1668,6 +1688,14 @@ function config_update_config() $error_update[] = __('Historical database events purge'); } + if ($dbm->setConfigToken( + 'trap_history_purge', + get_parameter('history_traps_days_purge') + ) !== true + ) { + $error_update[] = __('Historical database traps purge'); + } + if ($dbm->setConfigToken( 'string_purge', get_parameter('history_dbh_string_purge') @@ -2528,6 +2556,10 @@ function config_process_config() config_update_value('history_event_enabled', false); } + if (!isset($config['history_trap_enabled'])) { + config_update_value('history_trap_enabled', false); + } + if (!isset($config['history_db_host'])) { config_update_value('history_db_host', ''); } @@ -2564,6 +2596,14 @@ function config_process_config() config_update_value('history_event_days', 90); } + if (!isset($config['history_trap_days'])) { + 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); } diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0e859e6577..ebc5ccdbfc 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -631,6 +631,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'"); @@ -641,6 +642,7 @@ sub pandora_load_config_pdb ($) { $conf->{'_step_compact'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'step_compact'"); $conf->{'_history_db_enabled'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_enabled'"); $conf->{'_history_event_enabled'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_event_enabled'"); + $conf->{'_history_trap_enabled'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_trap_enabled'"); $conf->{'_history_db_host'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_host'"); $conf->{'_history_db_port'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_port'"); $conf->{'_history_db_name'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_name'"); @@ -650,6 +652,7 @@ sub pandora_load_config_pdb ($) { $conf->{'_history_db_adv'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_adv'"); $conf->{'_history_db_string_days'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_string_days'"); $conf->{'_history_event_days'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_event_days'"); + $conf->{'_history_trap_days'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_trap_days'"); $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'"); @@ -1119,6 +1122,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()."')"); @@ -1149,6 +1172,9 @@ sub pandoradb_main { if (defined($conf{'_history_event_enabled'}) && $conf->{'_history_event_enabled'} ne "" && $conf->{'_history_event_enabled'} == 1) { undef ($history_dbh) unless defined (enterprise_hook ('pandora_history_event', [$dbh, $history_dbh, $conf->{'_history_event_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); } + if (defined($conf{'_history_trap_enabled'}) && $conf->{'_history_trap_enabled'} ne "" && $conf->{'_history_trap_enabled'} == 1) { + undef ($history_dbh) unless defined (enterprise_hook ('pandora_history_trap', [$dbh, $history_dbh, $conf->{'_history_trap_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); + } } # Only active database should be compacted. Disabled for historical database.