From e16d48804e7ac6c0c76ec94bfceded219767d53a Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 14 Mar 2019 09:25:50 +0100 Subject: [PATCH] [Netflow live] Added removed unit from pie graph and summary table and refactorized bytes format Former-commit-id: 35b9fd71ad97869e23119bd0d2031ec12400d745 --- pandora_console/include/functions_netflow.php | 32 ++++++------------- pandora_console/include/functions_network.php | 26 +++++++++++++++ .../operation/network/network_report.php | 9 +----- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index f197b43063..af4ca422b2 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -14,6 +14,7 @@ require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_io.php'; require_once $config['homedir'].'/include/functions_io.php'; +require_once $config['homedir'].'/include/functions_network.php'; enterprise_include_once($config['homedir'].'/enterprise/include/pdf_translator.php'); enterprise_include_once($config['homedir'].'/enterprise/include/functions_metaconsole.php'); @@ -268,14 +269,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate) } $table->data[$x][0] = $agg; - $table->data[$x][1] = format_for_graph( - $data[$j]['data'], - 2, - '.', - ',', - 1024, - 'B' - ); + $table->data[$x][1] = network_format_bytes($data[$j]['data']); $j++; $x++; @@ -362,13 +356,8 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) foreach ($data['data'] as $timestamp => $values) { $table->data[$i][0] = date($time_format, $timestamp); for ($j = 0; $j < $source_count; $j++) { - $table->data[$i][($j + 1)] = format_for_graph( - (isset($values[$source_index[$j]])) ? $values[$source_index[$j]] : 0, - 2, - '.', - ',', - 1024, - 'B' + $table->data[$i][($j + 1)] = network_format_bytes( + $values[$source_index[$j]] ); } @@ -402,32 +391,32 @@ function netflow_summary_table($data) $row = []; $row[] = __('Total flows'); - $row[] = format_numeric($data['totalflows']); + $row[] = format_for_graph($data['totalflows'], 2); $table->data[] = $row; $row = []; $row[] = __('Total bytes'); - $row[] = format_numeric($data['totalbytes']); + $row[] = network_format_bytes($data['totalbytes']); $table->data[] = $row; $row = []; $row[] = __('Total packets'); - $row[] = format_numeric($data['totalpackets']); + $row[] = format_for_graph($data['totalpackets'], 2); $table->data[] = $row; $row = []; $row[] = __('Average bits per second'); - $row[] = format_numeric($data['avgbps']); + $row[] = network_format_bytes($data['avgbps']); $table->data[] = $row; $row = []; $row[] = __('Average packets per second'); - $row[] = format_numeric($data['avgpps']); + $row[] = format_for_graph($data['avgpps'], 2); $table->data[] = $row; $row = []; $row[] = __('Average bytes per packet'); - $row[] = format_numeric($data['avgbpp']); + $row[] = format_for_graph($data['avgbpp'], 2); $table->data[] = $row; $html = html_print_table($table, true); @@ -1319,7 +1308,6 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil $html .= ''; $html .= ''; $html .= netflow_summary_table($data_summary); - $html .= ''.__('Unit').': '.netflow_format_unit($unit); $html .= ' '.__('Aggregate').': '.netflow_format_aggregate($aggregate); $html .= ''; $html .= ''; diff --git a/pandora_console/include/functions_network.php b/pandora_console/include/functions_network.php index 186f751426..802fc4bb5c 100644 --- a/pandora_console/include/functions_network.php +++ b/pandora_console/include/functions_network.php @@ -128,3 +128,29 @@ function network_print_explorer_header( return $cell; } + + +/** + * Alias for format_for_graph to print bytes. + * + * @param integer $value Value to parse like bytes. + * + * @return string Number parsed. + */ +function network_format_bytes($value) +{ + if (!isset($value)) { + $value = 0; + } + + $value = (int) $value; + + return format_for_graph( + $value, + 2, + '.', + ',', + 1024, + 'B' + ); +} diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index ba6ddf2dc4..7ca13a8e79 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -299,14 +299,7 @@ foreach ($data as $item) { $row['pkts'] .= ' ('.$item['pct_pkts'].'%)'; } - $row['bytes'] = format_for_graph( - $item['sum_bytes'], - 2, - '.', - ',', - 1024, - 'B' - ); + $row['bytes'] = network_format_bytes($item['sum_bytes']); if (!$is_network) { $row['bytes'] .= ' ('.$item['pct_bytes'].'%)'; }