[Netflow live] Removed units

Former-commit-id: 37d9182a46a85b44a400a50eae48cd7778a3dc84
This commit is contained in:
fermin831 2019-03-14 10:36:15 +01:00
parent cf8915af36
commit da08acce4f
3 changed files with 14 additions and 70 deletions

View File

@ -4109,7 +4109,7 @@ function fullscale_data(
/** /**
* Print an area graph with netflow aggregated * Print an area graph with netflow aggregated
*/ */
function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='', $ttl=1, $only_image=false, $date=null) function graph_netflow_aggregate_area($data, $period, $width, $height, $ttl=1, $only_image=false, $date=null)
{ {
global $config; global $config;
global $graphic_type; global $graphic_type;
@ -4155,7 +4155,7 @@ function graph_netflow_aggregate_area($data, $period, $width, $height, $unit='',
'period' => $period, 'period' => $period,
'width' => '90%', 'width' => '90%',
'height' => 450, 'height' => 450,
'unit' => $unit, 'unit' => 'bytes',
'only_image' => $only_image, 'only_image' => $only_image,
'homeurl' => $homeurl, 'homeurl' => $homeurl,
'menu' => true, 'menu' => true,
@ -4306,7 +4306,7 @@ function graph_netflow_circular_mesh($data, $radius=700)
/** /**
* Print a rectangular graph with the traffic of the ports for each IP * Print a rectangular graph with the traffic of the ports for each IP
*/ */
function graph_netflow_host_traffic($data, $unit, $width=700, $height=700) function graph_netflow_host_traffic($data, $width=700, $height=700)
{ {
global $config; global $config;

View File

@ -289,7 +289,7 @@ function netflow_stat_table($data, $start_date, $end_date, $aggregate)
* *
* @return The statistics table. * @return The statistics table.
*/ */
function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit) function netflow_data_table($data, $start_date, $end_date, $aggregate)
{ {
global $nfdump_date_format; global $nfdump_date_format;
@ -346,7 +346,7 @@ function netflow_data_table($data, $start_date, $end_date, $aggregate, $unit)
foreach ($data as $timestamp => $value) { foreach ($data as $timestamp => $value) {
$table->data[$i][0] = date($time_format, $timestamp); $table->data[$i][0] = date($time_format, $timestamp);
$table->data[$i][1] = format_numeric($value['data']).' '.netflow_format_unit($unit); $table->data[$i][1] = network_format_bytes($value['data']);
$i++; $i++;
} }
} }
@ -463,7 +463,7 @@ function netflow_get_data($start_date, $end_date, $interval_length, $filter, $ag
// Requesting remote data // Requesting remote data
if (defined('METACONSOLE') && $connection_name != '') { if (defined('METACONSOLE') && $connection_name != '') {
$data = metaconsole_call_remote_api($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|".base64_encode(json_encode($filter))."|$aggregate|$max|$unit".(int) $address_resolution); $data = metaconsole_call_remote_api($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|".base64_encode(json_encode($filter))."|$aggregate|$max|1".(int) $address_resolution);
return json_decode($data, true); return json_decode($data, true);
} }
@ -611,7 +611,7 @@ function netflow_get_data($start_date, $end_date, $interval_length, $filter, $ag
$filter, $filter,
$aggregate, $aggregate,
$max, $max,
$unit, $absolute,
$connection_name $connection_name
); );
@ -1107,7 +1107,6 @@ function netflow_get_valid_intervals()
function netflow_draw_item($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $connection_name='', $output='HTML', $address_resolution=false) function netflow_draw_item($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $connection_name='', $output='HTML', $address_resolution=false)
{ {
$aggregate = $filter['aggregate']; $aggregate = $filter['aggregate'];
$unit = $filter['output'];
$interval = ($end_date - $start_date); $interval = ($end_date - $start_date);
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
$width = 950; $width = 950;
@ -1121,22 +1120,20 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
switch ($type) { switch ($type) {
case '0': case '0':
case 'netflow_area': case 'netflow_area':
$data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, true, $connection_name, $address_resolution); $data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, false, $connection_name, $address_resolution);
if (empty($data)) { if (empty($data)) {
break; break;
} }
if ($output == 'HTML' || $output == 'PDF') { if ($output == 'HTML' || $output == 'PDF') {
$html = '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate); $html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate);
if ($interval_length != 0) { if ($interval_length != 0) {
$html .= '&nbsp;<b>'._('Resolution').':</b> '.netflow_get_resolution_name($interval_length); $html .= '&nbsp;<b>'._('Resolution').':</b> '.netflow_get_resolution_name($interval_length);
} }
$html .= graph_netflow_aggregate_area($data, $interval, $width, $height, netflow_format_unit($unit), 1, false, $end_date); $html .= graph_netflow_aggregate_area($data, $interval, $width, $height, 1, false, $end_date);
return $html; return $html;
} else if ($output == 'XML') { } else if ($output == 'XML') {
$xml = "<unit>$unit</unit>\n";
$xml .= "<aggregate>$aggregate</aggregate>\n"; $xml .= "<aggregate>$aggregate</aggregate>\n";
$xml .= "<resolution>$interval_length</resolution>\n"; $xml .= "<resolution>$interval_length</resolution>\n";
$xml .= netflow_aggregate_area_xml($data); $xml .= netflow_aggregate_area_xml($data);
@ -1146,26 +1143,24 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
case '2': case '2':
case 'netflow_data': case 'netflow_data':
$data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, false, $connection_name, $address_resolution); $data = netflow_get_data($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, true, $connection_name, $address_resolution);
if (empty($data)) { if (empty($data)) {
break; break;
} }
if ($output == 'HTML' || $output == 'PDF') { if ($output == 'HTML' || $output == 'PDF') {
$html = '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate); $html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate);
if ($interval_length != 0) { if ($interval_length != 0) {
$html .= '&nbsp;<b>'._('Resolution').':</b> '.netflow_get_resolution_name($interval_length); $html .= '&nbsp;<b>'._('Resolution').':</b> '.netflow_get_resolution_name($interval_length);
} }
$html .= "<div style='width: 100%; overflow: auto;'>"; $html .= "<div style='width: 100%; overflow: auto;'>";
$html .= netflow_data_table($data, $start_date, $end_date, $aggregate, $unit); $html .= netflow_data_table($data, $start_date, $end_date, $aggregate);
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} else if ($output == 'XML') { } else if ($output == 'XML') {
$xml = "<unit>$unit</unit>\n";
$xml .= "<aggregate>$aggregate</aggregate>\n"; $xml .= "<aggregate>$aggregate</aggregate>\n";
$xml .= "<resolution>$interval_length</resolution>\n"; $xml .= "<resolution>$interval_length</resolution>\n";
// Same as netflow_aggregate_area_xml // Same as netflow_aggregate_area_xml
@ -1225,7 +1220,7 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
$filter, $filter,
$aggregate, $aggregate,
$max_aggregates, $max_aggregates,
$unit, true,
$connection_name, $connection_name,
$address_resolution $address_resolution
); );
@ -1234,17 +1229,14 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
} }
if ($output == 'HTML') { if ($output == 'HTML') {
$html = '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate); $html .= '&nbsp;<b>'.__('Aggregate').':</b> '.netflow_format_aggregate($aggregate);
$html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate)); $html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate));
return $html; return $html;
} else if ($output == 'PDF') { } else if ($output == 'PDF') {
$html = '<b>'.__('Unit').':</b> '.netflow_format_unit($unit);
$html .= '&nbsp;<b>'.__('Aggregate').":</b> $aggregate"; $html .= '&nbsp;<b>'.__('Aggregate').":</b> $aggregate";
$html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate), 2, true); $html .= graph_netflow_aggregate_pie($data_pie, netflow_format_aggregate($aggregate), 2, true);
return $html; return $html;
} else if ($output == 'XML') { } else if ($output == 'XML') {
$xml = "<unit>$unit</unit>\n";
$xml .= "<aggregate>$aggregate</aggregate>\n"; $xml .= "<aggregate>$aggregate</aggregate>\n";
$xml .= netflow_aggregate_pie_xml($data_pie); $xml .= netflow_aggregate_pie_xml($data_pie);
return $xml; return $xml;
@ -1268,7 +1260,7 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
$filter, $filter,
$aggregate, $aggregate,
$max_aggregates, $max_aggregates,
$unit, true,
$connection_name, $connection_name,
$address_resolution $address_resolution
); );
@ -1415,7 +1407,7 @@ function netflow_draw_item($start_date, $end_date, $interval_length, $type, $fil
$data['children'][] = $children; $data['children'][] = $children;
} }
} }
return graph_netflow_host_traffic($data, netflow_format_unit($unit), 'auto', 400); return graph_netflow_host_traffic($data, 'auto', 400);
break; break;
default: default:
@ -1493,7 +1485,6 @@ function netflow_xml_report($id, $start_date, $end_date, $interval_length=0)
echo ' <dst_port>'.io_safe_output($filter['src_port'])."</dst_port>\n"; echo ' <dst_port>'.io_safe_output($filter['src_port'])."</dst_port>\n";
echo ' <advanced>'.io_safe_output($filter['advanced_filter'])."</advanced>\n"; echo ' <advanced>'.io_safe_output($filter['advanced_filter'])."</advanced>\n";
echo ' <aggregate>'.io_safe_output($filter['aggregate'])."</aggregate>\n"; echo ' <aggregate>'.io_safe_output($filter['aggregate'])."</aggregate>\n";
echo ' <unit>'.io_safe_output($filter['output'])."</unit>\n";
echo " </filter>\n"; echo " </filter>\n";
echo netflow_draw_item($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $report['server_name'], 'XML'); echo netflow_draw_item($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $report['server_name'], 'XML');
@ -1642,38 +1633,6 @@ function netflow_summary_xml($data)
} }
/**
* Return a string describing the given unit.
*
* @param string Netflow unit.
*/
function netflow_format_unit($unit)
{
switch ($unit) {
case 'megabytes':
return __('MB');
case 'megabytespersecond':
return __('MB/s');
case 'kilobytes':
return __('kB');
case 'kilobytespersecond':
return __('kB/s');
case 'bytes':
return __('Bytes');
case 'bytespersecond':
return __('B/s');
default:
return '';
}
}
/** /**
* Return a string describing the given aggregate. * Return a string describing the given aggregate.
* *

View File

@ -80,7 +80,6 @@ $filter_id = (int) get_parameter('filter_id', 0);
$filter['id_name'] = get_parameter('name', ''); $filter['id_name'] = get_parameter('name', '');
$filter['id_group'] = (int) get_parameter('assign_group', 0); $filter['id_group'] = (int) get_parameter('assign_group', 0);
$filter['aggregate'] = get_parameter('aggregate', ''); $filter['aggregate'] = get_parameter('aggregate', '');
$filter['output'] = get_parameter('output', 'bytes');
$filter['ip_dst'] = get_parameter('ip_dst', ''); $filter['ip_dst'] = get_parameter('ip_dst', '');
$filter['ip_src'] = get_parameter('ip_src', ''); $filter['ip_src'] = get_parameter('ip_src', '');
$filter['dst_port'] = get_parameter('dst_port', ''); $filter['dst_port'] = get_parameter('dst_port', '');
@ -453,17 +452,6 @@ if (is_metaconsole()) {
echo '<td><b>'.__('Router ip').'</b></td>'; echo '<td><b>'.__('Router ip').'</b></td>';
echo '<td>'.html_print_input_text('router_ip', $filter['router_ip'], false, 30, 80, true).'</td>'; echo '<td>'.html_print_input_text('router_ip', $filter['router_ip'], false, 30, 80, true).'</td>';
echo '<td><b>'.__('Output format').'</b></td>';
$show_output = [
'bytes' => __('Bytes'),
'bytespersecond' => __('Bytes per second'),
'kilobytes' => __('Kilobytes'),
'megabytes' => __('Megabytes'),
'kilobytespersecond' => __('Kilobytes per second'),
'megabytespersecond' => __('Megabytes per second'),
];
echo '<td>'.html_print_select($show_output, 'output', $filter['output'], '', '', 0, true, false, true, '', false).'</td>';
echo '</tr>'; echo '</tr>';
echo '</table>'; echo '</table>';
@ -625,7 +613,6 @@ if (is_metaconsole()) {
$("#text-router_ip").val(''); $("#text-router_ip").val('');
$("#textarea_advanced_filter").val(''); $("#textarea_advanced_filter").val('');
$("#aggregate").val(''); $("#aggregate").val('');
$("#output").val('');
// Hide update filter button // Hide update filter button
$("#submit-update_button").hide(); $("#submit-update_button").hide();
@ -694,8 +681,6 @@ if (is_metaconsole()) {
$("#textarea_advanced_filter").val(val); $("#textarea_advanced_filter").val(val);
if (i == 'aggregate') if (i == 'aggregate')
$("#aggregate").val(val); $("#aggregate").val(val);
if (i == 'output')
$("#output").val(val);
}); });
}, },
"json"); "json");