Modified a bunch of functions to choose when the history db should be used and when not

This commit is contained in:
Alejandro Gallardo Escobar 2014-10-22 12:00:14 +02:00
parent fc5cfb3c32
commit e89565e760
3 changed files with 51 additions and 23 deletions

View File

@ -495,6 +495,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
// Set variables // Set variables
if ($date == 0) $date = get_system_time(); if ($date == 0) $date = get_system_time();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$resolution = $config['graph_res'] * 50; //Number of points of the graph $resolution = $config['graph_res'] * 50; //Number of points of the graph
$interval = (int) ($period / $resolution); $interval = (int) ($period / $resolution);
$agent_name = modules_get_agentmodule_agent_name ($agent_module_id); $agent_name = modules_get_agentmodule_agent_name ($agent_module_id);
@ -539,7 +540,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
"utimestamp > $datelimit", "utimestamp > $datelimit",
"utimestamp < $date", "utimestamp < $date",
'order' => 'utimestamp ASC'), 'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'), 'AND', true); array ('datos', 'utimestamp'), 'AND', $search_in_history_db);
// Get module warning_min and critical_min // Get module warning_min and critical_min
$warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id); $warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id);
@ -913,6 +914,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
if ($date == 0) if ($date == 0)
$date = get_system_time(); $date = get_system_time();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$resolution = $config['graph_res'] * 50; //Number of points of the graph $resolution = $config['graph_res'] * 50; //Number of points of the graph
$interval = (int) ($period / $resolution); $interval = (int) ($period / $resolution);
@ -1063,7 +1065,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
"utimestamp > $datelimit", "utimestamp > $datelimit",
"utimestamp < $date", "utimestamp < $date",
'order' => 'utimestamp ASC'), 'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'), 'AND', true); array ('datos', 'utimestamp'), 'AND', $search_in_history_db);
if ($data === false) { if ($data === false) {
$data = array (); $data = array ();
} }

View File

