diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a3228e1490..cfd1e4f4f5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,30 @@ +2010-02-01 Sancho Lerena + + Changes ported from 3.0 branch. + + * include/javascript/pandora_visual_console.js: Thiner lines in maps. + + * include/functions_visual_map.php: Fixed several issues in visual maps + (bad hierarchy status color, limited depth for recursion, get unknown + for agents and modules, and line color is now always associated to + parent status) and non-status elements like labels, graphs or progress + bars now doesnt propagate module status to parents. + + * include/functions_db.php: Added parameter to get_db_all_rows_sql() to + avoid use of cache. Function process_sql() was not properly checking if + cache usage was disabled and was always using cache. Added support for + checking unknown status in get_agentmodule_status() function. + + * extensions/dbmanager/dbmanager.css, + extensions/dbmanager.php: Fixed width of textarea. + + * operation/events/events.php: Fixed bug #2943907. + + * operation/agentes/exportdata.php: Fixed problem exporting CSV + when data to export is TOO big, using an internal cache to read + data. + + 2010-02-01 Raúl Mateos * operation/agentes/estado_agente.php: Changed colour order for diff --git a/pandora_console/extensions/dbmanager.php b/pandora_console/extensions/dbmanager.php index e1bb81ce26..076eb9c9bc 100644 --- a/pandora_console/extensions/dbmanager.php +++ b/pandora_console/extensions/dbmanager.php @@ -63,12 +63,11 @@ function dbmgr_extension_main () { echo "
"; echo "Some samples of usage:
SHOW STATUS;
DESCRIBE tagente
SELECT * FROM tserver
UPDATE tagente SET id_grupo = 15 WHERE nombre LIKE '%194.179%'
"; - echo "

