[Netflow] Merge three reports in one

Former-commit-id: 1a7fb1aaacda5009ba2ab911dc69594133517f91
This commit is contained in:
fermin831 2019-03-19 17:33:39 +01:00
parent bf633e891c
commit bc9192b98a
9 changed files with 67 additions and 252 deletions

View File

@ -11,6 +11,8 @@ CREATE TABLE IF NOT EXISTS `tnetwork_matrix` (
UNIQUE (`source`, `destination`, `utimestamp`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 ;
UPDATE `treport_content` SET type="netflow_summary" WHERE type="netflow_pie" OR type="netflow_statistics";
-- ----------------------------------------------------------------------
-- Add column in table `tagent_custom_fields`
-- ----------------------------------------------------------------------

View File

@ -1376,6 +1376,7 @@ ALTER TABLE treport_content ADD COLUMN `lapse` int(11) default '300';
ALTER TABLE treport_content ADD COLUMN `visual_format` tinyint(1) default '0';
ALTER TABLE treport_content ADD COLUMN `hide_no_data` tinyint(1) default '0';
ALTER TABLE treport_content ADD COLUMN `recursion` tinyint(1) default NULL;
UPDATE `treport_content` SET type="netflow_summary" WHERE type="netflow_pie" OR type="netflow_statistics";
-- ---------------------------------------------------------------------
-- Table `tmodule_relationship`

View File

@ -597,18 +597,16 @@ switch ($action) {
break;
case 'netflow_area':
case 'netflow_pie':
case 'netflow_data':
case 'netflow_statistics':
case 'netflow_summary':
$netflow_filter = $item['text'];
// Filter
// Filter.
$period = $item['period'];
$description = $item['description'];
$resolution = $item['top_n'];
// Interval resolution
// Interval resolution.
$max_values = $item['top_n_value'];
// Max values
// Max values.
break;
case 'nt_top_n':
@ -3667,16 +3665,6 @@ function chooseType() {
$("#row_historical_db_check").hide();
break;
case 'netflow_pie':
$("#row_netflow_filter").show();
$("#row_description").show();
$("#row_period").show();
$("#row_max_values").show();
$("#row_resolution").show();
$("#row_servers").show();
$("#row_historical_db_check").hide();
break;
case 'netflow_data':
$("#row_netflow_filter").show();
$("#row_description").show();
@ -3688,15 +3676,6 @@ function chooseType() {
break;
case 'netflow_summary':
$("#row_netflow_filter").show();
$("#row_description").show();
$("#row_period").show();
$("#row_resolution").show();
$("#row_servers").show();
$("#row_historical_db_check").hide();
break;
case 'netflow_statistics':
$("#row_netflow_filter").show();
$("#row_description").show();
$("#row_period").show();

View File

@ -1209,9 +1209,7 @@ switch ($action) {
break;
case 'netflow_area':
case 'netflow_pie':
case 'netflow_data':
case 'netflow_statistics':
case 'netflow_summary':
$values['text'] = get_parameter('netflow_filter');
$values['description'] = get_parameter('description');
@ -1583,9 +1581,7 @@ switch ($action) {
break;
case 'netflow_area':
case 'netflow_pie':
case 'netflow_data':
case 'netflow_statistics':
case 'netflow_summary':
$values['text'] = get_parameter('netflow_filter');
$values['description'] = get_parameter('description');

View File

@ -196,6 +196,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate)
$start_date = date($nfdump_date_format, $start_date);
$end_date = date($nfdump_date_format, $end_date);
$values = [];
$table = new stdClass();
$table->width = '100%';
$table->cellspacing = 0;
$table->class = 'databox';
@ -331,9 +332,10 @@ function netflow_summary_table($data)
global $nfdump_date_format;
$values = [];
$table->size = ['50%'];
$table = new stdClass();
$table->cellspacing = 0;
$table->class = 'databox';
$table->styleTable = 'width: 100%';
$table->data = [];
$table->style[0] = 'font-weight: bold; padding: 6px';
@ -1020,11 +1022,11 @@ function netflow_get_filter_arguments($filter)
function netflow_get_chart_types()
{
return [
'netflow_area' => __('Area graph'),
'netflow_pie_summatory' => __('Summary'),
'netflow_data' => __('Data table'),
'netflow_mesh' => __('Circular mesh'),
'netflow_host_treemap' => __('Host detailed traffic'),
'netflow_area' => __('Area graph'),
'netflow_summary' => __('Summary'),
'netflow_data' => __('Data table'),
'netflow_mesh' => __('Circular mesh'),
'netflow_host_treemap' => __('Host detailed traffic'),
];
}
@ -1068,7 +1070,6 @@ function netflow_draw_item(
// Process item.
switch ($type) {
case '0':
case 'netflow_area':
$data = netflow_get_data(
$start_date,
@ -1104,7 +1105,6 @@ function netflow_draw_item(
}
break;
case '2':
case 'netflow_data':
$data = netflow_get_data(
$start_date,
@ -1136,31 +1136,6 @@ function netflow_draw_item(
}
break;
case '3':
case 'netflow_statistics':
$data = netflow_get_stats(
$start_date,
$end_date,
$filter,
$aggregate,
$max_aggregates,
true,
$connection_name,
$address_resolution
);
if (empty($data)) {
break;
}
if ($output == 'HTML' || $output == 'PDF') {
$html = netflow_stat_table($data, $start_date, $end_date, $aggregate);
return $html;
} else if ($output == 'XML') {
return netflow_stat_xml($data);
}
break;
case '4':
case 'netflow_summary':
$data_summary = netflow_get_summary(
$start_date,
@ -1172,15 +1147,6 @@ function netflow_draw_item(
break;
}
if ($output == 'HTML' || $output == 'PDF') {
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,
@ -1195,62 +1161,31 @@ function netflow_draw_item(
break;
}
if ($output == 'HTML') {
if ($output === 'HTML' || $output === 'PDF') {
$html = '<table style="width: 100%">';
$html .= '<tr>';
$html .= '<td style="width: 50%">';
$html .= netflow_summary_table($data_summary);
$html .= '</td>';
$html .= '<td style="width: 50%">';
$html .= graph_netflow_aggregate_pie(
$data_pie,
netflow_format_aggregate($aggregate),
($output === 'HTML') ? 1 : 2,
($output === 'HTML')
);
$html .= '</td>';
$html .= '</tr>';
$html .= '</table>';
$html .= netflow_stat_table(
$data_pie,
$start_date,
$end_date,
$aggregate
);
return $html;
} else if ($output == 'PDF') {
return $html;
} else if ($output == 'XML') {
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,
true,
$connection_name,
$address_resolution
);
if (empty($data_pie)) {
break;
}
switch ($output) {
case 'HTML':
$html = '<table>';
$html .= '<tr>';
$html .= '<td>';
$html .= netflow_summary_table($data_summary);
$html .= '</td>';
$html .= '<td>';
$html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate));
$html .= '</td>';
$html .= '</tr>';
$html .= '</table>';
$html .= '</br>';
$html .= netflow_stat_table($data_pie, $start_date, $end_date, $aggregate);
return $html;
case 'XML':
return netflow_summary_xml($data_summary);
default:
// Nothing to do.
break;
} else if ($output === 'XML') {
return netflow_summary_xml($data_summary, $data_pie);
}
break;
@ -1409,7 +1344,7 @@ function netflow_aggregate_area_xml($data)
echo ' <timestamp>'.$timestamp."</timestamp>\n";
echo " <aggregates>\n";
foreach ($flow as $source => $data) {
echo " <aggregate>$source</aggregate>\n";
echo ' <aggregate>'.$source."</aggregate>\n";
echo ' <data>'.$data."</data>\n";
}
@ -1432,75 +1367,37 @@ function netflow_aggregate_area_xml($data)
}
/**
* Render a pie chart as an XML.
*
* @param array $data Netflow data.
*
* @return void XML is echoed.
*/
function netflow_aggregate_pie_xml($data)
{
// Calculate total.
$total = 0;
foreach ($data as $flow) {
$total += $flow['data'];
}
if ($total == 0) {
return;
}
// Print percentages.
echo "<pie>\n";
foreach ($data as $flow) {
echo '<aggregate>'.$flow['agg']."</aggregate>\n";
echo '<data>'.format_numeric((100 * $flow['data'] / $total), 2)."%</data>\n";
}
echo "</pie>\n";
}
/**
* Render a stats table as an XML.
*
* @param array $data Netflow data.
*
* @return string Wiht XML data.
*/
function netflow_stat_xml($data)
{
// Print stats.
$xml .= "<stats>\n";
foreach ($data as $flow) {
$xml .= '<aggregate>'.$flow['agg']."</aggregate>\n";
$xml .= '<data>'.$flow['data']."</data>\n";
}
$xml .= "</stats>\n";
return $xml;
}
/**
* Render a summary table as an XML.
*
* @param array $data Netflow data.
* @param array $data Netflow data.
* @param array $rows_data Table info (top N hosts).
*
* @return string Wiht XML data.
*/
function netflow_summary_xml($data)
function netflow_summary_xml($data, $rows_data)
{
// Print summary
// Print summary.
$xml = "<summary>\n";
$xml .= ' <total_flows>'.$data['totalflows']."</total_flows>\n";
$xml .= ' <total_bytes>'.$data['totalbytes']."</total_bytes>\n";
$xml .= ' <total_packets>'.$data['totalbytes']."</total_packets>\n";
$xml .= ' <average_bps>'.$data['avgbps']."</average_bps>\n";
$xml .= ' <average_pps>'.$data['avgpps']."</average_pps>\n";
$xml .= ' <average_bpp>'.$data['avgpps']."</average_bpp>\n";
$xml = " <totals>\n";
$xml .= ' <total_flows>'.$data['totalflows']."</total_flows>\n";
$xml .= ' <total_bytes>'.$data['totalbytes']."</total_bytes>\n";
$xml .= ' <total_packets>'.$data['totalbytes']."</total_packets>\n";
$xml .= ' <average_bps>'.$data['avgbps']."</average_bps>\n";
$xml .= ' <average_pps>'.$data['avgpps']."</average_pps>\n";
$xml .= ' <average_bpp>'.$data['avgpps']."</average_bpp>\n";
$xml .= " </totals>\n";
// Add the data table.
$xml .= " <hostsdata>\n";
foreach ($rows_data as $d) {
$xml .= "<data>\n";
$xml .= '<host>'.$d['agg']."</host>\n";
$xml .= '<bytes>'.$d['data']."</bytes>\n";
$xml .= "</data>\n";
}
$xml .= " </hostsdata>\n";
$xml .= "</summary>\n";
return $xml;

View File

@ -517,16 +517,6 @@ function reporting_make_reporting_data(
);
break;
case 'netflow_pie':
$report['contents'][] = reporting_netflow(
$report,
$content,
$type,
$force_width_chart,
$force_height_chart,
'netflow_pie',
$pdf
);
break;
case 'netflow_data':
@ -541,18 +531,6 @@ function reporting_make_reporting_data(
);
break;
case 'netflow_statistics':
$report['contents'][] = reporting_netflow(
$report,
$content,
$type,
$force_width_chart,
$force_height_chart,
'netflow_statistics',
$pdf
);
break;
case 'netflow_summary':
$report['contents'][] = reporting_netflow(
$report,
@ -3972,8 +3950,8 @@ function reporting_monitor_report($report, $content)
* @param string $type Report type (static, dynamic, data).
* @param integer $force_width_chart Fixed width chart.
* @param integer $force_height_chart Fixed height chart.
* @param string $type_netflow One of netflow_area, netflow_pie,
* netflow_data, netflow_statistics, netflow_summary.
* @param string $type_netflow One of netflow_area, netflow_data,
* netflow_summary.
* @param boolean $pdf True if a pdf report is generating.
*
* @return array Report item structure.
@ -3994,18 +3972,10 @@ function reporting_netflow(
$return['type'] = 'netflow_area';
break;
case 'netflow_pie':
$return['type'] = 'netflow_pie';
break;
case 'netflow_data':
$return['type'] = 'netflow_data';
break;
case 'netflow_statistics':
$return['type'] = 'netflow_statistics';
break;
case 'netflow_summary':
$return['type'] = 'netflow_summary';
break;
@ -4021,22 +3991,14 @@ function reporting_netflow(
$content['name'] = __('Netflow Area');
break;
case 'netflow_pie':
$content['name'] = __('Netflow Pie');
case 'netflow_summary':
$content['name'] = __('Netflow Summary');
break;
case 'netflow_data':
$content['name'] = __('Netflow Data');
break;
case 'netflow_statistics':
$content['name'] = __('Netflow Statistics');
break;
case 'netflow_summary':
$content['name'] = __('Netflow Summary');
break;
default:
$content['name'] = __('Unknown report');
break;

View File

@ -271,21 +271,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
break;
case 'netflow_area':
reporting_html_graph($table, $item);
break;
case 'netflow_pie':
reporting_html_graph($table, $item);
break;
case 'netflow_data':
reporting_html_graph($table, $item);
break;
case 'netflow_statistics':
reporting_html_graph($table, $item);
break;
case 'netflow_summary':
reporting_html_graph($table, $item);
break;

View File

@ -867,18 +867,10 @@ function reports_get_report_types($template=false, $not_editor=false)
'optgroup' => __('Netflow'),
'name' => __('Netflow area chart'),
];
$types['netflow_pie'] = [
'optgroup' => __('Netflow'),
'name' => __('Netflow pie chart'),
];
$types['netflow_data'] = [
'optgroup' => __('Netflow'),
'name' => __('Netflow data table'),
];
$types['netflow_statistics'] = [
'optgroup' => __('Netflow'),
'name' => __('Netflow statistics table'),
];
$types['netflow_summary'] = [
'optgroup' => __('Netflow'),
'name' => __('Netflow summary table'),

View File

@ -340,7 +340,7 @@ sub pandora_purgedb ($$) {
} else {
my @blacklist_types = ("'SLA_services'", "'custom_graph'", "'sql_graph_vbar'", "'sql_graph_hbar'",
"'sql_graph_pie'", "'database_serialized'", "'sql'", "'inventory'", "'inventory_changes'",
"'netflow_area'", "'netflow_pie'", "'netflow_data'", "'netflow_statistics'", "'netflow_summary'");
"'netflow_area'", "'netflow_data'", "'netflow_summary'");
my $blacklist_types_str = join(',', @blacklist_types);
# Deleted modules