@ -1497,7 +1497,9 @@ function modules_get_previous_data ($id_agent_module, $utimestamp = 0, $string =
ORDER BY utimestamp DESC', ORDER BY utimestamp DESC',
$id_agent_module, $utimestamp, $utimestamp - SECONDS_2DAY); $id_agent_module, $utimestamp, $utimestamp - SECONDS_2DAY);
return db_get_row_sql ($sql, true); $search_in_history_db = db_search_in_history_db($utimestamp);
return db_get_row_sql ($sql, $search_in_history_db);
} }
/** /**
@ -1529,7 +1531,9 @@ function modules_get_next_data ($id_agent_module, $utimestamp = 0, $string = 0)
ORDER BY utimestamp ASC', ORDER BY utimestamp ASC',
$id_agent_module, $utimestamp + $interval, $utimestamp); $id_agent_module, $utimestamp + $interval, $utimestamp);
return db_get_row_sql ($sql, true); $search_in_history_db = db_search_in_history_db($utimestamp);
return db_get_row_sql ($sql, $search_in_history_db);
} }
/** /**
@ -1550,6 +1554,7 @@ function modules_get_agentmodule_data ($id_agent_module, $period, $date = 0) {
} }
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
switch ($module['id_tipo_modulo']) { switch ($module['id_tipo_modulo']) {
//generic_data_string //generic_data_string
@ -1586,7 +1591,7 @@ function modules_get_agentmodule_data ($id_agent_module, $period, $date = 0) {
break; break;
} }
$values = db_get_all_rows_sql ($sql, true, false); $values = db_get_all_rows_sql ($sql, $search_in_history_db, false);
if ($values === false) { if ($values === false) {
return array (); return array ();

View File

@ -53,6 +53,8 @@ function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $d
if (empty ($date)) $date = get_system_time (); if (empty ($date)) $date = get_system_time ();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$id_module_type = modules_get_agentmodule_type ($id_agent_module); $id_module_type = modules_get_agentmodule_type ($id_agent_module);
$module_type = modules_get_moduletype_name ($id_module_type); $module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type); $uncompressed_module = is_module_uncompressed ($module_type);
@ -63,7 +65,7 @@ function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $d
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Uncompressed module data // Uncompressed module data
@ -156,6 +158,8 @@ function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date
if (empty ($date)) $date = get_system_time (); if (empty ($date)) $date = get_system_time ();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$id_module_type = modules_get_agentmodule_type ($id_agent_module); $id_module_type = modules_get_agentmodule_type ($id_agent_module);
$module_type = modules_get_moduletype_name ($id_module_type); $module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type); $uncompressed_module = is_module_uncompressed ($module_type);
@ -166,7 +170,7 @@ function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Uncompressed module data // Uncompressed module data
@ -235,6 +239,8 @@ function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date
if (empty ($date)) $date = get_system_time (); if (empty ($date)) $date = get_system_time ();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$id_module_type = modules_get_agentmodule_type ($id_agent_module); $id_module_type = modules_get_agentmodule_type ($id_agent_module);
$module_type = modules_get_moduletype_name ($id_module_type); $module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type); $uncompressed_module = is_module_uncompressed ($module_type);
@ -245,7 +251,7 @@ function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Uncompressed module data // Uncompressed module data
@ -308,6 +314,8 @@ function reporting_get_agentmodule_data_sum ($id_agent_module, $period=0, $date
if (empty ($date)) $date = get_system_time (); if (empty ($date)) $date = get_system_time ();
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module); $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module);
$module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type); $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type);
$module_interval = modules_get_interval ($id_agent_module); $module_interval = modules_get_interval ($id_agent_module);
@ -326,7 +334,7 @@ function reporting_get_agentmodule_data_sum ($id_agent_module, $period=0, $date
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Uncompressed module data // Uncompressed module data
@ -415,6 +423,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu
// Limit date to start searching data // Limit date to start searching data
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
// Get interval data // Get interval data
$sql = sprintf ('SELECT * $sql = sprintf ('SELECT *
FROM tagente_datos FROM tagente_datos
@ -464,7 +474,7 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")';
} }
$sql .= ' ORDER BY utimestamp ASC'; $sql .= ' ORDER BY utimestamp ASC';
$interval_data = db_get_all_rows_sql ($sql, true); $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db);
if ($interval_data === false) { if ($interval_data === false) {
$interval_data = array (); $interval_data = array ();
@ -579,6 +589,8 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
// Limit date to start searching data // Limit date to start searching data
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
// Get interval data // Get interval data
$sql = sprintf ('SELECT * FROM tagente_datos $sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d WHERE id_agente_modulo = %d
@ -631,7 +643,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
} }
$sql .= ' ORDER BY utimestamp ASC'; $sql .= ' ORDER BY utimestamp ASC';
$interval_data = db_get_all_rows_sql ($sql, true); $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db);
if ($interval_data === false) { if ($interval_data === false) {
$interval_data = array (); $interval_data = array ();
@ -4996,13 +5008,14 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_unshift($table2->head, __('Date')); array_unshift($table2->head, __('Date'));
$datelimit = $report["datetime"] - $content['period']; $datelimit = $report["datetime"] - $content['period'];
$search_in_history_db = db_search_in_history_db($datelimit);
// This query gets information from the default and the historic database // This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT * $result = db_get_all_rows_sql('SELECT *
FROM tagente_datos FROM tagente_datos
WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . ' AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], true); AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
// Adds string data if there is no numeric data // Adds string data if there is no numeric data
if ((count($result) < 0) or (!$result)) { if ((count($result) < 0) or (!$result)) {
@ -5011,7 +5024,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
FROM tagente_datos_string FROM tagente_datos_string
WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . ' AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], true); AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
} }
if ($result === false) { if ($result === false) {
$result = array(); $result = array();
@ -7123,6 +7136,8 @@ function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date =
// Read module configuration // Read module configuration
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module); WHERE id_agente_modulo = ' . (int) $id_agent_module);
@ -7146,7 +7161,7 @@ function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date =
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Get previous data // Get previous data
@ -7233,6 +7248,8 @@ function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date =
// Read module configuration // Read module configuration
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module); WHERE id_agente_modulo = ' . (int) $id_agent_module);
@ -7256,7 +7273,7 @@ function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date =
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Get previous data // Get previous data
@ -7342,6 +7359,8 @@ function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0
// Read module configuration // Read module configuration
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module); WHERE id_agente_modulo = ' . (int) $id_agent_module);
@ -7365,7 +7384,7 @@ function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Get previous data // Get previous data
@ -7442,6 +7461,8 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0
// Read module configuration // Read module configuration
$datelimit = $date - $period; $datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module); WHERE id_agente_modulo = ' . (int) $id_agent_module);
@ -7465,7 +7486,7 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0
WHERE id_agente_modulo = ' . (int) $id_agent_module . WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date . ' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true); ' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Get previous data // Get previous data