From 20d5276ff0eb5a86143f05f5936017a6269c31bd Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 4 Feb 2013 14:07:28 +0000 Subject: [PATCH] 2013-02-04 Miguel de Dios * include/functions_xml.php, include/functions_reporting.php, operation/reporting/reporting_xml.php: fixed the SLA agent name with entities differents to hexadecimal entities. And fixed the serialized data when has not separators. Fixes: #3602204 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7571 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 9 +++ .../include/functions_reporting.php | 31 +++++--- pandora_console/include/functions_xml.php | 9 ++- .../operation/reporting/reporting_xml.php | 72 +++++++++++++------ 4 files changed, 89 insertions(+), 32 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 4e987daed3..00a66097f5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2013-02-04 Miguel de Dios + + * include/functions_xml.php, include/functions_reporting.php, + operation/reporting/reporting_xml.php: fixed the SLA agent name + with entities differents to hexadecimal entities. And fixed the + serialized data when has not separators. + + Fixes: #3602204 + 2013-02-04 Miguel de Dios * godmode/reporting/reporting_builder.item_editor.php: fixed lost diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f97e3c2276..838376e26d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -22,17 +22,17 @@ /** * Include the usual functions */ -require_once ($config["homedir"]."/include/functions.php"); -require_once ($config["homedir"]."/include/functions_db.php"); -require_once ($config["homedir"]."/include/functions_agents.php"); +require_once($config["homedir"] . "/include/functions.php"); +require_once($config["homedir"] . "/include/functions_db.php"); +require_once($config["homedir"] . "/include/functions_agents.php"); include_once($config["homedir"] . "/include/functions_groups.php"); -require_once ('functions_graph.php'); +require_once($config["homedir"] . '/include/functions_graph.php'); include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_events.php"); include_once($config['homedir'] . "/include/functions_alerts.php"); include_once($config['homedir'] . '/include/functions_users.php'); -enterprise_include_once ('include/functions_metaconsole.php'); -enterprise_include_once ('include/functions_inventory.php'); +enterprise_include_once('include/functions_metaconsole.php'); +enterprise_include_once('include/functions_inventory.php'); include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); @@ -3633,6 +3633,9 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f if ($content['header_definition'] != '') { $table2->head = explode('|', $content['header_definition']); } + else { + $table2->head[] = __('Data'); + } array_unshift($table2->head, __('Date')); $datelimit = $report["datetime"] - $content['period']; @@ -3658,10 +3661,20 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $table2->data = array(); foreach ($result as $row) { $date = date ($config["date_format"], $row['utimestamp']); - $serialized = $row['datos']; - $rowsUnserialize = explode($content['line_separator'], $serialized); + $serialized = $row['datos']; + + $rowsUnserialize = (array)$serialized; + if (!empty($content['line_separator'])) { + $rowsUnserialize = explode($line_separator, + $serialized); + } + foreach ($rowsUnserialize as $rowUnser) { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); + $columnsUnserialize = (array)$rowUnser; + if (!empty($content['column_separator'])) { + $columnsUnserialize = explode($content['column_separator'], $rowUnser); + } + array_unshift($columnsUnserialize, $date); array_push($table2->data, $columnsUnserialize); } diff --git a/pandora_console/include/functions_xml.php b/pandora_console/include/functions_xml.php index f9540baae0..da291e3ef4 100644 --- a/pandora_console/include/functions_xml.php +++ b/pandora_console/include/functions_xml.php @@ -21,7 +21,7 @@ include_once ('include/functions_netflow.php'); //xml con los datos de un agente function xml_file_agent_data ($agent_data = array(), $file_temp) { $file = fopen($file_temp, 'a+'); - + $content_report = " ". $agent_data['nombre']."\n"; $content_report .= " ". $agent_data['comentarios']."\n"; $content_report .= " ".$agent_data['direccion']."\n"; @@ -49,7 +49,7 @@ function xml_file_agent_data ($agent_data = array(), $file_temp) { $result = fwrite($file, $content_report); $position++; - + fclose($file); return $position; } @@ -62,7 +62,7 @@ function xml_file_agent_conf ($modules = array(), $file_temp, $position = 0, $id foreach ($modules as $module) { $content_report = " \n"; - + $content_report .= " ".$module['nombre']."\n"; $content_report .= " ".$module['id_agente_modulo']."\n"; $content_report .= " ".$module['id_tipo_modulo']."\n"; @@ -101,6 +101,7 @@ function xml_file_agent_conf ($modules = array(), $file_temp, $position = 0, $id $position++; } fclose($file); + return $position; } @@ -142,6 +143,7 @@ function xml_file_event ($events = array(), $file_temp, $position = 0, $id_agent } fclose($file); + return $position; } @@ -163,6 +165,7 @@ function xml_file_graph ($data_module = array(), $file_temp, $position = 0) { } fclose($file); + return $position; } ?> diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 7e30df722a..80577022c8 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -164,7 +164,9 @@ $time = (string) get_parameter ('time', date ('h:iA')); $datetime = strtotime ($date.' '.$time); if ($datetime === false || $datetime == -1) { - echo "Invalid date selected"; //Not translatable because this is an error message and might have to be used on the other end + //Not translatable because this is an error message and might have + //to be used on the other end + echo "Invalid date selected"; exit; } @@ -291,7 +293,7 @@ foreach ($contents as $content) { $position = 0; while ($offset < $data_count) { - $sql = "SELECT * + $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; @@ -381,7 +383,7 @@ foreach ($contents as $content) { case 2: case 'custom_graph': case 'automatic_custom_graph': - + $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); @@ -406,38 +408,44 @@ foreach ($contents as $content) { $date_init = $date_end - $content['period']; /// $temp_file = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - + $file = fopen ($temp_file, 'a+'); - + $buffer_file["objdata"] = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - + $limit = 1000; $offset = 0; - - $sql_count = "SELECT COUNT(id_agente_modulo) FROM tagente_datos WHERE id_agente_modulo=".$content2['id_agent_module']." + + $sql_count = "SELECT COUNT(id_agente_modulo) + FROM tagente_datos + WHERE id_agente_modulo=".$content2['id_agent_module']." AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; $data_count = db_get_value_sql($sql_count); - + if ($data_count == false) { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); - } else if ($data_count <= $limit) { + } + else if ($data_count <= $limit) { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content2['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - + $sql = "SELECT * + FROM tagente_datos + WHERE id_agente_modulo=".$content2['id_agent_module']." + AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; + $data_module = db_get_all_rows_sql($sql); xml_file_graph ($data_module, $temp_file); $file = fopen ($temp_file, 'a+'); $content_report = " \n"; $result = fwrite($file, $content_report); - - } else { + + } + else { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); @@ -486,7 +494,7 @@ foreach ($contents as $content) { } $sla_data = array (); - $sla_data["agent"] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); + $sla_data["agent"] = io_safe_output(modules_get_agentmodule_agent_name ($sla['id_agent_module'])); $sla_data["module"] = modules_get_agentmodule_name ($sla['id_agent_module']); $sla_data["max"] = $sla['sla_max']; $sla_data["min"] = $sla['sla_min']; @@ -958,14 +966,27 @@ foreach ($contents as $content) { if ($content['header_definition'] != '') { $tags = explode('|', $content['header_definition']); } + else { + $tags[] = 'Data'; + } array_unshift($tags, 'Date'); $datelimit = $report["datetime"] - $content['period']; $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos_string + FROM tagente_datos WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' AND utimestamp <= ' . $report["datetime"]); + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"]); + + // Adds string data if there is no numeric data + if ((count($result) < 0) or (!$result)){ + $result = db_get_all_rows_sql('SELECT * + FROM tagente_datos_string + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"]); + } if ($result === false) { $result = array(); } @@ -974,9 +995,20 @@ foreach ($contents as $content) { foreach ($result as $row) { $date = date ($config["date_format"], $row['utimestamp']); $serialized = $row['datos']; - $rowsUnserialize = explode($content['line_separator'], $serialized); + + $rowsUnserialize = (array)$serialized; + if (!empty($content['line_separator'])) { + $rowsUnserialize = explode($line_separator, + $serialized); + } + foreach ($rowsUnserialize as $rowUnser) { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); + + $columnsUnserialize = (array)$rowUnser; + if (!empty($content['column_separator'])) { + $columnsUnserialize = explode($content['column_separator'], $rowUnser); + } + array_unshift($columnsUnserialize, $date); $objdata = array ();