From 1a030bcd424cda5dd9386edbc1556000957cebae Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 21 Mar 2022 12:21:47 +0100 Subject: [PATCH] fixed several netflow bugs --- .../godmode/netflow/nf_edit_form.php | 1 + pandora_console/include/functions_netflow.php | 132 ++++++++++-------- .../include/functions_reporting.php | 80 ++++------- 3 files changed, 103 insertions(+), 110 deletions(-) diff --git a/pandora_console/godmode/netflow/nf_edit_form.php b/pandora_console/godmode/netflow/nf_edit_form.php index 19a89ab589..8ce55b3641 100644 --- a/pandora_console/godmode/netflow/nf_edit_form.php +++ b/pandora_console/godmode/netflow/nf_edit_form.php @@ -174,6 +174,7 @@ if ($create) { } } +$table = new stdClass(); $table->id = 'table1'; $table->width = '100%'; $table->border = 0; diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index f88f6b751d..a43a1ed6be 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -242,7 +242,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate) * * @return string HTML data table. */ -function netflow_data_table($data, $start_date, $end_date, $aggregate) +function netflow_data_table($data, $start_date, $end_date, $aggregate, $pdf=false) { global $nfdump_date_format; @@ -265,8 +265,12 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate) $values = []; $table = new stdClass(); - $table->size = ['100%']; - $table->class = 'databox'; + + if ($pdf === false) { + $table->size = ['100%']; + } + + $table->class = 'databox w100p'; $table->cellspacing = 0; $table->data = []; @@ -1279,7 +1283,7 @@ function netflow_draw_item( if ($output === 'HTML' || $output === 'PDF') { $html = "
"; - $html .= netflow_data_table($data, $start_date, $end_date, $aggregate); + $html .= netflow_data_table($data, $start_date, $end_date, $aggregate, $output === 'PDF'); $html .= '
'; return $html; @@ -1485,6 +1489,8 @@ function netflow_draw_item( * * @param string $start_date Period start date. * @param string $end_date Period end date. + * @param mixed $interval_length Resolution points or hourly or daily. + * @param string $type_netflow Period end date. * @param array $filter Netflow filter. * @param integer $max_aggregates Maximum number of aggregates. * @param string $connection_name Node name when data is get in meta. @@ -1494,77 +1500,81 @@ function netflow_draw_item( function netflow_get_item_data( string $start_date, string $end_date, + $interval_length, + string $type_netflow, array $filter, int $max_aggregates, string $connection_name ) { - $data_summary = netflow_get_summary( - $start_date, - $end_date, - $filter, - $connection_name - ); + $data = []; - $data_top_n = netflow_get_top_N( - $start_date, - $end_date, - $filter, - $max_aggregates, - $connection_name - ); + switch ($type_netflow) { + case 'netflow_top_N': + /* + $data_summary = netflow_get_summary( + $start_date, + $end_date, + $filter, + $connection_name + ); - return [ - 'summary' => $data_summary, - 'top_n' => $data_top_n, - ]; -} + $data_top_n = netflow_get_top_N( + $start_date, + $end_date, + $filter, + $max_aggregates, + $connection_name + ); + $data = [ + 'summary' => $data_summary, + 'top_n' => $data_top_n, + ];*/ + break; -/** - * Render an aggregated area chart as an XML. - * - * @param array $data Netflow data. - * - * @return void XML is echoed. - */ -function netflow_aggregate_area_xml($data) -{ - // Print source information. - if (isset($data['sources'])) { - echo "\n"; - foreach ($data['sources'] as $source => $discard) { - echo ''.$source."\n"; - } + case 'netflow_summary': + $aggregate = $filter['aggregate']; - echo "\n"; + $data_summary = netflow_get_summary( + $start_date, + $end_date, + $filter, + $connection_name + ); - // Print flow information. - echo "\n"; - foreach ($data['data'] as $timestamp => $flow) { - echo "\n"; - echo ' '.$timestamp."\n"; - echo " \n"; - foreach ($flow as $source => $data) { - echo ' '.$source."\n"; - echo ' '.$data."\n"; - } + $data_stats = netflow_get_stats( + $start_date, + $end_date, + $filter, + $aggregate, + $max_aggregates, + true, + $connection_name + ); - echo " \n"; - echo "\n"; - } + $data = [ + 'summary' => $data_summary, + 'stats' => $data_stats, + ]; + break; - echo "\n"; - } else { - echo "\n"; - foreach ($data as $timestamp => $flow) { - echo "\n"; - echo ' '.$timestamp."\n"; - echo ' '.$flow['data']."\n"; - echo "\n"; - } + default: + $aggregate = $filter['aggregate']; - echo "\n"; + $data = netflow_get_data( + $start_date, + $end_date, + $interval_length, + $filter, + $aggregate, + $max_aggregates, + true, + $connection_name + ); + break; } + + return $data; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ba3dc52551..a9f2f71b3e 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -5648,60 +5648,42 @@ function reporting_netflow( ); if ($type_netflow === 'netflow_top_N') { - // Always aggregate by destination port. + // Aggregate by destination port. $filter['aggregate'] = 'dstport'; + } - switch ($type) { - case 'dinamic': - case 'static': - $return['chart'] = netflow_draw_item( - ($report['datetime'] - $content['period']), - $report['datetime'], - $content['top_n'], - $type_netflow, - $filter, - $content['top_n_value'], - $content['server_name'], - (($pdf === true) ? 'PDF' : 'HTML') - ); - break; + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = netflow_draw_item( + ($report['datetime'] - $content['period']), + $report['datetime'], + $content['top_n'], + $type_netflow, + $filter, + $content['top_n_value'], + $content['server_name'], + (($pdf === true) ? 'PDF' : 'HTML') + ); + break; - case 'data': - $return['data'] = netflow_get_item_data( - ($report['datetime'] - $content['period']), - $report['datetime'], - $filter, - $content['top_n_value'], - $content['server_name'] - ); - break; + case 'data': + $data = netflow_get_item_data( + ($report['datetime'] - $content['period']), + $report['datetime'], + $content['top_n'], + $type_netflow, + $filter, + $content['top_n_value'], + $content['server_name'] + ); - default: - // Nothing to do. - break; - } - } else { - switch ($type) { - case 'dinamic': - case 'static': - case 'data': - $return['chart'] = netflow_draw_item( - ($report['datetime'] - $content['period']), - $report['datetime'], - $content['top_n'], - $type_netflow, - $filter, - $content['top_n_value'], - $content['server_name'], - $pdf ? 'PDF' : 'HTML' - ); - break; + $return['data'] = (array_key_exists('data', $data) === true) ? $data['data'] : $data; + break; - case 'data': - default: - // Nothing to do. - break; - } + default: + // Nothing to do. + break; } $return['subtitle'] = netflow_generate_subtitle_report(