Added listeners and talkers netflow explorer

Former-commit-id: aabd4c468ae9163a89447da170861a5ab1dcc2a0
This commit is contained in:
fermin831 2019-03-06 13:31:55 +01:00
parent 2e65301ace
commit ccb8078a5a
4 changed files with 141 additions and 1 deletions

View File

@ -1866,3 +1866,91 @@ function netflow_check_nfdump_binary($nfdump_binary)
return 2; return 2;
} }
/**
* Get the netflow datas to build a netflow explorer data structure.
*
* @param integer $max Number of result displayed.
* @param string $top_action Action to do (listeners,talkers,tcp or udp).
* @param integer $start_date In utimestamp.
* @param integer $end_date In utimestamp.
* @param string $filter Ip to filter.
*
* @return array With data (host, sum_bytes, sum_pkts and sum_flows).
*/
function netflow_get_top_summary(
$max,
$top_action,
$start_date,
$end_date,
$filter=''
) {
global $nfdump_date_format;
$netflow_filter = [];
$sort = '';
switch ($top_action) {
case 'listeners':
if (empty(!$filter)) {
$netflow_filter['ip_src'] = $filter;
}
$sort = 'dstip';
break;
case 'talkers':
if (empty(!$filter)) {
$netflow_filter['ip_dst'] = $filter;
}
$sort = 'srcip';
break;
case 'tcp':
// Todo.
break;
case 'udp':
// Todo.
break;
default:
return [];
}
$command = netflow_get_command($netflow_filter);
// Execute nfdump.
$command .= " -q -o csv -n $max -s $sort/bytes -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date);
exec($command, $result);
if (! is_array($result)) {
return [];
}
// Remove first line (avoiding slow array_shift).
$result = array_reverse($result);
array_pop($result);
$result = array_reverse($result);
$top_info = [];
foreach ($result as $line) {
if (empty($line)) {
continue;
}
$data = explode(',', $line);
if (!isset($data[9])) {
continue;
}
$top_info[$data[4]] = [
'host' => $data[4],
'sum_bytes' => $data[9],
'sum_pkts' => $data[7],
'sum_flows' => $data[5],
];
}
return $top_info;
}

View File

@ -81,7 +81,7 @@ if (check_acl($config['id_user'], 0, 'AR')) {
$netflow_sub = array_merge( $netflow_sub = array_merge(
$netflow_sub, $netflow_sub,
[ [
'operation/netflow/network_explorer' => [ 'operation/netflow/netflow_explorer' => [
'text' => __('Netflow explorer'), 'text' => __('Netflow explorer'),
'id' => 'Netflow explorer', 'id' => 'Netflow explorer',
], ],

View File

@ -0,0 +1,40 @@
<?php
/**
* Network explorer
*
* @package Operations.
* @subpackage Netflow explorer view.
*
* Pandora FMS - http://pandorafms.com
* ==================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
global $config;
check_login();
// ACL Check.
if (! check_acl($config['id_user'], 0, 'AR')) {
db_pandora_audit(
'ACL Violation',
'Trying to access Netflow explorer'
);
include 'general/noaccess.php';
exit;
}
$action = get_parameter('action', 'listeners');
$is_network = false;
ui_print_page_header(__('Netflow explorer'));
require $config['homedir'].'/operation/network/network_report.php';

View File

@ -147,6 +147,14 @@ if ($is_network) {
$utimestamp_greater, $utimestamp_greater,
$main_value $main_value
); );
} else {
$data = netflow_get_top_summary(
$top,
$action,
$utimestamp_lower,
$utimestamp_greater,
$main_value
);
} }
unset($table); unset($table);
@ -226,6 +234,10 @@ foreach ($data as $item) {
$item['host'], $item['host'],
array_merge($hidden_main_link, ['main_value' => $item['host']]) array_merge($hidden_main_link, ['main_value' => $item['host']])
); );
if (!$is_network) {
$row['flows'] = format_for_graph($item['sum_flows'], 2);
}
$row['pkts'] = format_for_graph($item['sum_pkts'], 2); $row['pkts'] = format_for_graph($item['sum_pkts'], 2);
$row['bytes'] = format_for_graph( $row['bytes'] = format_for_graph(
$item['sum_bytes'], $item['sum_bytes'],