diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 6478256f61..b09449ce7d 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150722 +Version: 6.0dev-150723 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 38482c62ef..08f13d91ad 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="6.0dev-150722" +pandora_version="6.0dev-150723" 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 0a90b4550e..740c83dd0c 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150722'; +use constant AGENT_BUILD => '150723'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index fe518f358a..d7d8c521ac 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 6.0dev -%define release 150722 +%define release 150723 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 028db9da5a..b848bc76f0 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 6.0dev -%define release 150722 +%define release 150723 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 64f9e028d9..81a1281290 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150722} +{150723} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 715c2095db..af431e1187 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 ("6.0dev(Build 150722)") +#define PANDORA_VERSION ("6.0dev(Build 150723)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 5be01e2ad6..e57d0a5f36 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", "(6.0dev(Build 150722))" + VALUE "ProductVersion", "(6.0dev(Build 150723))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 251c7d1ec8..e4f24e7060 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150722 +Version: 6.0dev-150723 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 a1cca395d8..15c5c3e3ef 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="6.0dev-150722" +pandora_version="6.0dev-150723" package_pear=0 package_pandora=1 diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 46b0396a63..1c858d7e06 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -81,7 +81,7 @@ $table_behaviour->data[$row][1] = html_print_checkbox('paginate_module', 1, $config['paginate_module'], true); $row++; -$table_behaviour->data[$row][0] = __('Display proc modules in binary format (OK/FAIL).'); +$table_behaviour->data[$row][0] = __('Display data of proc modules in other format'); $table_behaviour->data[$row][1] = __('Yes') . ' ' . html_print_radio_button ('render_proc', 1, '', $config["render_proc"], true) . @@ -90,6 +90,15 @@ $table_behaviour->data[$row][1] .= __('No') . ' ' . html_print_radio_button ('render_proc', 0, '', $config["render_proc"], true); $row++; + +$table_behaviour->data[$row][0] = __('Display text proc modules have state is ok'); +$table_behaviour->data[$row][1] = html_print_input_text ('render_proc_ok', $config["render_proc_ok"], '', 25, 25, true); +$row++; + +$table_behaviour->data[$row][0] = __('Display text when proc modules have state critical'); +$table_behaviour->data[$row][1] = html_print_input_text ('render_proc_fail', $config["render_proc_fail"], '', 25, 25, true); +$row++; + echo "
"; echo "" . __('Behaviour configuration') . ""; html_print_table ($table_behaviour); diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 74b828036a..a72b1456a2 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -903,9 +903,9 @@ if ($list_modules) { case 21: case 31: if ($module["datos"]>=1) - $salida ='OK'; + $salida = $config["render_proc_ok"]; else - $salida = 'FAIL'; + $salida = $config["render_proc_fail"]; break; default: $salida = format_numeric($module["datos"]); diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index bfa7ad4e0b..8da45db7d2 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150722'; +$build_version = 'PC150723'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 0c982d35f8..71c520bb20 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -468,7 +468,11 @@ function config_update_config () { if (!config_update_value ('type_module_charts', (string) get_parameter('type_module_charts', 'area'))) $error_update[] = __('Default type of module charts.'); if (!config_update_value ('render_proc', (bool) get_parameter('render_proc', false))) - $error_update[] = __('Display proc modules in binary format (OK/FAIL)'); + $error_update[] = __('Display dara of proc modules in other format'); + if (!config_update_value ('render_proc_ok', (string) get_parameter('render_proc_ok', __('Ok') ))) + $error_update[] = __('Display text proc modules have state is ok'); + if (!config_update_value ('render_proc_fail', (string) get_parameter('render_proc_fail', __('Fail') ))) + $error_update[] = __('Display text when proc modules have state critical'); @@ -1296,6 +1300,13 @@ function config_process_config () { config_update_value ('render_proc', 0); } + if (!isset($config["render_proc_ok"])) { + config_update_value ('render_proc_ok', __('Ok') ); + } + if (!isset($config["render_proc_fail"])) { + config_update_value ('render_proc_fail', __('Fail') ); + } + if (!isset($config['command_snapshot'])) { config_update_value ('command_snapshot', 1); } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4304c89420..a5f262c36f 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -571,7 +571,11 @@ function reporting_SLA($report, $content, $type = 'dinamic', $id_agent_modules[] = $sla['id_agent_module']; } - $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); + $planned_downtimes = + reporting_get_planned_downtimes( + ($report['datetime'] - $content['period']), + $report['datetime'], + $id_agent_modules); $malformed_planned_downtimes = planned_downtimes_get_malformed(); if (!empty($planned_downtimes)) @@ -586,7 +590,8 @@ function reporting_SLA($report, $content, $type = 'dinamic', $data['name'] = $planned_downtime['name']; $data['description'] = $planned_downtime['description']; $data['execution'] = ucfirst($planned_downtime['type_execution']); - $data['dates'] = reporting_format_planned_downtime_dates($planned_downtime); + $data['dates'] = + reporting_format_planned_downtime_dates($planned_downtime); $data['malformed'] = 0; if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) { @@ -636,6 +641,8 @@ function reporting_SLA($report, $content, $type = 'dinamic', continue; } + + //Get the sla_value in % and store it on $sla_value $sla_value = reporting_get_agentmodule_sla( $sla['id_agent_module'], @@ -6367,6 +6374,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, global $config; + + if (empty($id_agent_module)) return false; @@ -6385,8 +6394,11 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, } + + // Calculate the SLA for large time without hours if ($timeFrom == $timeTo) { + // Get interval data $sql = sprintf ('SELECT * FROM tagente_datos @@ -6438,7 +6450,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, } // Calculate planned downtime dates - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + $downtime_dates = reporting_get_planned_downtimes_intervals( + $id_agent_module, $datelimit, $date); // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); @@ -6476,12 +6489,27 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, } $previous_utimestamp = $first_data['utimestamp']; - if ((($max_value > $min_value AND ($first_data['datos'] > $max_value OR $first_data['datos'] < $min_value))) OR - ($max_value <= $min_value AND $first_data['datos'] < $min_value)) { + if ( + ( + ( + $max_value > $min_value AND ( + $first_data['datos'] > $max_value OR + $first_data['datos'] < $min_value + ) + ) + ) OR + ( + $max_value <= $min_value AND + $first_data['datos'] < $min_value + ) + ) { $previous_status = 1; foreach ($downtime_dates as $date_dt) { - if (($date_dt['date_from'] <= $previous_utimestamp) AND ($date_dt['date_to'] >= $previous_utimestamp)) { + + if (($date_dt['date_from'] <= $previous_utimestamp) AND + ($date_dt['date_to'] >= $previous_utimestamp)) { + $previous_status = 0; } } @@ -6537,13 +6565,14 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $timeTo); } else { + // Extract the data each day $sla = 0; $i = 0; - for ($interval = 0; $interval <= $period; $interval = $interval + SECONDS_1DAY) { - $datelimit = $date - $interval; + for ($interval = SECONDS_1DAY; $interval <= $period; $interval = $interval + SECONDS_1DAY) { + $sla_day = reporting_get_agentmodule_sla( $id_agent_module, @@ -6555,8 +6584,12 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $timeFrom, $timeTo); - $sla += $sla_day; - $i++; + + // Avoid to add the period of module not init + if ($sla_day !== false) { + $sla += $sla_day; + $i++; + } } $sla = $sla / $i; @@ -7400,13 +7433,16 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_ // Limit date to start searching data $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); // Get interval data $sql = sprintf ('SELECT * FROM tagente_datos WHERE id_agente_modulo = %d - AND utimestamp > %d AND utimestamp <= %d', + AND utimestamp > %d + AND utimestamp <= %d', $id_agent_module, $datelimit, $date); //Add the working times (mon - tue - wed ...) and from time to time @@ -7467,10 +7503,11 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_ } // Calculate planned downtime dates - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + $downtime_dates = + reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + $previous_data = modules_get_previous_data($id_agent_module, $datelimit); if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; @@ -7548,6 +7585,7 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_ $previous_utimestamp = $data['utimestamp']; } + // Return the percentage of SLA compliance return (float) (100 - ($bad_period / $period) * 100); } diff --git a/pandora_console/include/get_file.php b/pandora_console/include/get_file.php index 7e3a44b34f..d5087827c9 100644 --- a/pandora_console/include/get_file.php +++ b/pandora_console/include/get_file.php @@ -13,21 +13,22 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +if (! isset($_SESSION['id_usuario'])) { + session_start(); +} + require_once('functions.php'); require_once('functions_filemanager.php'); - -session_start(); - require_once ("config.php"); global $config; +check_login (); + $auth_method = db_get_value('value', 'tconfig', 'token', 'auth'); require_once("auth/" . $auth_method . ".php"); -session_write_close (); -check_login (); $styleError = "background:url(\"../images/err.png\") no-repeat scroll 0 0 transparent; padding:4px 1px 6px 30px; color:#CC0000;"; diff --git a/pandora_console/install.php b/pandora_console/install.php index 203f997264..853059aca0 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
' . $network_map['name'] . ''; + . '&id_networkmap=' . $network_map['id_networkmap'] . '">' . io_safe_output($network_map['name']) . ''; $data[1] = $network_map['type']; $data[2] = ui_print_group_icon ($network_map['store_group'], true); diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index fa0a67f3fc..22e3923a8f 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 6.0dev -%define release 150722 +%define release 150723 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index 347393ab9d..b72b043bb1 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 6.0dev -%define release 150722 +%define release 150723 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index a163ee30d1..fd2dd54b71 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -39,7 +39,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('step_compact','1'), ('db_scheme_first_version', '6.0dev'), ('db_scheme_version','6.0dev'), -('db_scheme_build','PD150722'), +('db_scheme_build','PD150723'), ('show_unknown','0'), ('show_lastalerts','1'), ('style','pandora'), diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index 7eb9fd2d03..0a8b6ace2f 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 6.0dev-150722 +Version: 6.0dev-150723 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index cf9cf486a3..52dd266d33 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/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="6.0dev-150722" +pandora_version="6.0dev-150723" package_cpan=0 package_pandora=1 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 19cf11e69f..9aabe01307 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -43,7 +43,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "6.0dev"; -my $pandora_build = "150722"; +my $pandora_build = "150723"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index bf1b68edba..7c8b674c50 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -34,6 +34,7 @@ our @EXPORT = qw( add_new_address_agent db_concat db_connect + db_delete_limit db_disconnect db_do db_get_lock @@ -638,9 +639,9 @@ sub get_db_value_limit ($$$;@) { # Cache statements my $sth; if ($RDBMS ne 'oracle') { - $sth = $dbh->prepare_cached($query . ' LIMIT ' . $limit); + $sth = $dbh->prepare_cached($query . ' LIMIT ' . int($limit)); } else { - $sth = $dbh->prepare_cached('SELECT * FROM (' . $query . ') WHERE ROWNUM <= ' . $limit); + $sth = $dbh->prepare_cached('SELECT * FROM (' . $query . ') WHERE ROWNUM <= ' . int($limit)); } $sth->execute(@values); @@ -739,6 +740,29 @@ sub get_db_rows_limit ($$$;@) { return @rows; } +########################################################################## +## SQL delete with a LIMIT clause. +########################################################################## +sub db_delete_limit ($$$$;@) { + my ($dbh, $from, $where, $limit, @values) = @_; + my $sth; + + # MySQL + if ($RDBMS eq 'mysql') { + $sth = $dbh->prepare_cached("DELETE FROM $from WHERE $where LIMIT " . int($limit)); + } + # PostgreSQL + elsif ($RDBMS eq 'postgresql') { + $sth = $dbh->prepare_cached("DELETE FROM $from WHERE $where LIMIT " . int($limit)); + } + # Oracle + elsif ($RDBMS eq 'oracle') { + $sth = $dbh->prepare_cached("DELETE FROM (SELECT * FROM $from WHERE $where) WHERE ROWNUM <= " . int($limit)); + } + + $sth->execute(@values); +} + ########################################################################## ## SQL insert. Returns the ID of the inserted row. ########################################################################## @@ -1109,7 +1133,10 @@ sub db_insert_get_values ($) { ######################################################################## sub db_get_lock($$;$) { my ($dbh, $lock_name, $lock_timeout) = @_; - + + # Only supported in MySQL. + return 1 unless ($RDBMS eq 'mysql'); + # Set a default lock timeout of 1 second $lock_timeout = 1 if (! defined ($lock_timeout)); @@ -1130,6 +1157,9 @@ sub db_get_lock($$;$) { sub db_release_lock($$) { my ($dbh, $lock_name) = @_; + # Only supported in MySQL. + return unless ($RDBMS eq 'mysql'); + my $sth = $dbh->prepare('SELECT RELEASE_LOCK(?)'); $sth->execute($lock_name); my ($lock) = $sth->fetchrow; diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 7fdd02501a..4ece564b87 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 6.0dev -%define release 150722 +%define release 150723 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index d074d5f30f..c77e434eea 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 6.0dev -%define release 150722 +%define release 150723 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/util/pandora_database_check.pl b/pandora_server/util/pandora_database_check.pl index b6fc7bbfb1..6590fd6619 100755 --- a/pandora_server/util/pandora_database_check.pl +++ b/pandora_server/util/pandora_database_check.pl @@ -53,7 +53,7 @@ pandora_init(\%conf); pandora_load_config (\%conf); # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ($conf{'dbengine'}, $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'}, $conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index c7276537c8..c16ec46506 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -33,7 +33,7 @@ use PandoraFMS::Tools; use PandoraFMS::DB; # version: define current version -my $version = "6.0dev PS150722"; +my $version = "6.0dev PS150723"; # Pandora server configuration my %conf; @@ -87,7 +87,7 @@ sub pandora_purgedb ($$) { # Delete extended session data if (enterprise_load (\%conf) != 0) { db_do ($dbh, "DELETE FROM tsesion_extended - WHERE id_sesion NOT IN ( SELECT id_sesion FROM tsesion );"); + WHERE id_sesion NOT IN ( SELECT id_sesion FROM tsesion )"); log_message ('PURGE', 'Deleting old extended session data.'); } @@ -113,7 +113,7 @@ sub pandora_purgedb ($$) { # steps (100 fixed by default) # Starting from the oldest record on the table - $first_mark = get_db_value ($dbh, 'SELECT utimestamp FROM tagente_datos_inventory ORDER BY utimestamp ASC LIMIT 1'); + $first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagente_datos_inventory ORDER BY utimestamp ASC', 1); if (defined ($first_mark)) { $total_time = $ulimit_timestamp - $first_mark; $purge_steps = int($total_time / $BIG_OPERATION_STEP); @@ -137,7 +137,7 @@ sub pandora_purgedb ($$) { # # Now the log4x data # - $first_mark = get_db_value ($dbh, 'SELECT utimestamp FROM tagente_datos_log4x ORDER BY utimestamp ASC LIMIT 1'); + $first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagente_datos_log4x ORDER BY utimestamp ASC', 1); if (defined ($first_mark)) { $total_time = $ulimit_timestamp - $first_mark; $purge_steps = int($total_time / $BIG_OPERATION_STEP); @@ -206,7 +206,7 @@ sub pandora_purgedb ($$) { # Delete with buffer to avoid problems with performance my $events_to_delete = get_db_value ($dbh, "SELECT COUNT(*) FROM $events_table WHERE utimestamp < ?", $event_limit); while($events_to_delete > 0) { - db_do($dbh, "DELETE FROM $events_table WHERE utimestamp < ? LIMIT ?", $event_limit, $BIG_OPERATION_STEP); + db_delete_limit($dbh, $events_table, "utimestamp < ?", $BIG_OPERATION_STEP, $event_limit); $events_to_delete = $events_to_delete - $BIG_OPERATION_STEP; # Mark the progress @@ -222,7 +222,7 @@ sub pandora_purgedb ($$) { log_message ('PURGE', "Deleting validated events from tmetaconsole_event_history.", ''); $events_to_delete = get_db_value ($dbh, "SELECT COUNT(*) FROM tmetaconsole_event_history WHERE estado = 1"); while($events_to_delete > 0) { - db_do($dbh, "DELETE FROM tmetaconsole_event_history WHERE estado = 1 LIMIT ?", $BIG_OPERATION_STEP); + db_delete_limit($dbh, 'tmetaconsole_event_history', 'estado = 1', $BIG_OPERATION_STEP); $events_to_delete = $events_to_delete - $BIG_OPERATION_STEP; # Mark the progress @@ -292,7 +292,7 @@ sub pandora_purgedb ($$) { my $nstate = get_db_value ($dbh, 'SELECT count(id_agente_modulo) FROM tagente_estado WHERE id_agente_modulo=?', $id_module); last if($nstate == 0); - db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo=? LIMIT ?', $id_module, $buffer); + db_delete_limit ($dbh, 'tagente_estado', 'id_agente_modulo=?', $buffer, $id_module); } } log_message ('', "\n"); @@ -303,7 +303,7 @@ sub pandora_purgedb ($$) { log_message ('PURGE', "Deleting old access data (More than 24hr)"); - $first_mark = get_db_value ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC LIMIT 1'); + $first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC', 1); if (defined ($first_mark)) { $total_time = $ulimit_access_timestamp - $first_mark; $purge_steps = int( $total_time / $BIG_OPERATION_STEP); @@ -339,31 +339,31 @@ sub pandora_purgedb ($$) { db_do ($dbh, "DELETE FROM treport_content WHERE id_agent_module != 0 AND id_agent_module NOT IN (SELECT id_agente_modulo FROM tagente_modulo) - AND type NOT IN ($blacklist_types_str);"); + AND ${RDBMS_QUOTE}type${RDBMS_QUOTE} NOT IN ($blacklist_types_str)"); db_do ($dbh, "DELETE FROM treport_content_item WHERE id_agent_module != 0 AND id_agent_module NOT IN (SELECT id_agente_modulo FROM tagente_modulo) - AND id_report_content NOT IN (SELECT id_rc FROM treport_content WHERE type IN ($blacklist_types_str));"); + AND id_report_content NOT IN (SELECT id_rc FROM treport_content WHERE ${RDBMS_QUOTE}type${RDBMS_QUOTE} IN ($blacklist_types_str))"); db_do ($dbh, "DELETE FROM treport_content_sla_combined WHERE id_agent_module != 0 AND id_agent_module NOT IN (SELECT id_agente_modulo FROM tagente_modulo) - AND id_report_content NOT IN (SELECT id_rc FROM treport_content WHERE type = 'SLA_services');"); + AND id_report_content NOT IN (SELECT id_rc FROM treport_content WHERE ${RDBMS_QUOTE}type${RDBMS_QUOTE} = 'SLA_services')"); # Deleted agents log_message ('PURGE', "Delete contents in report that have some deleted agents."); db_do ($dbh, "DELETE FROM treport_content WHERE id_agent != 0 AND id_agent NOT IN (SELECT id_agente FROM tagente) - AND type NOT IN ($blacklist_types_str);"); + AND ${RDBMS_QUOTE}type${RDBMS_QUOTE} NOT IN ($blacklist_types_str)"); # Empty contents log_message ('PURGE', "Delete empty contents in report (like SLA or Exception)."); db_do ($dbh, "DELETE FROM treport_content - WHERE type LIKE 'exception' - AND id_rc NOT IN (SELECT id_report_content FROM treport_content_item);"); + WHERE ${RDBMS_QUOTE}type${RDBMS_QUOTE} LIKE 'exception' + AND id_rc NOT IN (SELECT id_report_content FROM treport_content_item)"); db_do ($dbh, "DELETE FROM treport_content - WHERE type IN ('SLA', 'SLA_monthly', 'SLA_services') - AND id_rc NOT IN (SELECT id_report_content FROM treport_content_sla_combined);"); + WHERE ${RDBMS_QUOTE}type${RDBMS_QUOTE} IN ('SLA', 'SLA_monthly', 'SLA_services') + AND id_rc NOT IN (SELECT id_report_content FROM treport_content_sla_combined)"); } @@ -913,7 +913,7 @@ sub pandora_delete_old_module_data { # you alter code and you don't know exactly what are you doing. Please take in mind this code executes each hour # and has been patches MANY times. Before altering anything, think twice ! - $first_mark = get_db_value ($dbh, "SELECT utimestamp FROM $table ORDER BY utimestamp ASC LIMIT 1"); + $first_mark = get_db_value_limit ($dbh, "SELECT utimestamp FROM $table ORDER BY utimestamp ASC", 1); if (defined ($first_mark)) { $total_time = $ulimit_timestamp - $first_mark; $purge_steps = int($total_time / $BIG_OPERATION_STEP); @@ -926,7 +926,7 @@ sub pandora_delete_old_module_data { # Let's split the intervals in $SMALL_OPERATION_STEP deletes each $purge_count = get_db_value ($dbh, "SELECT COUNT(id_agente_modulo) FROM $table WHERE utimestamp < $mark1 AND utimestamp >= $mark2"); while ($purge_count > 0){ - db_do ($dbh, "DELETE FROM $table WHERE utimestamp < $mark1 AND utimestamp >= $mark2 LIMIT $SMALL_OPERATION_STEP"); + db_delete_limit ($dbh, $table, 'utimestamp < ? AND utimestamp >= ?', $SMALL_OPERATION_STEP, $mark1, $mark2); # Do a nanosleep here for 0,001 sec usleep (10000); $purge_count = $purge_count - $SMALL_OPERATION_STEP; @@ -950,7 +950,8 @@ sub pandora_delete_old_export_data { my ($dbh, $ulimit_timestamp) = @_; log_message ('PURGE', "Deleting old export data from tserver_export_data\n"); - while(db_do ($dbh, "DELETE FROM tserver_export_data WHERE UNIX_TIMESTAMP(timestamp) < ? LIMIT $SMALL_OPERATION_STEP", $ulimit_timestamp) ne '0E0') { + 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); }; } @@ -962,7 +963,7 @@ sub pandora_delete_old_session_data { my ($dbh, $ulimit_timestamp) = @_; log_message ('PURGE', "Deleting old session data from tsessions_php\n"); - while(db_do ($dbh, "DELETE FROM tsessions_php WHERE last_active < ? LIMIT $SMALL_OPERATION_STEP", $ulimit_timestamp) ne '0E0') { + while(db_delete_limit ($dbh, 'tsessions_php', 'last_active < ?', $SMALL_OPERATION_STEP, $ulimit_timestamp) ne '0E0') { usleep (10000); }; } @@ -1019,7 +1020,7 @@ else { } # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ($conf{'dbengine'}, $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'}, $conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 78b9e8962a..4064e618b2 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -35,7 +35,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "6.0dev PS150722"; +my $version = "6.0dev PS150723"; # save program name for logging my $progname = basename($0);