Moved report nt_top_n requesting data to functions_network

Former-commit-id: a117a63c1b23c0104ffadb2741d049f02a81d6d4
This commit is contained in:
fermin831 2019-03-04 12:43:31 +01:00
parent b11fd87592
commit f9b14072d8
2 changed files with 65 additions and 10 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* Network explorer
*
* @package Include.
* @subpackage Network functions.
*
* 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.
*/
// Write here requires and definitions.
/**
* Get the tnetwok_matrix summatory data.
*
* @param integer $top Number of hosts to show.
* @param boolean $talker Talker (true) or listetener (false).
* @param integer $start Utimestamp of start time.
* @param integer $end Utimestamp of end time.
*
* @return array With requested data.
*/
function network_matrix_get_top($top, $talker, $start, $end)
{
$field_to_group = ($talker === true) ? 'source' : 'destination';
$sql = sprintf(
'SELECT SUM(bytes) sum_bytes, SUM(pkts) sum_pkts, %s host
FROM tnetwork_matrix
WHERE utimestamp > %d AND utimestamp < %d
GROUP BY %s
ORDER BY sum_bytes DESC
LIMIT %d',
$field_to_group,
$start,
$end,
$field_to_group,
$top
);
$data = db_get_all_rows_sql($sql);
return ($data !== false) ? $data : [];
}

View File

@ -36,6 +36,7 @@ require_once $config['homedir'].'/include/functions_forecast.php';
require_once $config['homedir'].'/include/functions_ui.php';
require_once $config['homedir'].'/include/functions_netflow.php';
require_once $config['homedir'].'/include/functions_os.php';
require_once $config['homedir'].'/include/functions_network.php';
//
// CONSTANTS DEFINITIONS //
@ -11385,17 +11386,17 @@ function reporting_nt_top_n_report($period, $content, $pdf)
// Get the data sent and received
$return['data'] = [];
$start_time = ($period['datetime'] - (int) $content['period']);
$sql = "SELECT SUM(bytes) sum_bytes, SUM(pkts) sum_pkts, %s host
FROM tnetwork_matrix
WHERE utimestamp > {$start_time} AND utimestamp < {$period['datetime']}
GROUP BY %s
ORDER BY sum_bytes DESC
LIMIT {$content['top_n_value']}";
$return['data']['send'] = db_get_all_rows_sql(
sprintf($sql, 'source', 'source')
$return['data']['send'] = network_matrix_get_top(
$content['top_n_value'],
true,
$start_time,
$period['datetime']
);
$return['data']['recv'] = db_get_all_rows_sql(
sprintf($sql, 'destination', 'destination')
$return['data']['recv'] = network_matrix_get_top(
$content['top_n_value'],
false,
$start_time,
$period['datetime']
);
return $return;
}