From a767b6c13374e729a1afd084e50acc7c15e22e48 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 23 Nov 2020 20:16:11 +0100 Subject: [PATCH 1/2] Fixes in history db settings and improved pandora_db tool --- pandora_console/godmode/setup/performance.php | 7 +-- pandora_server/util/pandora_db.pl | 54 ++++++++++++++++--- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 096defb664..bc79631697 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -64,7 +64,7 @@ if ($update_config == 1 && $config['history_db_enabled'] == 1) { $historical_string_purge = get_parameter('historical_string_purge', 0); $history_connect = @mysql_db_process_sql( - 'SELECT 1 FROM tconfig', + 'DESCRIBE tconfig', 'affected_rows', $config['history_db_connection'], false @@ -390,8 +390,8 @@ if ($config['history_db_enabled'] == 1) { $config_history = false; if ($config['history_db_connection']) { - $history_connect = @mysql_db_process_sql( - 'SELECT 1 FROM tconfig', + $history_connect = mysql_db_process_sql( + 'DESCRIBE tconfig', 'affected_rows', $config['history_db_connection'], false @@ -408,6 +408,7 @@ if ($config['history_db_enabled'] == 1) { if (isset($config_history_array) && is_array($config_history_array)) { foreach ($config_history_array as $key => $value) { $config_history[$value['token']] = $value['value']; + $config_history = true; } } } else { diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 2c55dbf933..4cac97dd34 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -581,6 +581,28 @@ sub pandora_init_pdb ($) { help_screen () if ($conf->{'_pandora_path'} eq ''); } +######################################################################## +# Prepares conf read from historical database settings. +######################################################################## +sub pandoradb_load_history_conf($) { + my $dbh = shift; + + my @options = get_db_rows($dbh, 'SELECT * FROM `tconfig`'); + + my %options = map + { + '_' . $_->{'token'} => $_->{'value'} + } @options; + + $options{'_days_autodisable_deletion'} = 0 unless defined ($options{'_days_autodisable_deletion'}); + $options{'_num_past_special_days'} = 0 unless defined($options{'_num_past_special_days'}); + $options{'_delete_old_network_matrix'} = 0 unless defined($options{'_delete_old_network_matrix'}); + $options{'_delete_old_messages'} = 0 unless defined($options{'_delete_old_messages'}); + $options{'_netflow_max_lifetime'} = 0 unless defined($options{'_netflow_max_lifetime'}); + $options{'claim_back_snmp_modules'} = 0 unless defined($options{'claim_back_snmp_modules'}); + + return \%options; +} ######################################################################## # Read external configuration file. @@ -651,7 +673,7 @@ sub pandora_load_config_pdb ($) { $conf->{'_metaconsole_events_history'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'metaconsole_events_history'"); $conf->{'_netflow_max_lifetime'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_max_lifetime'"); $conf->{'_netflow_nfexpire'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_nfexpire'"); - $conf->{'_netflow_path'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_path'"); + $conf->{'_netflow_path'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_path'"); $conf->{'_delete_notinit'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_notinit'"); $conf->{'_session_timeout'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'session_timeout'"); @@ -726,7 +748,7 @@ sub pandora_checkdb_consistency { # 1. Check for modules that do not have tagente_estado but have # tagente_module #------------------------------------------------------------------- - if (defined($conf->{'_delete_notinit'}) && $conf->{'_delete_notinit'} == 1) { + if (defined($conf->{'_delete_notinit'}) && $conf->{'_delete_notinit'} eq "1") { log_message ('CHECKDB', "Deleting not-init data."); my @modules = get_db_rows ($dbh, 'SELECT id_agente_modulo, id_agente @@ -956,7 +978,7 @@ sub pandora_delete_old_module_data { sub pandora_delete_old_export_data { my ($dbh, $ulimit_timestamp) = @_; - log_message ('PURGE', "Deleting old export data from tserver_export_data\n"); + log_message ('PURGE', "Deleting old export data from tserver_export_data"); while((my $rc = db_delete_limit ($dbh, 'tserver_export_data', 'UNIX_TIMESTAMP(timestamp) < ?', $SMALL_OPERATION_STEP, $ulimit_timestamp)) ne '0E0') { print "RC:$rc\n"; usleep (10000); @@ -982,7 +1004,7 @@ sub pandora_delete_old_session_data { $ulimit_timestamp = time() - $session_timeout; } - log_message ('PURGE', "Deleting old session data from tsessions_php\n"); + log_message ('PURGE', "Deleting old session data from tsessions_php"); while(db_delete_limit ($dbh, 'tsessions_php', 'last_active < ?', $SMALL_OPERATION_STEP, $ulimit_timestamp) ne '0E0') { usleep (10000); }; @@ -1076,8 +1098,9 @@ if ($conf{'_force'} == 0 && pandora_is_master(\%conf) == 0) { exit 1; } -# Get a lock -my $lock = db_get_lock ($dbh, 'pandora_db'); +# Get a lock on dbname. +my $lock_name = $conf{'dbname'}; +my $lock = db_get_lock ($dbh, $lock_name); if ($lock == 0 && $conf{'_force'} == 0) { log_message ('', " [*] Another instance of DB Tool seems to be running.\n\n"); exit 1; @@ -1086,9 +1109,26 @@ if ($lock == 0 && $conf{'_force'} == 0) { # Main pandoradb_main(\%conf, $dbh, $history_dbh); +# history_dbh is unset in pandoradb_main if not in use. +if (defined($history_dbh)) { + log_message('', " [>] DB Tool running on historical database.\n"); + my $h_conf = pandoradb_load_history_conf($history_dbh); + + # Keep base settings. + $h_conf->{'_onlypurge'} = $conf{'_onlypurge'}; + + # Re-launch maintenance process for historical database. + pandoradb_main( + $h_conf, + $history_dbh, + undef + ); + +} + # Release the lock if ($lock == 1) { - db_release_lock ($dbh, 'pandora_db'); + db_release_lock ($dbh, $lock_name); } # Cleanup and exit From 2b17ab4496a264bd4f05aebdfba7c4734e4498d9 Mon Sep 17 00:00:00 2001 From: artica Date: Fri, 8 Jan 2021 01:00:18 +0100 Subject: [PATCH 2/2] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/unix/pandora_agent_installer | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.rhel7.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/pandora_server_installer | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 8d867a5cd3..46ae44ff08 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.751-210107 +Version: 7.0NG.751-210108 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 6c4365a751..757a26d4b6 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.751-210107" +pandora_version="7.0NG.751-210108" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index bdf83bf1ea..0387c56470 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1016,7 +1016,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.751'; -use constant AGENT_BUILD => '210107'; +use constant AGENT_BUILD => '210108'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index a131a1b630..1571a5af1e 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.751 -%define release 210107 +%define release 210108 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 516c7f2ecb..5136e24b1c 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.751 -%define release 210107 +%define release 210108 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index d8f7d6985e..39eaacdb14 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.751" -PI_BUILD="210107" +PI_BUILD="210108" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 464fd3a01c..200fe2dfa6 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{210107} +{210108} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 22ffd51125..4dec4bcf70 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.751(Build 210107)") +#define PANDORA_VERSION ("7.0NG.751(Build 210108)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 002b41f045..0ef1fda9c5 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.751(Build 210107))" + VALUE "ProductVersion", "(7.0NG.751(Build 210108))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index f6a10094bb..370312645e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.751-210107 +Version: 7.0NG.751-210108 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 2735cb15fe..62aeadcb25 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.751-210107" +pandora_version="7.0NG.751-210108" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index b55a0aa48c..f4af373064 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC210107'; +$build_version = 'PC210108'; $pandora_version = 'v7.0NG.751'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index c13e84fd56..4c36b2b015 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -129,7 +129,7 @@
[ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index e750c9f255..4b5220a625 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.751 -%define release 210107 +%define release 210108 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 64c884efac..4997b25d45 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.751 -%define release 210107 +%define release 210108 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 8faff08aa8..6a88d5fc1f 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.751" -PI_BUILD="210107" +PI_BUILD="210108" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 695e6d7d7a..907576d975 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -35,7 +35,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.751 PS210107"; +my $version = "7.0NG.751 PS210108"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index f5e08c96bf..17009b3754 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.751 PS210107"; +my $version = "7.0NG.751 PS210108"; # save program name for logging my $progname = basename($0);