From 91194155b09abcdaa9b7fdf3caf7a38595cd56f4 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 19 Sep 2022 11:15:22 +0200 Subject: [PATCH] implemented trap history --- .../snmpconsole/snmp_trap_generator.php | 1 + pandora_console/include/functions_config.php | 28 +++++++++++++++++++ pandora_server/util/pandora_db.pl | 11 ++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) 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 fbe12e27f8..65bb579f09 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1554,6 +1554,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'); } @@ -1578,6 +1582,14 @@ 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'); + } + $history_db_step = get_parameter('history_db_step'); if (!is_numeric($history_db_step) || $history_db_step <= 0 @@ -1642,6 +1654,14 @@ function config_update_config() $error_update[] = __('Historical database events purge'); } + if ($dbm->setConfigToken( + 'trap_purge', + get_parameter('history_dbh_traps_purge') + ) !== true + ) { + $error_update[] = __('Historical database traps purge'); + } + if ($dbm->setConfigToken( 'string_purge', get_parameter('history_dbh_string_purge') @@ -2476,6 +2496,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', ''); } @@ -2504,6 +2528,10 @@ 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['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 2c498d6d0f..b92d027dab 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -638,6 +638,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'"); @@ -645,6 +646,7 @@ sub pandora_load_config_pdb ($) { $conf->{'_history_db_pass'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_pass'"); $conf->{'_history_db_days'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'history_db_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'"); @@ -1128,9 +1130,12 @@ sub pandoradb_main ($$$;$) { # Move old data to the history DB if (defined ($history_dbh)) { - undef ($history_dbh) unless defined (enterprise_hook ('pandora_historydb', [$dbh, $history_dbh, $conf->{'_history_db_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); - 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'}])); + #undef ($history_dbh) unless defined (enterprise_hook ('pandora_historydb', [$dbh, $history_dbh, $conf->{'_history_db_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); + #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'}])); } }