From 68a10343fbd292d02ea19e8530a4d9f26edaf5d0 Mon Sep 17 00:00:00 2001 From: vgilc Date: Fri, 10 Nov 2017 12:24:33 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"Merge=20branch=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts merge request !1025 --- pandora_console/include/ajax/events.php | 11 +- pandora_console/include/db/mysql.php | 4 +- pandora_console/include/functions_db.php | 345 +++++++++++------- pandora_console/include/functions_graph.php | 337 ++++++++--------- pandora_console/include/functions_modules.php | 83 ++--- .../include/graphs/flot/pandora.flot.js | 20 +- .../operation/agentes/stat_win.php | 17 +- 7 files changed, 464 insertions(+), 353 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index d431a83dd7..cad5efae1a 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -478,13 +478,10 @@ if ($get_extended_event) { if ($get_events_details) { $event_ids = explode(',',get_parameter ('event_ids')); - $events = db_get_all_rows_filter ( - 'tevento', - array ('id_evento' => $event_ids,'order' => 'utimestamp ASC'), - array ('evento', 'utimestamp', 'estado', 'criticity', 'id_usuario'), - 'AND', - true - ); + $events = db_get_all_rows_filter ('tevento', + array ('id_evento' => $event_ids, + 'order' => 'utimestamp ASC'), + array ('evento', 'utimestamp', 'estado', 'criticity', 'id_usuario')); $out = ''; $out .= ''; diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 7101f960de..7da9316c65 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -738,7 +738,7 @@ function mysql_db_get_row_sql ($sql, $search_history_db = false) { * * @return mixed Array of the row or false in case of error. */ -function mysql_db_get_row_filter ($table, $filter, $fields = false, $where_join = 'AND', $historydb = false) { +function mysql_db_get_row_filter ($table, $filter, $fields = false, $where_join = 'AND') { if (empty ($fields)) { $fields = '*'; } @@ -758,7 +758,7 @@ function mysql_db_get_row_filter ($table, $filter, $fields = false, $where_join $sql = sprintf ('SELECT %s FROM %s %s', $fields, $table, $filter); - return db_get_row_sql ($sql, $historydb); + return db_get_row_sql ($sql); } /** diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a156538b9a..06c85ef194 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -416,12 +416,12 @@ function db_get_row ($table, $field_search, $condition, $fields = false) { * * @return mixed Array of the row or false in case of error. */ -function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND', $historydb = false) { +function db_get_row_filter($table, $filter, $fields = false, $where_join = 'AND') { global $config; switch ($config["dbtype"]) { case "mysql": - return mysql_db_get_row_filter($table, $filter, $fields, $where_join, $historydb); + return mysql_db_get_row_filter($table, $filter, $fields, $where_join); break; case "postgresql": return postgresql_db_get_row_filter($table, $filter, $fields, $where_join); @@ -493,7 +493,7 @@ function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true, $d * @param int $tend end of search * */ -function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend = false, $historydb = false) { +function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend = false) { global $config; if (!isset($id_agente_modulo)) { @@ -521,7 +521,7 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend $query .= " AND utimestamp >= $tstart AND utimestamp <= $tend "; $query .= " ORDER BY utimestamp ASC"; - $events = db_get_all_rows_sql($query, $historydb); + $events = db_get_all_rows_sql($query); if (! is_array($events)){ return false; @@ -582,6 +582,17 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f return false; } + if ((!isset($tstart)) || ($tstart === false)) { + // Return data from the begining + // Get first available utimestamp in active DB + $query_first_man_time = " SELECT utimestamp FROM tagente_datos "; + $query_first_man_time .= " WHERE id_agente_modulo = $id_agente_modulo"; + $query_first_man_time .= " ORDER BY utimestamp ASC LIMIT 1"; + + $first_man_time = db_get_all_rows_sql( $query_first_man_time, false); + $tstart = $first_man_time[0]['utimestamp']; + } + if ((!isset($tend)) || ($tend === false)) { // Return data until now $tend = time(); @@ -605,51 +616,53 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f $table = "tagente_datos_string"; } - $result = modules_get_first_date($id_agente_modulo,$tstart); - $first_utimestamp = $result["first_utimestamp"]; - $search_historydb = $result["search_historydb"]; + // Get first available utimestamp in active DB + $query = " SELECT utimestamp, datos FROM $table "; + $query .= " WHERE id_agente_modulo=$id_agente_modulo AND utimestamp < $tstart"; + $query .= " ORDER BY utimestamp DESC LIMIT 1"; - if ($first_utimestamp === false) { - $first_data["utimestamp"] = $tstart; + $ret = db_get_all_rows_sql( $query , $search_historydb); + + if ( ( $ret === false ) || (( isset($ret[0]["utimestamp"]) && ($ret[0]["utimestamp"] > $tstart )))) { + // Value older than first retrieved from active DB + $search_historydb = true; + + $ret = db_get_all_rows_sql( $query , $search_historydb); + + if ($ret) { + $tstart = $ret[0]["utimestamp"]; + } + } + else { + $first_data["utimestamp"] = $ret[0]["utimestamp"]; + $first_data["datos"] = $ret[0]["datos"]; + } + + if ( ( $ret === false ) || (( isset($ret[0]["utimestamp"]) && ($ret[0]["utimestamp"] > $tstart )))) { + // No previous data. -> not init + // Avoid false unknown status + $first_data["utimestamp"] = time(); $first_data["datos"] = false; } else { - $query = "SELECT datos,utimestamp FROM $table "; - $query .= " WHERE id_agente_modulo=$id_agente_modulo "; - $query .= " AND utimestamp=" . $first_utimestamp; - - $data = db_get_all_rows_sql($query,$search_historydb); - if ($data === false) { - // first utimestamp not found in active database - // SEARCH HISTORY DB - $search_historydb = true; - $data = db_get_all_rows_sql($query,$search_historydb); - } - - if ($data === false) { // Not init - $first_data["utimestamp"] = $tstart; - $first_data["datos"] = false; - } - else { - $first_data["utimestamp"] = $data[0]["utimestamp"]; - $first_data["datos"] = $data[0]["datos"]; - - } + $first_data["utimestamp"] = $ret[0]["utimestamp"]; + $first_data["datos"] = $ret[0]["datos"]; } $query = " SELECT utimestamp, datos FROM $table "; $query .= " WHERE id_agente_modulo=$id_agente_modulo AND utimestamp >= $tstart AND utimestamp <= $tend"; $query .= " ORDER BY utimestamp ASC"; + // Retrieve all data from module in given range $raw_data = db_get_all_rows_sql($query, $search_historydb); - if (($raw_data === false) && ($first_utimestamp === $tstart)) { + if (($raw_data === false) && ($ret === false)) { // No data return false; } // Retrieve going unknown events in range - $unknown_events = db_get_module_ranges_unknown($id_agente_modulo, $tstart, $tend, $search_historydb); + $unknown_events = db_get_module_ranges_unknown($id_agente_modulo, $tstart, $tend); // Retrieve module_interval to build the template $module_interval = modules_get_interval ($id_agente_modulo); @@ -672,115 +685,197 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f $current_timestamp = $tstart; $last_inserted_value = $first_data["datos"]; $last_timestamp = $first_data["utimestamp"]; - $last_value = $first_data["datos"]; + $data_found = 0; // Build template $pool_id = 0; $now = time(); - $current_unknown = array_shift($unknown_events); - $current_raw_data = array_shift($raw_data); - + $in_unknown_status = 0; + if (is_array($unknown_events)) { + $current_unknown = array_shift($unknown_events); + } while ( $current_timestamp < $tend ) { + $expected_data_generated = 0; + $return[$pool_id]["data"] = array(); $tmp_data = array(); - $current_timestamp_end = $current_timestamp + $slice_size; + $data_found = 0; - if ( ( $current_timestamp > $now) || - ( ($current_timestamp_end - $last_timestamp) > - (SECONDS_1DAY + 2*$module_interval) ) ) { - $tmp_data["utimestamp"] = $last_timestamp + SECONDS_1DAY + 2*$module_interval; - - //check not init - $tmp_data["datos"] = $last_value === false ? false : null; - - // debug purpose - //$tmp_data["obs"] = "unknown extra"; - array_push($return[$pool_id]["data"], $tmp_data); - } - - //insert first slice data - $tmp_data["utimestamp"] = $current_timestamp; - $tmp_data["datos"] = $last_inserted_value; - // debug purpose - //$tmp_data["obs"] = "virtual data"; - - $return[$pool_id]["utimestamp"] = $current_timestamp; - array_push($return[$pool_id]["data"], $tmp_data); - - //insert raw data - while ( ($current_raw_data != null) && - ( ($current_timestamp_end >= $current_raw_data['utimestamp']) && - ($current_timestamp < $current_raw_data['utimestamp']) ) ) { - - // Add unknown state detected - $tmp_data["utimestamp"] = $current_raw_data["utimestamp"]; - $tmp_data["datos"] = $current_raw_data["datos"]; - // debug purpose - //$tmp_data["obs"] = "real data"; - array_push($return[$pool_id]["data"], $tmp_data); - - $last_value = $current_raw_data["datos"]; - $last_timestamp = $current_raw_data["utimestamp"]; - $current_raw_data = array_shift($raw_data); - } - - //unknown - $data_slices = $return[$pool_id]["data"]; - while ( ($current_unknown != null) && - ( ( ($current_unknown['time_from'] != null) && - ($current_timestamp_end >= $current_unknown['time_from']) ) || - ($current_timestamp_end >= $current_unknown['time_to']) ) ) { - - if( ( $current_timestamp < $current_unknown['time_from']) && - ( $current_timestamp_end >= $current_unknown['time_from'] ) ){ - // Add unknown state detected - $tmp_data["utimestamp"] = $current_unknown["time_from"]; - $tmp_data["datos"] = null; - // debug purpose - //$tmp_data["obs"] = "event data unknown from"; - array_push($return[$pool_id]["data"], $tmp_data); - $current_unknown["time_from"] = null; - } - - if( ($current_timestamp < $current_unknown['time_to']) && - ($current_timestamp_end >= $current_unknown['time_to'] ) ){ - $tmp_data["utimestamp"] = $current_unknown["time_to"]; - $i = count($data_slices) - 1; - while ($i >= 0) { - if($data_slices[$i]['utimestamp'] <= $current_unknown["time_to"]){ - $tmp_data["datos"] = - $data_slices[$i]['datos'] == null - ? $last_value - : $data_slices[$i]['datos']; - break; - } - $i--; + if (is_array($unknown_events)) { + $i = 0; + while ($current_timestamp >= $unknown_events[$i]["time_to"] ) { + // Skip unknown events in past + array_splice($unknown_events, $i,1); + $i++; + if (!isset($unknown_events[$i])) { + break; } - - // debug purpose - //$tmp_data["obs"] = "event data unknown to"; - array_push($return[$pool_id]["data"], $tmp_data); - $current_unknown = array_shift($unknown_events); } + if (isset($current_unknown)) { + + // check if recovered from unknown status + if(is_array($unknown_events) && isset($current_unknown)) { + if ( (($current_timestamp+$slice_size) > $current_unknown["time_to"]) + && ($current_timestamp < $current_unknown["time_to"]) + && ($in_unknown_status == 1) ) { + // Recovered from unknown + + if ( ($current_unknown["time_to"] > $current_timestamp) + && ($expected_data_generated == 0) ) { + // also add the "expected" data + $tmp_data["utimestamp"] = $current_timestamp; + if ($in_unknown_status == 1) { + $tmp_data["datos"] = null; + } + else { + $tmp_data["datos"] = $last_inserted_value; + } + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + $expected_data_generated = 1; + } + + + $tmp_data["utimestamp"] = $current_unknown["time_to"]; + $tmp_data["datos"] = $last_inserted_value; + // debug purpose + //$tmp_data["obs"] = "event recovery data"; + + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + $data_found = 1; + $in_unknown_status = 0; + } + + if ( (($current_timestamp+$slice_size) > $current_unknown["time_from"]) + && (($current_timestamp+$slice_size) < $current_unknown["time_to"]) + && ($in_unknown_status == 0) ) { + // Add unknown state detected + + if ( $current_unknown["time_from"] < ($current_timestamp+$slice_size)) { + if ( ($current_unknown["time_from"] > $current_timestamp) + && ($expected_data_generated == 0) ) { + // also add the "expected" data + $tmp_data["utimestamp"] = $current_timestamp; + if ($in_unknown_status == 1) { + $tmp_data["datos"] = null; + } + else { + $tmp_data["datos"] = $last_inserted_value; + } + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + $expected_data_generated = 1; + } + + $tmp_data["utimestamp"] = $current_unknown["time_from"]; + $tmp_data["datos"] = null; + // debug purpose + //$tmp_data["obs"] = "event data"; + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + $data_found = 1; + } + $in_unknown_status = 1; + } + + if ( ($in_unknown_status == 0) && ($current_timestamp >= $current_unknown["time_to"]) ) { + $current_unknown = array_shift($unknown_events); + } + } + } // unknown events handle } - //sort current slice - usort( - $return[$pool_id]['data'], - function ($a, $b) { - if ($a['utimestamp'] == $b['utimestamp']) return 0; - return ($a['utimestamp'] < $b['utimestamp']) ? -1 : 1; + // Search for data + $i=0; + if (is_array($raw_data)) { + foreach ($raw_data as $data) { + if ( ($data["utimestamp"] >= $current_timestamp) + && ($data["utimestamp"] < ($current_timestamp+$slice_size)) ) { + // Data in block, push in, and remove from $raw_data (processed) + + if ( ($data["utimestamp"] > $current_timestamp) + && ($expected_data_generated == 0) ) { + // also add the "expected" data + $tmp_data["utimestamp"] = $current_timestamp; + if ($in_unknown_status == 1) { + $tmp_data["datos"] = null; + } + else { + $tmp_data["datos"] = $last_inserted_value; + } + //$tmp_data["obs"] = "expected data"; + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + $expected_data_generated = 1; + } + + $tmp_data["utimestamp"] = intval($data["utimestamp"]); + $tmp_data["datos"] = $data["datos"]; + // debug purpose + //$tmp_data["obs"] = "real data"; + + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + + $last_inserted_value = $data["datos"]; + $last_timestamp = intval($data["utimestamp"]); + + unset($raw_data[$i]); + $data_found = 1; + $in_unknown_status = 0; + } + elseif ($data["utimestamp"] > ($current_timestamp+$slice_size)) { + // Data in future, stop searching new ones + break; + } } - ); - //put the last slice data like first element of next slice - $last_inserted_value = end($return[$pool_id]['data']); - $last_inserted_value = $last_inserted_value['datos']; - - //increment + $i++; + } + + if ($data_found == 0) { + // No data found, lug the last_value until SECONDS_1DAY + 2*modules_get_interval + // UNKNOWN! + + if (($current_timestamp > $now) || (($current_timestamp - $last_timestamp) > (SECONDS_1DAY + 2*$module_interval))) { + if (isset($last_inserted_value)) { + // unhandled unknown status control + $unhandled_time_unknown = $current_timestamp - (SECONDS_1DAY + 2*$module_interval) - $last_timestamp; + if ($unhandled_time_unknown > 0) { + // unhandled unknown status detected. Add to previous pool + $tmp_data["utimestamp"] = intval($last_timestamp) + (SECONDS_1DAY + 2*$module_interval); + $tmp_data["datos"] = null; + // debug purpose + //$tmp_data["obs"] = "unknown extra"; + // add to previous pool if needed + if (isset($return[$pool_id-1])) { + array_push($return[$pool_id-1]["data"], $tmp_data); + } + } + } + $last_inserted_value = null; + } + + $tmp_data["utimestamp"] = $current_timestamp; + + if ($in_unknown_status == 1) { + $tmp_data["datos"] = null; + } + else { + $tmp_data["datos"] = $last_inserted_value; + } + // debug purpose + //$tmp_data["obs"] = "virtual data"; + + $return[$pool_id]["utimestamp"] = $current_timestamp; + array_push($return[$pool_id]["data"], $tmp_data); + } + $pool_id++; - $current_timestamp = $current_timestamp_end; + $current_timestamp += $slice_size; } + return $return; } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index c91e71c07a..0c9bd6ebfb 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -550,6 +550,8 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); + + if($force_interval){ $resolution = $period/$time_interval; } @@ -580,29 +582,18 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, // Get event data (contains alert data too) $events = array(); if ($show_unknown == 1 || $show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter ( - 'tevento', + $events = db_get_all_rows_filter ('tevento', array ('id_agentmodule' => $agent_module_id, "utimestamp > $datelimit", "utimestamp < $date", 'order' => 'utimestamp ASC'), - array ('id_evento', 'evento', 'utimestamp', 'event_type'), - 'AND', - $search_in_history_db - ); + array ('id_evento', 'evento', 'utimestamp', 'event_type')); // Get the last event after inverval to know if graph start on unknown - $prev_event = db_get_row_filter ( - 'tevento', + $prev_event = db_get_row_filter ('tevento', array ('id_agentmodule' => $agent_module_id, "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_in_history_db - ); - + 'order' => 'utimestamp DESC')); if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { $start_unknown = true; } @@ -1127,7 +1118,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, global $config; global $graphic_type; - + if(!$fullscale){ $time_format_2 = ''; $temp_range = $period; @@ -1354,6 +1345,21 @@ function graphic_combined_module ($module_list, $weight_list, $period, continue; } + // if(empty($aux_array)){ + // foreach ($data as $key => $value) { + // $aux_array[$value['utimestamp']] = $value['datos']; + // } + // } else { + // foreach ($data as $key => $value) { + // if(array_key_exists($value['utimestamp'],$aux_array)){ + // $aux_array[$value['utimestamp']] = $aux_array[$value['utimestamp']] + $value['datos']; + // } else { + // $aux_array[$value['utimestamp']] = $value['datos']; + // } + // } + // } + + // html_debug($aux_array); if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) { if ($labels[$agent_module_id] != '') $module_name_list[$i] = $labels[$agent_module_id]; @@ -3986,33 +3992,22 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, if ($uncompressed_module) { $avg_only = 1; } + $search_in_history_db = db_search_in_history_db($datelimit); // Get event data (contains alert data too) if ($show_unknown == 1 || $show_events == 1 || $show_alerts == 1) { - $events = db_get_all_rows_filter( - 'tevento', + $events = db_get_all_rows_filter('tevento', array ('id_agentmodule' => $agent_module_id, "utimestamp > $datelimit", "utimestamp < $date", - 'order' => 'utimestamp ASC' - ), - array ('evento', 'utimestamp', 'event_type', 'id_evento'), - 'AND', - $search_in_history_db - ); + 'order' => 'utimestamp ASC'), + array ('evento', 'utimestamp', 'event_type', 'id_evento')); // Get the last event after inverval to know if graph start on unknown - $prev_event = db_get_row_filter ( - 'tevento', + $prev_event = db_get_row_filter ('tevento', array ('id_agentmodule' => $agent_module_id, "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC' - ), - false, - 'AND', - $search_in_history_db - ); - + 'order' => 'utimestamp DESC')); if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { $start_unknown = true; } @@ -4117,7 +4112,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, $zero = 0; $total = 0; $count = 0; - + $is_unknown = false; // Read data that falls in the current interval while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && @@ -4150,7 +4145,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, // Is the first point of a unknown interval $first_unknown = false; - $check_unknown = false; + $event_ids = array(); $alert_ids = array(); while (isset ($events[$k]) && @@ -4169,15 +4164,10 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, if ($is_unknown == false) { $first_unknown = true; } - else{ - $first_unknown = false; - } - $check_unknown = true; $is_unknown = true; } else if (substr ($events[$k]['event_type'], 0, 5) == 'going') { $is_unknown = false; - $first_unknown = false; } } $k++; @@ -4260,12 +4250,6 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, $chart[$timestamp]['unknown'.$series_suffix] = 0; } $chart[$timestamp]['unknown'.$series_suffix] = $unknown_value; - - if($unknown_value == 0 && $check_unknown == true){ - $chart[$timestamp]['unknown'.$series_suffix] = 1; - $check_unknown = false; - } - $series_type['unknown'.$series_suffix] = 'area'; } @@ -4396,138 +4380,165 @@ function fullscale_data ( &$chart_data, &$chart_extra_data, &$long_index, global $min_value; global $series_type; global $chart_extra_data; + + $ranges_unknown = db_get_module_ranges_unknown($agent_module_id, $datelimit, $date); - $first_data = 0; + $table = "tagente_datos"; + $module_type_str = modules_get_type_name ($agent_module_id); + if (strstr ($module_type_str, 'string') !== false) { + $table = "tagente_datos_string"; + } + $query = " SELECT utimestamp, datos FROM $table "; + $query .= " WHERE id_agente_modulo=$agent_module_id "; + $query .= " ORDER BY utimestamp ASC LIMIT 1"; + + $ret = db_get_all_rows_sql( $query , true); + + $first_data = $ret[0]['utimestamp']; $data_uncompress = db_uncompress_module_data($agent_module_id, $datelimit, $date); - - $chart_data = array(); - - $min_value = PHP_INT_MAX-1; - $max_value = PHP_INT_MIN+1; - $previous_data = $first_data; - $previous_unknown = 0; - - $i=0; - $current_event = $events[0]; - $prueba = array(); - foreach ($data_uncompress as $k) { - foreach ($k["data"] as $v) { - $real_date = date("Y M d H:i:s", $v['utimestamp']); - - if(!$flash_chart){ - $real_date = date("Y/M/d", $v['utimestamp']); - $real_date .= "\n"; - $real_date .= date(" H:i:s", $v['utimestamp']); - } - - $event_ids = array(); - $alert_ids = array(); - while (isset($current_event) && ($v['utimestamp'] >= $current_event["utimestamp"]) ) { - $event_date = date("Y M d H:i:s", $current_event['utimestamp']); + $i = 0; + $max_value = 0; + $min_value = 0; + $timestamp_second = 0; + if(is_array($data_uncompress)){ + foreach ($data_uncompress as $v) { + foreach ($v['data'] as $key => $value) { + $real_date = date("Y M d H:i:s", $value['utimestamp']); if(!$flash_chart){ - $event_date = date("Y/M/d", $current_event['utimestamp']); - $event_date .= "\n"; - $event_date .= date(" H:i:s", $current_event['utimestamp']); + $real_date = date("Y/M/d", $value['utimestamp']); + $real_date .= "\n"; + $real_date .= date(" H:i:s", $value['utimestamp']); } - - if ($show_events && (strpos($current_event["event_type"], "going") !== false)) { - $event_ids[$event_date][] = $current_event["id_evento"]; - - $chart_data[$event_date]["event" . $series_suffix] = 1; - $chart_data[$event_date]["alert" . $series_suffix] = NULL; - $chart_extra_data[count($chart_data)-1]['events'] = implode (',', $event_ids[$event_date]); + // Read events and alerts that fall in the current interval + $event_value = 0; + $alert_value = 0; + $unknown_value = 0; + $event_i = 0; + // Is the first point of a unknown interval + $first_unknown = false; + + $event_ids = array(); + $alert_ids = array(); + + // + if($timestamp_second == 0){ + $timestamp_second = $value['utimestamp']; } - elseif ($show_alerts && (strpos($current_event["event_type"], "alert") !== false)) { - $alert_ids[$event_date][] = $current_event["id_evento"]; - - $chart_data[$event_date]["event" . $series_suffix] = NULL; - $chart_data[$event_date]["alert" . $series_suffix] = 1; - $chart_extra_data[count($chart_data)-1]['alerts'] = implode (',', $alert_ids[$event_date]); + $timestamp_first = $timestamp_second; + $timestamp_second = $value['utimestamp']; + + foreach ($events as $key => $val) { + if( $val['utimestamp'] > $timestamp_first && + $val['utimestamp'] <= $timestamp_second ){ + if ($show_events == 1) { + $event_ids[] = $val['id_evento']; + $event_value++; + } + if ($show_alerts == 1 && substr ($val['event_type'], 0, 5) == 'alert') { + $alert_ids[] = $val['id_evento']; + $alert_value++; + } + if ($show_unknown) { + if ($val['event_type'] == 'going_unknown') { + if ($is_unknown == false) { + $first_unknown = true; + } + $is_unknown = true; + } + else if (substr ($val['event_type'], 0, 5) == 'going') { + $is_unknown = false; + } + } + } + } + + if(empty($value['datos'])){ + if($value['utimestamp'] < $first_data){ + //$chart_data[$real_date]['unknown'.$series_suffix] = 0; + $is_unknown = false; + } + else{ + //$chart_data[$real_date]['unknown'.$series_suffix] = 1; + $first_unknown = true; + } + } + + $timestamp_short = date("Y M d H:i:s", $value['utimestamp']); + + if(!$flash_chart){ + $timestamp_short = date("Y/M/d", $value['utimestamp']); + $timestamp_short .= "\n"; + $timestamp_short .= date(" H:i:s", $value['utimestamp']); + } + + + $long_index[$timestamp_short] = date( + html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $value['utimestamp']); + // In some cases, can be marked as known because a recovery event + // was found in same interval. For this cases first_unknown is + // checked too + if ($is_unknown || $first_unknown) { + $unknown_value++; + } + + // Data + if ($show_events) { + if (!isset($chart_data[$real_date]['event'.$series_suffix])) { + $chart_data[$real_date]['event'.$series_suffix] = 0; + } + + $chart_data[$real_date]['event'.$series_suffix] += $event_value; + + $series_type['event'.$series_suffix] = 'points'; + } + + if ($show_alerts) { + if (!isset($chart_data[$real_date]['alert'.$series_suffix])) { + $chart_data[$real_date]['alert'.$series_suffix] = 0; + } + + $chart_data[$real_date]['alert'.$series_suffix] += $alert_value; + + $series_type['alert'.$series_suffix] = 'points'; + } + + $chart_data[$real_date]['sum'.$series_suffix] = $value['datos']; + + if($value['datos'] > $max_value){ + $max_value = $value['datos']; + } + + if($value['datos'] < $min_value){ + $min_value = $value['datos']; } - $chart_data[$event_date]["sum" . $series_suffix] = $previous_data; - if($show_unknown) { - $chart_data[$event_date]["unknown" . $series_suffix] = $previous_unknown; - } - $current_event = $events[$i++]; - } - - if ($v["datos"] === NULL) { - // Unknown - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } - } - - $chart_data[$real_date]["sum" . $series_suffix] = $previous_data; - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = "1"; - } - $previous_unknown = "1"; - } - elseif($v["datos"] === false) { - // Not Init - $previous_data = $v["datos"]; - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if ($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if ($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } + if ($show_unknown) { + if (!isset($chart_data[$real_date]['unknown'.$series_suffix])) { + $chart_data[$real_date]['unknown'.$series_suffix] = 0; + } + $chart_data[$real_date]['unknown'.$series_suffix] = $unknown_value; + $series_type['unknown'.$series_suffix] = 'area'; } - $chart_data[$real_date]["sum" . $series_suffix] = $v["datos"]; - - if($v['datos'] >= $max_value){ - $max_value = $v['datos']; + if (!empty($event_ids)) { + $chart_extra_data[count($chart_data)-1]['events'] = implode(',',$event_ids); } - - if($v['datos'] <= $min_value){ - $min_value = $v['datos']; - } - - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = NULL; - $previous_unknown = NULL; + if (!empty($alert_ids)) { + $chart_extra_data[count($chart_data)-1]['alerts'] = implode(',',$alert_ids); } } - else { - $previous_data = $v["datos"]; - if (!isset($chart_data[$real_date]["event" . $series_suffix])) { - if ($show_events) { - $chart_data[$real_date]["event" . $series_suffix] = NULL; - } - if ($show_alerts) { - $chart_data[$real_date]["alert" . $series_suffix] = NULL; - } - } - - $chart_data[$real_date]["sum" . $series_suffix] = $v["datos"]; - - if($v['datos'] >= $max_value){ - $max_value = $v['datos']; - } - - if($v['datos'] <= $min_value){ - $min_value = $v['datos']; - } - - if($show_unknown) { - $chart_data[$real_date]["unknown" . $series_suffix] = NULL; - $previous_unknown = NULL; - } - } + } + + if (!is_null($percentil) && $percentil) { + $avg = array_map(function($item) { return $item['sum']; }, $chart_data); + $percentil_result = get_percentile($percentil, $avg); + //Fill the data of chart + array_walk($chart_data, function(&$item) use ($percentil_result, $series_suffix) { + $item['percentil' . $series_suffix] = $percentil_result; }); + $series_type['percentil' . $series_suffix] = 'line'; } } - $series_type['event'.$series_suffix] = 'points'; - $series_type['alert'.$series_suffix] = 'points'; - $series_type['unknown'.$series_suffix] = 'area'; } function grafico_modulo_boolean ($agent_module_id, $period, $show_events, diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 03f63e624c..bcdeb6819c 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2261,53 +2261,50 @@ function modules_change_relation_lock ($id_relation) { return ($result !== false ? $new_value : $old_value); } -/* - * @return utimestamp with the first contact of the module or first contact before datelimit, false if not-init - */ -function modules_get_first_date($id_agent_module, $datelimit = 0) { + + +function modules_get_count_datas($id_agent_module, $date_init, $date_end) { + $interval = modules_get_interval ($id_agent_module); + + // TODO REMOVE THE TIME IN PLANNED DOWNTIME + + if (!is_numeric($date_init)) { + $date_init = strtotime($date_init); + } + + if (!is_numeric($date_end)) { + $date_end = strtotime($date_end); + } + + + + $first_date = modules_get_first_contact_date($id_agent_module); + + + + if ($date_init < $first_date) { + $date_init = $first_date; + } + + $diff = $date_end - $date_init; + + + return ($diff / $interval); +} + + +function modules_get_first_contact_date($id_agent_module) { global $config; - //check datatype string or normal - $table = "tagente_datos"; - $module_type_str = modules_get_type_name ($id_agent_module); - if (strstr ($module_type_str, 'string') !== false) { - $table = "tagente_datos_string"; - } - - $search_historydb = false; - - // tagente_estado.first_utimestamp is not valid or is not updated. Scan DBs for first utimestamp - if ($datelimit > 0) { - // get last data before datelimit - $query = " SELECT max(utimestamp) as utimestamp FROM $table "; - $query .= " WHERE id_agente_modulo=$id_agent_module "; - $query .= " AND utimestamp < $datelimit "; + // TODO REMOVE THE TIME IN PLANNED DOWNTIME - } - else { - // get first utimestamp - $query = " SELECT min(utimestamp) as utimestamp FROM $table "; - $query .= " WHERE id_agente_modulo=$id_agent_module "; - } + // TODO FOR OTHER KIND OF DATA - - // SEARCH ACTIVE DB - $data = db_get_all_rows_sql($query,$search_historydb); - if (($data === false) || ($data[0]["utimestamp"] === NULL) || ($data[0]["utimestamp"] <= 0)) { - // first utimestamp not found in active database - // SEARCH HISTORY DB - $search_historydb = true; - $data = db_get_all_rows_sql($query,$search_historydb); - } - - if (($data === false) || ($data[0]["utimestamp"] === NULL) || ($data[0]["utimestamp"] <= 0)) { - // Nor active DB nor history DB have the data, the module is not-init - return array ("first_utimestamp" => false, "search_historydb" => $search_historydb); - } - - // The data has been found - return array ("first_utimestamp" => $data[0]["utimestamp"], "search_historydb" => $search_historydb); - + $first_date = db_get_value('utimestamp', 'tagente_datos', + 'id_agente_modulo', $id_agent_module, + $config['history_db_enabled']); + + return $first_date; } /** diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index e6f97bc829..6fe97ae606 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1767,11 +1767,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, if (timesize+timenewpos > canvaslimit) { $('#timestamp_'+graph_id).css('left', timenewpos - timesize); - $('#timestamp_'+graph_id).css('top', 50); } else { $('#timestamp_'+graph_id).css('left', timenewpos); - $('#timestamp_'+graph_id).css('top', 50); } } else { @@ -1814,16 +1812,24 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, plot.unhighlight(); if (item && item.series.label != '' && (item.series.label == legend_events || item.series.label == legend_events+series_suffix_str || item.series.label == legend_alerts || item.series.label == legend_alerts+series_suffix_str)) { plot.unhighlight(); + var canvaslimit = parseInt(plot.offset().left + plot.width()); var dataset = plot.getData(); + var timenewpos = parseInt(dataset[0].xaxis.p2c(pos.x)+plot.offset().left); + var extrasize = parseInt($('#extra_'+graph_id).css('width').split('px')[0]); + + var left_pos; + if (extrasize+timenewpos > canvaslimit) { + left_pos = timenewpos - extrasize - 20; + } + else { + left_pos = timenewpos - (extrasize / 2); + } var extra_info = 'No info to show'; var extra_show = false; - var coord_x = (item.dataIndex/item.series.xaxis.datamax)* (event.target.clientWidth - event.target.offsetLeft + 1) + event.target.offsetLeft; - - - $('#extra_'+graph_id).css('left',coord_x); - $('#extra_'+graph_id).css('top', event.target.offsetTop + 55 ); + $('#extra_'+graph_id).css('left',left_pos); + $('#extra_'+graph_id).css('top',plot.offset().top + 25); switch(item.series.label) { case legend_alerts+series_suffix_str: diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index f0fdf37082..ba7965fd63 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -111,6 +111,8 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $id = (int) get_parameter ("id", 0); // Agent id $agent_id = (int) modules_get_agentmodule_agent($id); + // Kind module + $type_module = modules_get_agentmodule_kind($id); if (empty($id) || empty($agent_id)) { ui_print_error_message(__('There was a problem locating the source of the graph')); @@ -169,6 +171,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); $time_compare_overlapped = get_parameter ("time_compare_overlapped", 0); $unknown_graph = get_parameter_checkbox ("unknown_graph", 1); + //$type_module == 'predictionserver'; $fullscale_sent = get_parameter ("fullscale_sent", 0); if(!$fullscale_sent){ if(!isset($config['full_scale_option']) || $config['full_scale_option'] == 0){ @@ -420,12 +423,14 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent); break; } - $data = array(); - $data[0] = __('Show full scale graph (TIP)'); - $data[1] = html_print_checkbox ("fullscale", 1, (bool) $fullscale, - true, false); - $table->data[] = $data; - $table->rowclass[] = ''; + if($type_module != 'predictionserver'){ + $data = array(); + $data[0] = __('Show full scale graph (TIP)'); + $data[1] = html_print_checkbox ("fullscale", 1, (bool) $fullscale, + true, false); + $table->data[] = $data; + $table->rowclass[] = ''; + } $form_table = html_print_table($table, true);