fixed several netflow bugs

This commit is contained in:
alejandro.campos@artica.es 2022-03-21 12:21:47 +01:00
parent c736fbe726
commit 1a030bcd42
3 changed files with 103 additions and 110 deletions

View File

@ -174,6 +174,7 @@ if ($create) {
} }
} }
$table = new stdClass();
$table->id = 'table1'; $table->id = 'table1';
$table->width = '100%'; $table->width = '100%';
$table->border = 0; $table->border = 0;

View File

@ -242,7 +242,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate)
* *
* @return string HTML data table. * @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; global $nfdump_date_format;
@ -265,8 +265,12 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate)
$values = []; $values = [];
$table = new stdClass(); $table = new stdClass();
$table->size = ['100%'];
$table->class = 'databox'; if ($pdf === false) {
$table->size = ['100%'];
}
$table->class = 'databox w100p';
$table->cellspacing = 0; $table->cellspacing = 0;
$table->data = []; $table->data = [];
@ -1279,7 +1283,7 @@ function netflow_draw_item(
if ($output === 'HTML' || $output === 'PDF') { if ($output === 'HTML' || $output === 'PDF') {
$html = "<div class='w100p overflow'>"; $html = "<div class='w100p overflow'>";
$html .= netflow_data_table($data, $start_date, $end_date, $aggregate); $html .= netflow_data_table($data, $start_date, $end_date, $aggregate, $output === 'PDF');
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -1485,6 +1489,8 @@ function netflow_draw_item(
* *
* @param string $start_date Period start date. * @param string $start_date Period start date.
* @param string $end_date Period end 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 array $filter Netflow filter.
* @param integer $max_aggregates Maximum number of aggregates. * @param integer $max_aggregates Maximum number of aggregates.
* @param string $connection_name Node name when data is get in meta. * @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( function netflow_get_item_data(
string $start_date, string $start_date,
string $end_date, string $end_date,
$interval_length,
string $type_netflow,
array $filter, array $filter,
int $max_aggregates, int $max_aggregates,
string $connection_name string $connection_name
) { ) {
$data_summary = netflow_get_summary( $data = [];
$start_date,
$end_date,
$filter,
$connection_name
);
$data_top_n = netflow_get_top_N( switch ($type_netflow) {
$start_date, case 'netflow_top_N':
$end_date, /*
$filter, $data_summary = netflow_get_summary(
$max_aggregates, $start_date,
$connection_name $end_date,
); $filter,
$connection_name
);
return [ $data_top_n = netflow_get_top_N(
'summary' => $data_summary, $start_date,
'top_n' => $data_top_n, $end_date,
]; $filter,
} $max_aggregates,
$connection_name
);
$data = [
'summary' => $data_summary,
'top_n' => $data_top_n,
];*/
break;
/** case 'netflow_summary':
* Render an aggregated area chart as an XML. $aggregate = $filter['aggregate'];
*
* @param array $data Netflow data.
*
* @return void XML is echoed.
*/
function netflow_aggregate_area_xml($data)
{
// Print source information.
if (isset($data['sources'])) {
echo "<aggregates>\n";
foreach ($data['sources'] as $source => $discard) {
echo '<aggregate>'.$source."</aggregate>\n";
}
echo "</aggregates>\n"; $data_summary = netflow_get_summary(
$start_date,
$end_date,
$filter,
$connection_name
);
// Print flow information. $data_stats = netflow_get_stats(
echo "<flows>\n"; $start_date,
foreach ($data['data'] as $timestamp => $flow) { $end_date,
echo "<flow>\n"; $filter,
echo ' <timestamp>'.$timestamp."</timestamp>\n"; $aggregate,
echo " <aggregates>\n"; $max_aggregates,
foreach ($flow as $source => $data) { true,
echo ' <aggregate>'.$source."</aggregate>\n"; $connection_name
echo ' <data>'.$data."</data>\n"; );
}
echo " </aggregates>\n"; $data = [
echo "</flow>\n"; 'summary' => $data_summary,
} 'stats' => $data_stats,
];
break;
echo "</flows>\n"; default:
} else { $aggregate = $filter['aggregate'];
echo "<flows>\n";
foreach ($data as $timestamp => $flow) {
echo "<flow>\n";
echo ' <timestamp>'.$timestamp."</timestamp>\n";
echo ' <data>'.$flow['data']."</data>\n";
echo "</flow>\n";
}
echo "</flows>\n"; $data = netflow_get_data(
$start_date,
$end_date,
$interval_length,
$filter,
$aggregate,
$max_aggregates,
true,
$connection_name
);
break;
} }
return $data;
} }

View File

@ -5648,60 +5648,42 @@ function reporting_netflow(
); );
if ($type_netflow === 'netflow_top_N') { if ($type_netflow === 'netflow_top_N') {
// Always aggregate by destination port. // Aggregate by destination port.
$filter['aggregate'] = 'dstport'; $filter['aggregate'] = 'dstport';
}
switch ($type) { switch ($type) {
case 'dinamic': case 'dinamic':
case 'static': case 'static':
$return['chart'] = netflow_draw_item( $return['chart'] = netflow_draw_item(
($report['datetime'] - $content['period']), ($report['datetime'] - $content['period']),
$report['datetime'], $report['datetime'],
$content['top_n'], $content['top_n'],
$type_netflow, $type_netflow,
$filter, $filter,
$content['top_n_value'], $content['top_n_value'],
$content['server_name'], $content['server_name'],
(($pdf === true) ? 'PDF' : 'HTML') (($pdf === true) ? 'PDF' : 'HTML')
); );
break; break;
case 'data': case 'data':
$return['data'] = netflow_get_item_data( $data = netflow_get_item_data(
($report['datetime'] - $content['period']), ($report['datetime'] - $content['period']),
$report['datetime'], $report['datetime'],
$filter, $content['top_n'],
$content['top_n_value'], $type_netflow,
$content['server_name'] $filter,
); $content['top_n_value'],
break; $content['server_name']
);
default: $return['data'] = (array_key_exists('data', $data) === true) ? $data['data'] : $data;
// Nothing to do. break;
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;
case 'data': default:
default: // Nothing to do.
// Nothing to do. break;
break;
}
} }
$return['subtitle'] = netflow_generate_subtitle_report( $return['subtitle'] = netflow_generate_subtitle_report(