"; echo "
"; - print_textarea ('sql', 5, 50, html_entity_decode($sql, ENT_QUOTES)); + print_textarea ('sql', 5, 40, html_entity_decode($sql, ENT_QUOTES)); echo '
'; - echo '
'; + echo '
'; print_submit_button (__('Execute SQL'), '', false, 'class="sub next"'); echo '
'; echo ""; diff --git a/pandora_console/extensions/dbmanager/dbmanager.css b/pandora_console/extensions/dbmanager/dbmanager.css index ea2d0d7932..cb3adf34c3 100644 --- a/pandora_console/extensions/dbmanager/dbmanager.css +++ b/pandora_console/extensions/dbmanager/dbmanager.css @@ -22,9 +22,9 @@ table.dbmanager th { background: #888; } -textarea.dbmanager { +textarea { min-height: 50px; height: 50px; - width: 90%; + width: 95%; } diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 03a419bc29..6bcacc89e3 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC091231'; +$build_version = 'PC100202'; $pandora_version = 'v3.1-dev'; /* Help to debug problems. Override global PHP configuration */ diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index dbd84bc444..ac5beb0756 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1816,13 +1816,14 @@ function get_db_sql ($sql, $field = 0, $search_history_db = false) { * Get all the result rows using an SQL statement. * * @param string SQL statement to execute. + * @param bool If want to search in history database also + * @param bool If want to use cache (true by default) * * @return mixed A matrix with all the values returned from the SQL statement or * false in case of empty result */ -function get_db_all_rows_sql ($sql, $search_history_db = false) { +function get_db_all_rows_sql ($sql, $search_history_db = false, $cache = true) { global $config; - $cache = true; $history = array (); // Read from the history DB if necessary @@ -2072,7 +2073,9 @@ function process_sql ($sql, $rettype = "affected_rows", $dbconnection = '', $cac while ($row = mysql_fetch_array ($result)) { array_push ($retval, $row); } - $sql_cache[$sql] = $retval; + + if ($cache === true) + $sql_cache[$sql] = $retval; mysql_free_result ($result); } } @@ -2348,12 +2351,28 @@ function format_array_to_where_clause_sql ($values, $join = 'AND', $prefix = fal * module were fired. */ function get_agentmodule_status ($id_agentmodule = 0) { + $current_timestamp = get_system_time (); + $times_fired = get_db_value ('SUM(times_fired)', 'talert_template_modules', 'id_agent_module', $id_agentmodule); if ($times_fired > 0) { return 4; // Alert } - $status = get_db_value ('estado', 'tagente_estado', 'id_agente_modulo', $id_agentmodule); + + + $status_row = get_db_row ("tagente_estado", "id_agente_modulo", $id_agentmodule); + + // Not init or current_interval == 0: Return current status and avoid problems here ! + if ($status_row["current_interval"] == 0) + return $status_row["estado"]; + + // Unknown status + if ( ($status_row["current_interval"] * 2) + $status_row["utimestamp"] < $current_timestamp){ + $status = 3; + } + else { + $status = $status_row['estado']; + } return $status; } @@ -2470,7 +2489,7 @@ function get_agentmodule_data ($id_agent_module, $period, $date = 0) { AND utimestamp > %d AND utimestamp <= %d ORDER BY utimestamp ASC", $id_agent_module, $datelimit, $date); - $values = get_db_all_rows_sql ($sql, true); + $values = get_db_all_rows_sql ($sql, true, false); if ($values === false) { return array (); diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 673d826086..09414b9b6b 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -59,34 +59,73 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = if ($layout_datas !== false) { foreach ($layout_datas as $layout_data) { + + // **************************************************************** + // Get parent status (Could be an agent, module, map, others doesnt have parent info) + // **************************************************************** + + if ($layout_data["parent_item"] != 0){ + $id_agent_module_parent = get_db_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); + $id_agent_parent = get_db_value ("id_agent", "tlayout_data", "id", $layout_data["parent_item"]); + $id_layout_linked = get_db_value ("id_layout_linked", "tlayout_data", "id", $layout_data["parent_item"]); + + // Module + if ($id_agent_module_parent != 0) { + $status_parent = get_agentmodule_status ($id_agent_module_parent); + // Agent + } + elseif ($id_agent_parent != 0) { + $status_parent = get_agent_status ($id_agent_parent); + } + // Another layout/map + elseif ($id_layout_linked != 0) { + $status_parent = get_layout_status ($id_layout_linked); + } + + else { + $status_parent = 3; + } + + } else { + $id_agent_module_parent = 0; + $status_parent = 3; + } + + + // **************************************************************** + // Get STATUS of current object + // **************************************************************** + // Linked to other layout ?? - Only if not module defined if ($layout_data['id_layout_linked'] != 0) { $status = get_layout_status ($layout_data['id_layout_linked']); - $status_parent = 3; - } else { + + // Single object + } elseif ($layout_data["type"] == 0) { // Status for a simple module if ($layout_data['id_agente_modulo'] != 0) { - $id_agent = get_db_value ("id_agente", "tagente_estado", "id_agente_modulo", $layout_data['id_agente_modulo']); - $id_agent_module_parent = get_db_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); - // Item value $status = get_agentmodule_status ($layout_data['id_agente_modulo']); - if ($layout_data['no_link_color'] == 1) - $status_parent = 3; - else - $status_parent = get_agentmodule_status ($id_agent_module_parent); - // Status for a whole agent + $id_agent = get_db_value ("id_agente", "tagente_estado", "id_agente_modulo", $layout_data['id_agente_modulo']); + + // Status for a whole agent, if agente_modulo was == 0 } elseif ($layout_data['id_agent'] != 0) { $status = get_agent_status ($layout_data["id_agent"]); - $status_parent = $status; + if ($status == -1) // get_agent_status return -1 for unknown! + $status = 3; $id_agent = $layout_data["id_agent"]; } else { $status = 3; - $status_parent = 3; $id_agent = 0; } + } else { + // If it's a graph, a progress bar or a data tag, ALWAYS report + // status OK (=0) to avoid confussions here. + $status = 0; } - + + // **************************************************************** // STATIC IMAGE (type = 0) + // **************************************************************** if ($layout_data['type'] == 0) { // Link image //index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=1 @@ -110,11 +149,14 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = if ($show_links) { if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { + // Link to an agent echo ''; } elseif ($layout_data['id_layout_linked'] > 0) { + // Link to a map echo ''; + } else { // A void object echo ''; @@ -184,7 +226,9 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo "
"; } + // **************************************************************** // SIMPLE DATA VALUE (type = 2) + // **************************************************************** switch ($layout_data['type']) { case 2: if ($resizedMap) @@ -195,6 +239,10 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo get_db_value ('datos', 'tagente_estado', 'id_agente_modulo', $layout_data['id_agente_modulo']); echo ''; break; + + // **************************************************************** + // Progress bar + // **************************************************************** case 3: // Percentile bar (type = 3) @@ -220,6 +268,10 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo ''; //} break; + + // **************************************************************** + // Single module graph + // **************************************************************** case 1; // SINGLE GRAPH (type = 1) if ($resizedMap) @@ -263,12 +315,25 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = } */ + // **************************************************************** + // Lines joining objects + // **************************************************************** // Get parent relationship - Create line data if ($layout_data["parent_item"] != "" && $layout_data["parent_item"] != 0) { $line['id'] = $layout_data['id']; $line['node_begin'] = 'layout-data-'.$layout_data["parent_item"]; $line['node_end'] = 'layout-data-'.$layout_data["id"]; - $line['color'] = $status_parent ? '#00dd00' : '#dd0000'; + switch ($status_parent) { + case 3: $line["color"] = "#ccc"; // Gray + break; + case 2: $line["color"] = "#20f6f6"; // Yellow + break; + case 0: $line["color"] = "#00ff00"; // Green + break; + case 4: + case 1: $line["color"] = "#ff0000"; // Red + break; + } array_push ($lines, $line); } } @@ -350,12 +415,19 @@ function get_user_layouts ($id_user = 0, $only_names = false, $filter = false) { * are OK. If any of them is down, then result is down (0) * * @param int Id of the layout + * @param int Depth (for recursion control) * * @return bool The status of the given layout. True if it's OK, false if not. */ -function get_layout_status ($id_layout = 0) { +function get_layout_status ($id_layout = 0, $depth = 0) { $temp_status = 0; $temp_total = 0; + $depth++; // For recursion depth checking + + // TODO: Implement this limit as a configurable item in setup + if ($depth > 10){ + return 3; // No status data if we need to exit by a excesive recursion + } $id_layout = (int) $id_layout; @@ -371,7 +443,7 @@ function get_layout_status ($id_layout = 0) { continue; // Other Layout (Recursive!) if (($data["id_layout_linked"] != 0) && ($data["id_agente_modulo"] == 0)) { - $status = get_layout_status ($data["id_layout_linked"]); + $status = get_layout_status ($data["id_layout_linked"], $depth); // Module } elseif ($data["id_agente_modulo"] != 0) { $status = get_agentmodule_status ($data["id_agente_modulo"]); diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js index b14d310aba..0e4e41946d 100644 --- a/pandora_console/include/javascript/pandora_visual_console.js +++ b/pandora_console/include/javascript/pandora_visual_console.js @@ -18,7 +18,7 @@ function draw_line (line, id_div) { div = document.getElementById (id_div); brush = new jsGraphics (div); - brush.setStroke (2); + brush.setStroke (1); brush.setColor (line['color']); if (line['x1']) { x1 = line['x']; diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index 5aeb3099ef..57b27ecde7 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -81,6 +81,12 @@ $export_type = get_parameter_post ('export_type', 'data'); $export_btn = get_parameter_post ('export_btn', 0); if (!empty ($export_btn) && !empty ($module)) { + + // Disable SQL cache + global $sql_cache; + $sql_cache = array ('saved' => 0); + + //Convert start time and end time to unix timestamps $start = strtotime ($start_date." ".$start_time); $end = strtotime ($end_date." ".$end_time); @@ -92,47 +98,17 @@ if (!empty ($export_btn) && !empty ($module)) { print_error_message (__('Invalid time specified')); return; } - - // Data - $data = array (); - switch ($export_type) { - case "data": - case "excel": - case "csv": - foreach ($module as $selected) { - $data_single = get_agentmodule_data ($selected, $period, $end); - if (!empty ($data_single)) { - $data = array_merge ($data, $data_single); - } - } - break; - case "avg": - foreach ($module as $selected) { - $arr = array (); - $arr["data"] = get_agentmodule_data_average ($selected, $period, $end); - if ($arr["data"] === false) { - continue; - } - $arr["module_name"] = get_agentmodule_name ($selected); - $arr["agent_name"] = get_agentmodule_agent_name ($selected); - $arr["agent_id"] = get_agentmodule_agent ($selected); - $arr["utimestamp"] = $end; - array_push ($data, $arr); - } - break; - default: - print_error_message (__('Invalid method supplied')); - return; - break; - } - + + // *************************************************** // Starts, ends and dividers + // *************************************************** + switch ($export_type) { case "data": case "avg": default: //HTML output - don't style or use XHTML just in case somebody needs to copy/paste it. (Office doesn't handle and ) - $datastart = ''; + $datastart = '
'.__('Agent').''.__('Module').''.__('Data').''.__('Timestamp').'
'; $rowstart = ''; @@ -158,42 +134,124 @@ if (!empty ($export_btn) && !empty ($module)) { break; } - $output = $datastart; - foreach ($data as $key => $module) { - $output .= $rowstart; - $output .= $module['agent_name']; - $output .= $divider; - $output .= $module['module_name']; - $output .= $divider; - $output .= $module['data']; - $output .= $divider; - $output .= date ($config["date_format"], $module['utimestamp']); - $output .= $rowend; - } - $output .= $dataend; - + // *************************************************** + // Header output + // *************************************************** + + + switch ($export_type) { - default: - case "data": - case "avg": - echo $output; - return; - break; case "excel": case "csv": - //Encase into a file and offer download - //Flush buffers - we don't need them. $config['ignore_callback'] = true; while (@ob_end_clean ()); + header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=export_".date("Ymd", $start)."_".date("Ymd", $end).".".$extension); header("Pragma: no-cache"); header("Expires: 0"); - echo $output; - exit; - //Exit necessary so it doesn't continue processing and give erroneous downloads + } + + // *************************************************** + // Data processing + // *************************************************** + + $data = array (); + switch ($export_type) { + case "data": + case "excel": + case "csv": + + // Show header + echo $datastart; + + foreach ($module as $selected) { + + $output = ""; + $work_period = 120000; + + $work_end = $end - $period + $work_period; + //Buffer to get data, anyway this will report a memory exhaustin + + while ( $work_end < $end) { + $work_end = $work_end + $work_period; + + $data = array (); // Reinitialize array for each module chunk + $data_single = get_agentmodule_data ($selected, $work_period, $work_end); + if (!empty ($data_single)) { + $data = array_merge ($data, $data_single); + } + +/* + if ($work_end > $end) { + $work_period = $work_end - $end; + $work_end = $end; + } +*/ + foreach ($data as $key => $module) { + $output .= $rowstart; + $output .= $module['agent_name']; + $output .= $divider; + $output .= $module['module_name']; + $output .= $divider; + $output .= $module['data']; + $output .= $divider; + $output .= date ("Y-m-d g:i:s", $module['utimestamp']); + $output .= $rowend; + } + + switch ($export_type) { + default: + case "data": + case "avg": + echo $output; + break; + case "excel": + case "csv": + echo $output; + break; + } + unset($output); + $output = ""; + unset($data); + unset($data_single); + } + unset ($output); + $output = ""; + } // main foreach + echo $dataend; + break; + + case "avg": + foreach ($module as $selected) { + $arr = array (); + $arr["data"] = get_agentmodule_data_average ($selected, $period, $end); + if ($arr["data"] === false) { + continue; + } + $arr["module_name"] = get_agentmodule_name ($selected); + $arr["agent_name"] = get_agentmodule_agent_name ($selected); + $arr["agent_id"] = get_agentmodule_agent ($selected); + $arr["utimestamp"] = $end; + array_push ($data, $arr); + } + break; + default: + print_error_message (__('Invalid method supplied')); + return; break; } + +switch ($export_type) { + case "excel": + case "csv": + exit; // Necesary for CSV export, if not give problems + break; + default: + return; +} + + } elseif (!empty ($export_btn) && empty ($module)) { print_error_message (__('No modules specified')); } @@ -252,14 +310,14 @@ if ($agent > 0) { $table->data[2][1] = print_select ($modules, "module_arr[]", array_keys ($modules), '', '', 0, true, true, true, 'w130', false); //Start date selector -$table->data[3][0] = ''.__('Begin date (*)').''; +$table->data[3][0] = ''.__('Begin date').''; $table->data[3][1] = print_input_text ('start_date', date ("Y-m-d", get_system_time () - 86400), false, 10, 10, true); $table->data[3][1] .= print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => 'scwShow(scwID("text-start_date"),this);')); $table->data[3][1] .= print_input_text ('start_time', date ("H:m", get_system_time () - 86400), false, 10, 5, true); //End date selector -$table->data[4][0] = ''.__('End date (*)').''; +$table->data[4][0] = ''.__('End date').''; $table->data[4][1] = print_input_text ('end_date', date ("Y-m-d", get_system_time ()), false, 10, 10, true); $table->data[4][1] .= print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => 'scwShow(scwID("text-end_date"),this);')); $table->data[4][1] .= print_input_text ('end_time', date ("H:m", get_system_time ()), false, 10, 5, true); diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 2fcc84ae0c..f8d92b15f4 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -430,11 +430,11 @@ foreach ($result as $event) { // Colored box if ($event["estado"] == 0) { $img = "images/tick_off.png"; - $title = __('Event validated'); + $title = __('Event not validated'); } else { $img = "images/tick.png"; - $title = __('Event not validated'); + $title = __('Event validated'); } $data[0] = print_image ($img, true, array ("class" => "image_status", @@ -504,7 +504,7 @@ foreach ($result as $event) { array ("title" => __('Go to alert overview'))); $data[5] .= ''; } - + $data[6] = print_group_icon ($event["id_grupo"], true); if ($group_rep == 1) { @@ -512,8 +512,8 @@ foreach ($result as $event) { } else { if (!empty ($event["estado"])) { - if ($event["id_usuario"] != '0' && $event["id_usuario"] != ''){ - $data[7] = ''.mb_substr ($event["id_usuario"],0,8).''; + if ($event["id_usuario"] != '0' && $event["id_usuario"] != '' && $event["id_usuario"] != 'system' && $event["id_usuario"] != "System"){ + $data[7] = ''.mb_substr ($event["id_usuario"],0,8).''; } else { $data[7] = __('System');
'.__('Agent').''.__('Module').''.__('Data').''.__('Timestamp').'
'; $divider = ''; $rowend = '