From 68fc7e09b58733c24afc1eda09d6c2077b51e8e0 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 14 Feb 2013 13:37:33 +0000 Subject: [PATCH] 2013-02-14 Miguel de Dios * include/functions_netflow.php, operation/netflow/nf_live_view.php: fixed the show pie graph with table. Fixes: #3604468 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7653 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 + pandora_console/include/functions_netflow.php | 156 ++++++++++++------ .../operation/netflow/nf_live_view.php | 22 ++- 3 files changed, 125 insertions(+), 60 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 840631d721..f9da08d77d 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2013-02-14 Miguel de Dios + + * include/functions_netflow.php, operation/netflow/nf_live_view.php: + fixed the show pie graph with table. + + Fixes: #3604468 + 2013-02-14 Sergio Martin * pandoradb_data.sql: Fixed the macros of the diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 3fc7f0c463..843c7323ee 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -366,7 +366,9 @@ function netflow_summary_table ($data) { $table->data[5][0] = ''.__('Average bytes per packet').''; $table->data[5][1] = format_numeric ($data['avgbpp']); - return html_print_table ($table, true); + $html = html_print_table ($table, true); + + return $html; } /** @@ -821,13 +823,11 @@ function netflow_get_filter_arguments ($filter) { * */ function netflow_get_chart_types () { - return array( - __('Area graph'), - __('Pie graph'), - __('Data table'), - __('Statistics table'), - __('Summary table')); + 'netflow_area' => __('Area graph'), + 'netflow_pie_summatory' => __('Pie graph and Summary table'), + 'netflow_statistics' => __('Statistics table'), + 'netflow_data' => __('Data table')); } /** @@ -923,7 +923,8 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } $html .= graph_netflow_aggregate_area ($data, $interval, 850, 320, netflow_format_unit ($unit)); return $html; - } else if ($output == 'PDF') { + } + else if ($output == 'PDF') { $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); $html .= " " . __('Aggregate') . ": " . netflow_format_aggregate ($aggregate); if ($interval_length != 0) { @@ -931,7 +932,8 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } $html .= graph_netflow_aggregate_area ($data, $interval, 850, 320, netflow_format_unit ($unit), 2, true); return $html; - } else if ($output == 'XML') { + } + else if ($output == 'XML') { $xml = "$unit\n"; $xml .= "$aggregate\n"; $xml .= "$interval_length\n"; @@ -947,14 +949,16 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } $html .= graph_netflow_total_area ($data, $interval, 660, 320, netflow_format_unit ($unit)); return $html; - } else if ($output == 'PDF') { + } + else if ($output == 'PDF') { $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); if ($interval_length != 0) { $html .= " " . _('Resolution') . ": $interval_length " . __('seconds'); } $html .= graph_netflow_total_area ($data, $interval, 660, 320, netflow_format_unit ($unit), 2, true); return $html; - } else if ($output == 'XML') { + } + else if ($output == 'XML') { $xml = "$unit\n"; $xml .= "$interval_length\n"; $xml .= netflow_total_area_xml ($data); @@ -962,31 +966,6 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } } break; - case '1': - case 'netflow_pie': - $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); - if (empty ($data)) { - break; - } - if ($output == 'HTML') { - $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); - $html .= " " . __('Aggregate') . ": " . netflow_format_aggregate ($aggregate); - $html .= graph_netflow_aggregate_pie ($data, netflow_format_aggregate ($aggregate)); - return $html; - } - else if ($output == 'PDF') { - $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); - $html .= " " . __('Aggregate') . ": $aggregate"; - $html .= graph_netflow_aggregate_pie ($data, netflow_format_aggregate ($aggregate), 2, true); - return $html; - } - else if ($output == 'XML') { - $xml = "$unit\n"; - $xml .= "$aggregate\n"; - $xml .= netflow_aggregate_pie_xml ($data); - return $xml; - } - break; case '2': case 'netflow_data': $data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name); @@ -1015,7 +994,8 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi break; case '3': case 'netflow_statistics': - $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); + $data = netflow_get_stats ($start_date, $end_date, $filter, + $aggregate, $max_aggregates, $unit, $connection_name); if (empty ($data)) { break; } @@ -1028,21 +1008,87 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi break; case '4': case 'netflow_summary': - - $data = netflow_get_summary ($start_date, $end_date, $filter, $connection_name); + $data_summary = netflow_get_summary ($start_date, $end_date, + $filter, $connection_name); if (empty ($data)) { break; } if ($output == 'HTML' || $output == 'PDF') { - return netflow_summary_table ($data); - } else if ($output == 'XML') { - return netflow_summary_xml ($data); + return netflow_summary_table ($data_summary); + } + else if ($output == 'XML') { + return netflow_summary_xml ($data_summary); + } + break; + case '1': + case 'netflow_pie': + $data_pie = netflow_get_stats ($start_date, $end_date, + $filter, $aggregate, $max_aggregates, $unit, + $connection_name); + if (empty ($data_pie)) { + break; + } + if ($output == 'HTML') { + $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); + $html .= " " . __('Aggregate') . ": " . netflow_format_aggregate ($aggregate); + $html .= graph_netflow_aggregate_pie ($data_pie, netflow_format_aggregate ($aggregate)); + return $html; + } + else if ($output == 'PDF') { + $html = "" . __('Unit') . ": " . netflow_format_unit ($unit); + $html .= " " . __('Aggregate') . ": $aggregate"; + $html .= graph_netflow_aggregate_pie ($data_pie, netflow_format_aggregate ($aggregate), 2, true); + return $html; + } + else if ($output == 'XML') { + $xml = "$unit\n"; + $xml .= "$aggregate\n"; + $xml .= netflow_aggregate_pie_xml ($data_pie); + return $xml; + } + break; + case 'netflow_pie_summatory': + $data_summary = netflow_get_summary ($start_date, $end_date, + $filter, $connection_name); + if (empty ($data_summary)) { + break; + } + + $data_pie = netflow_get_stats ($start_date, $end_date, + $filter, $aggregate, $max_aggregates, $unit, + $connection_name); + if (empty ($data_pie)) { + break; + } + + switch ($output) { + case 'HTML': + $html = ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
'; + $html .= netflow_summary_table ($data_summary); + $html .= "" . __('Unit') . ": " . + netflow_format_unit ($unit); + $html .= " " . __('Aggregate') . ": " . netflow_format_aggregate ($aggregate); + $html .= ''; + $html .= graph_netflow_aggregate_pie ($data_pie, netflow_format_aggregate ($aggregate)); + $html .= '
'; + return $html; + break; + case 'PDF': + break; + case 'XML': + return netflow_summary_xml ($data_summary); + break; } break; default: break; } - + if ($output == 'HTML' || $output == 'PDF') { return fs_error_image(); } @@ -1078,20 +1124,26 @@ function netflow_xml_report ($id, $start_date, $end_date, $interval_length = 0) echo " " . io_safe_output ($report['description']) . "\n"; echo " " . date ("r", $start_date) . "\n"; echo " " . date ("r", $end_date) . "\n"; - + // Get netflow item types $item_types = netflow_get_chart_types (); // Print report items - $report_contents = db_get_all_rows_sql ("SELECT * FROM tnetflow_report_content WHERE id_report='" . $report['id_report'] . "' ORDER BY `order`"); + $report_contents = db_get_all_rows_sql ("SELECT * + FROM tnetflow_report_content + WHERE id_report='" . $report['id_report'] . "' + ORDER BY `order`"); foreach ($report_contents as $content) { - - // Get item filters - $filter = db_get_row_sql("SELECT * FROM tnetflow_filter WHERE id_sg = '" . io_safe_input ($content['id_filter']) . "'", false, true); - if ($filter === FALSE) { + + // Get item filters + $filter = db_get_row_sql("SELECT * + FROM tnetflow_filter + WHERE id_sg = '" . io_safe_input ($content['id_filter']) . "'", + false, true); + if ($filter === FALSE) { continue; } - + echo " \n"; echo " " . io_safe_output ($content['description']) . "\n"; echo " " . io_safe_output ($item_types[$content['show_graph']]) . "\n"; @@ -1106,9 +1158,9 @@ function netflow_xml_report ($id, $start_date, $end_date, $interval_length = 0) echo " " . io_safe_output ($filter['aggregate']) . "\n"; echo " " . io_safe_output ($filter['output']) . "\n"; echo " \n"; - + echo netflow_draw_item ($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $report['server_name'], 'XML'); - + echo " \n"; } echo "\n"; diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index 2d2ba02b6e..c270d18c05 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -82,7 +82,7 @@ $filter['advanced_filter'] = get_parameter('advanced_filter',''); $filter['advanced_filter'] = get_parameter('advanced_filter',''); // Read chart configuration -$chart_type = (int) get_parameter('chart_type', 0); +$chart_type = get_parameter('chart_type', 'netflow_area'); $max_aggregates = (int) get_parameter('max_aggregates', 0); $period = (int) get_parameter('period', '86400'); $update_date = (int) get_parameter('update_date', 0); @@ -105,7 +105,9 @@ if (! defined ('METACONSOLE')) { //Header ui_print_page_header (__('Netflow live view'), "images/networkmap/so_cisco_new.png", false, "", false, array ()); if (! is_executable ($config['netflow_nfdump'])) { - ui_print_error_message(__('nfdump binary not found!')); + ui_print_error_message( + sprintf(__('nfdump binary (%s) not found!'), + $config['netflow_nfdump'])); } } else { @@ -142,8 +144,10 @@ else if ($update != '' && check_acl ($config["id_user"], 0, "AW")) { // Save filter args $filter_copy['filter_args'] = netflow_get_filter_arguments ($filter_copy); - $result = db_process_sql_update ('tnetflow_filter', $filter_copy, array ('id_sg' => $filter_id)); - ui_print_result_message ($result, __('Filter updated successfully'), __('Error updating filter')); + $result = db_process_sql_update ('tnetflow_filter', $filter_copy, + array('id_sg' => $filter_id)); + ui_print_result_message ($result, __('Filter updated successfully'), + __('Error updating filter')); } @@ -166,7 +170,7 @@ echo '
"; echo "" . - ''.__('Date').'' . + '' . __('Date') . '' . ""; echo "" . html_print_input_text ('date', $date, false, 10, 10, true) . @@ -185,10 +189,10 @@ echo '"; echo ""; - echo "" . ''.__('Type').'' . ""; + echo "" . '' . __('Type') . '' . ""; echo "" . html_print_select (netflow_get_chart_types (), 'chart_type', $chart_type,'','',0,true) . ""; - echo "" . ''.__('Max. values').'' . ""; + echo "" . '' . __('Max. values') . '' . ""; $max_values = array ('2' => '2', '5' => '5', '10' => '10', @@ -367,7 +371,9 @@ if ($draw != '') { // Draw echo "
"; - echo netflow_draw_item ($start_date, $end_date, $interval_length, $chart_type, $filter, $max_aggregates, $connection_name); + echo netflow_draw_item ($start_date, $end_date, + $interval_length, $chart_type, $filter, + $max_aggregates, $connection_name); } ?>