From 5749eda8c3c47303c90cd11849e04cf3458a58fc Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 11 Jan 2022 09:13:25 +0100 Subject: [PATCH] include historic db data in report --- pandora_console/include/db/mysql.php | 4 ++-- pandora_console/include/db/oracle.php | 4 ++-- pandora_console/include/db/postgresql.php | 4 ++-- pandora_console/include/functions_db.php | 8 ++++---- pandora_console/include/functions_reporting.php | 16 ++++++++++++---- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 8ded979b77..0c100f93d6 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -874,10 +874,10 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa * * @return the first value of the first row of a table result from query. */ -function mysql_db_get_value_sql($sql, $dbconnection=false) +function mysql_db_get_value_sql($sql, $dbconnection=false, $search_history_db=false) { $sql .= ' LIMIT 1'; - $result = mysql_db_get_all_rows_sql($sql, false, true, $dbconnection); + $result = mysql_db_get_all_rows_sql($sql, $search_history_db, true, $dbconnection); if ($result === false) { return false; diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php index 5000aaf719..bdf1411600 100644 --- a/pandora_console/include/db/oracle.php +++ b/pandora_console/include/db/oracle.php @@ -977,10 +977,10 @@ function oracle_recode_query($sql, $values, $join='AND', $return=true) * * @return the first value of the first row of a table result from query. */ -function oracle_db_get_value_sql($sql, $dbconnection=false) +function oracle_db_get_value_sql($sql, $dbconnection=false, $search_history_db=false) { $sql = 'SELECT * FROM ('.$sql.') WHERE rownum < 2'; - $result = oracle_db_get_all_rows_sql($sql, false, true, $dbconnection); + $result = oracle_db_get_all_rows_sql($sql, $search_history_db, true, $dbconnection); if ($result === false) { return false; diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php index cfacdad7d6..8617920dd9 100644 --- a/pandora_console/include/db/postgresql.php +++ b/pandora_console/include/db/postgresql.php @@ -686,10 +686,10 @@ function postgresql_db_format_array_where_clause_sql($values, $join='AND', $pref * * @return the first value of the first row of a table result from query. */ -function postgresql_db_get_value_sql($sql, $dbconnection=false) +function postgresql_db_get_value_sql($sql, $dbconnection=false, $search_history_db=false) { $sql .= ' LIMIT 1'; - $result = postgresql_db_get_all_rows_sql($sql, false, true, $dbconnection); + $result = postgresql_db_get_all_rows_sql($sql, $search_history_db, true, $dbconnection); if ($result === false) { return false; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 34bb53ef26..cbcc645fdb 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -414,21 +414,21 @@ function db_get_value_filter($field, $table, $filter, $where_join='AND', $search * * @return mixed the first value of the first row of a table result from query. */ -function db_get_value_sql($sql, $dbconnection=false) +function db_get_value_sql($sql, $dbconnection=false, $search_history_db=false) { global $config; switch ($config['dbtype']) { case 'mysql': - return mysql_db_get_value_sql($sql, $dbconnection); + return mysql_db_get_value_sql($sql, $dbconnection, $search_history_db); break; case 'postgresql': - return postgresql_db_get_value_sql($sql, $dbconnection); + return postgresql_db_get_value_sql($sql, $dbconnection, $search_history_db); break; case 'oracle': - return oracle_db_get_value_sql($sql, $dbconnection); + return oracle_db_get_value_sql($sql, $dbconnection, $search_history_db); break; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 8caca733a5..63e39a652a 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -8775,6 +8775,8 @@ function reporting_increment($report, $content) $return['data'] = []; + $search_in_history_db = db_search_in_history_db($return['from']); + if (is_metaconsole()) { $sql1 = 'SELECT datos FROM tagente_datos WHERE id_agente_modulo = '.$id_agent_module.' AND utimestamp <= '.(time() - $period).' ORDER BY utimestamp DESC'; @@ -8801,17 +8803,23 @@ function reporting_increment($report, $content) $connection = false; } - $old_data = db_get_value_sql($sql1); + $old_data = db_get_value_sql($sql1, false, $search_in_history_db); - $last_data = db_get_value_sql($sql2); + $last_data = db_get_value_sql($sql2, false, $search_in_history_db); } } else { $old_data = db_get_value_sql( 'SELECT datos FROM tagente_datos WHERE id_agente_modulo = '.$id_agent_module.' - AND utimestamp <= '.(time() - $period).' ORDER BY utimestamp DESC' + AND utimestamp <= '.(time() - $period).' ORDER BY utimestamp DESC', + false, + $search_in_history_db ); - $last_data = db_get_value_sql('SELECT datos FROM tagente_datos WHERE id_agente_modulo = '.$id_agent_module.' ORDER BY utimestamp DESC'); + $last_data = db_get_value_sql( + 'SELECT datos FROM tagente_datos WHERE id_agente_modulo = '.$id_agent_module.' ORDER BY utimestamp DESC', + false, + $search_in_history_db + ); } if (!is_metaconsole()) {