Fixed errors related with the oracle compatibility

This commit is contained in:
Alejandro Gallardo Escobar 2015-05-18 18:08:14 +02:00
parent c5d80cd104
commit 24aa40a726
1 changed files with 42 additions and 95 deletions

View File

@ -1753,6 +1753,7 @@ function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
global $config; global $config;
global $graphic_type; global $graphic_type;
$filter = array();
if ($id_agent < 1) { if ($id_agent < 1) {
$query = ""; $query = "";
@ -1760,18 +1761,9 @@ function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
else { else {
$modules = agents_get_modules($id_agent); $modules = agents_get_modules($id_agent);
$module_ids = array_keys($modules); $module_ids = array_keys($modules);
if (!empty($module_ids)) { if (!empty($module_ids))
$module_ids_str = implode(",", $module_ids); $filter['id_agente_modulo'] = $module_ids;
if (empty($module_ids_str))
$module_ids_str = "0";
}
else {
$module_ids_str = "0";
}
$query = sprintf (" AND id_agente_modulo IN (%s)", $module_ids_str);
} }
// All data (now) // All data (now)
@ -1790,101 +1782,56 @@ function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
$time_3months = $time_now - SECONDS_3MONTHS; $time_3months = $time_now - SECONDS_3MONTHS;
$query_error = false; $query_error = false;
// Data from 1 day ago // Data from 1 day ago
$sql_1day = sprintf("SELECT COUNT(*) $filter['utimestamp'] = '>' . $time_1day;
+ (SELECT COUNT(*) $num_1day = 0;
FROM tagente_datos_string $num_1day += (int) db_get_value_filter('count(*)', 'tagente_datos', $filter);
WHERE utimestamp >= %d %s) $num_1day += (int) db_get_value_filter('count(*)', 'tagente_datos_string', $filter);
+ (SELECT COUNT(*) $num_1day += (int) db_get_value_filter('count(*)', 'tagente_datos_log4x', $filter);
FROM tagente_datos_log4x
WHERE utimestamp >= %d %s)
FROM tagente_datos
WHERE utimestamp > %d %s",
$time_1day, $query,
$time_1day, $query,
$time_1day, $query);
$num_1day = db_get_sql($sql_1day);
if ($num_1day !== false) { if ($num_1day !== false) {
// Data from 1 week ago // Data from 1 week ago
$sql_1week = sprintf("SELECT COUNT(*) $filter['utimestamp'] = '>' . $time_1week;
+ (SELECT COUNT(*) $num_1week = 0;
FROM tagente_datos_string $num_1week += (int) db_get_value_filter('count(*)', 'tagente_datos', $filter);
WHERE utimestamp >= %d %s) $num_1week += (int) db_get_value_filter('count(*)', 'tagente_datos_string', $filter);
+ (SELECT COUNT(*) $num_1week += (int) db_get_value_filter('count(*)', 'tagente_datos_log4x', $filter);
FROM tagente_datos_log4x
WHERE utimestamp >= %d %s)
FROM tagente_datos
WHERE utimestamp >= %d %s",
$time_1week, $query,
$time_1week, $query,
$time_1week, $query);
$num_1week = db_get_sql($sql_1week);
if ($num_1week !== false) { if ($num_1week !== false) {
// Data from 1 month ago // Data from 1 month ago
$sql_1month = sprintf("SELECT COUNT(*) $filter['utimestamp'] = '>' . $time_1month;
+ (SELECT COUNT(*) $num_1month = 0;
FROM tagente_datos_string $num_1month += (int) db_get_value_filter('count(*)', 'tagente_datos', $filter);
WHERE utimestamp >= %d %s) $num_1month += (int) db_get_value_filter('count(*)', 'tagente_datos_string', $filter);
+ (SELECT COUNT(*) $num_1month += (int) db_get_value_filter('count(*)', 'tagente_datos_log4x', $filter);
FROM tagente_datos_log4x
WHERE utimestamp >= %d %s)
FROM tagente_datos
WHERE utimestamp >= %d %s",
$time_1month, $query,
$time_1month, $query,
$time_1month, $query);
$num_1month = db_get_sql($sql_1month);
if ($num_1month !== false) { if ($num_1month !== false) {
// Data from 3 months ago // Data from 3 months ago
$sql_3months = sprintf("SELECT COUNT(*) $filter['utimestamp'] = '>' . $time_3months;
+ (SELECT COUNT(*) $num_3months = 0;
FROM tagente_datos_string $num_3months += (int) db_get_value_filter('count(*)', 'tagente_datos', $filter);
WHERE utimestamp >= %d %s) $num_3months += (int) db_get_value_filter('count(*)', 'tagente_datos_string', $filter);
+ (SELECT COUNT(*) $num_3months += (int) db_get_value_filter('count(*)', 'tagente_datos_log4x', $filter);
FROM tagente_datos_log4x
WHERE utimestamp >= %d %s)
FROM tagente_datos
WHERE utimestamp >= %d %s",
$time_3months, $query,
$time_3months, $query,
$time_3months, $query);
$num_3months = db_get_sql($sql_3months);
if ($num_3months !== false) { if ($num_3months !== false) {
// All data // All data
$sql_all = sprintf("SELECT COUNT(*) unset($filter['utimestamp']);
+ (SELECT COUNT(*) $num_all = 0;
FROM tagente_datos_string $num_all += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos');
WHERE 1=1 %s) $num_all += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos_string');
+ (SELECT COUNT(*) $num_all += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos_log4x');
FROM tagente_datos_log4x
WHERE 1=1 %s)
FROM tagente_datos
WHERE 1=1 %s",
$query, $query, $query);
$num_all = db_get_sql($sql_all);
if ($num_all !== false) { if ($num_all !== false) {
$num_older = $num_all - $num_3months; $num_older = $num_all - $num_3months;
if ($config['history_db_enabled'] == 1) { if ($config['history_db_enabled'] == 1) {
// All data in common and history database // All data in common and history database
$sql_all_w_history = sprintf("SELECT COUNT(*) $num_all_w_history = 0;
+ (SELECT COUNT(*) $num_all_w_history += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos', true);
FROM tagente_datos_string $num_all_w_history += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos_string', true);
WHERE 1=1 %s) $num_all_w_history += (int) db_get_value_sql('SELECT count(*) FROM tagente_datos_log4x', true);
+ (SELECT COUNT(*)
FROM tagente_datos_log4x
WHERE 1=1 %s)
FROM tagente_datos
WHERE 1=1 %s",
$query, $query, $query);
$num_all_w_history = db_get_sql($sql_all_w_history, 0, true);
if ($num_all_w_history !== false) { if ($num_all_w_history !== false) {
$num_history = $num_all_w_history - $num_all; $num_history = $num_all_w_history - $num_all;
} else { } else {
@ -1906,7 +1853,7 @@ function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) {
} else { } else {
$query_error = true; $query_error = true;
} }
// Error // Error
if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0) if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0)
|| (empty($num_1day) && empty($num_1week) && empty($num_1month) || (empty($num_1day) && empty($num_1week) && empty($num_1month)