From b28206332567420c71bf3c7de5c42c8538e8c448 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 3 Jul 2017 15:09:31 +0200 Subject: [PATCH] Added changes to resolve bad history database data --- pandora_console/include/functions_graph.php | 49 ++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 27bcaa491a..8b64a44101 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -579,11 +579,46 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, } else { $data = db_get_all_rows_filter ('tagente_datos', - array ('id_agente_modulo' => (int)$agent_module_id, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('datos', 'utimestamp'), 'AND', $search_in_history_db); + array ('id_agente_modulo' => (int)$agent_module_id, + "utimestamp > $datelimit", + "utimestamp < $date", + 'order' => 'utimestamp ASC'), + array ('datos', 'utimestamp'), 'AND', false); + + if ($search_in_history_db) { + $cache = false; + $history = false; + + $sql = "SELECT datos, utimestamp FROM tagente_datos WHERE id_agente_modulo = " . (int)$agent_module_id . + " AND utimestamp > " . $datelimit . " AND utimestamp < " . $date . + " ORDER BY utimestamp ASC"; + + // Connect to the history DB + if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) { + $config['history_db_connection'] = db_connect($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false); + } + if ($config['history_db_connection'] !== false) { + $history = mysql_db_process_sql ($sql, 'affected_rows', $config['history_db_connection'], false); + } + + if ($history === false) { + $history = array (); + } + + $new_data = array(); + $last_timestamp = 0; + foreach($history as $h) { + $new_data[] = $h; + $last_timestamp = $h['utimestamp']; + } + foreach($data as $d) { + if ($d['utimestamp'] > $last_timestamp) { + $new_data[] = $d; + $last_timestamp = $d['utimestamp']; + } + } + $data = $new_data; + } } // Get module warning_min and critical_min @@ -3868,7 +3903,9 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, $timestamp_short = date($time_format, $timestamp); $long_index[$timestamp_short] = date( html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); - $timestamp = $timestamp_short; + if (!$fullscale) { + $timestamp = $timestamp_short; + } ///////////////////////////////////////////////////////////////// if ($total > $max_value) {