Added filter by ip requesting network matrix datas

Former-commit-id: 20a88fe66f9bcb2c39a9121b46e7204ed006470d
This commit is contained in:
Fermin 2019-03-04 20:26:11 +01:00
parent c95b057c14
commit d62b7f0d79
2 changed files with 17 additions and 6 deletions

View File

@ -28,22 +28,31 @@
* @param boolean $talker Talker (true) or listetener (false). * @param boolean $talker Talker (true) or listetener (false).
* @param integer $start Utimestamp of start time. * @param integer $start Utimestamp of start time.
* @param integer $end Utimestamp of end time. * @param integer $end Utimestamp of end time.
* @param string $ip_filter Ip to filter.
* *
* @return array With requested data. * @return array With requested data.
*/ */
function network_matrix_get_top($top, $talker, $start, $end) function network_matrix_get_top($top, $talker, $start, $end, $ip_filter='')
{ {
$field_to_group = ($talker === true) ? 'source' : 'destination'; $field_to_group = ($talker === true) ? 'source' : 'destination';
$filter_sql = '';
if (!empty($ip_filter)) {
$filter_field = ($talker === true) ? 'destination' : 'source';
$filter_sql = sprintf('AND %s="%s"', $filter_field, $ip_filter);
}
$sql = sprintf( $sql = sprintf(
'SELECT SUM(bytes) sum_bytes, SUM(pkts) sum_pkts, %s host 'SELECT SUM(bytes) sum_bytes, SUM(pkts) sum_pkts, %s host
FROM tnetwork_matrix FROM tnetwork_matrix
WHERE utimestamp > %d AND utimestamp < %d WHERE utimestamp > %d AND utimestamp < %d
%s
GROUP BY %s GROUP BY %s
ORDER BY sum_bytes DESC ORDER BY sum_bytes DESC
LIMIT %d', LIMIT %d',
$field_to_group, $field_to_group,
$start, $start,
$end, $end,
$filter_sql,
$field_to_group, $field_to_group,
$top $top
); );

View File

@ -134,12 +134,14 @@ if ($is_network) {
$top, $top,
$action === 'talkers', $action === 'talkers',
$utimestamp_lower, $utimestamp_lower,
$utimestamp_greater $utimestamp_greater,
''
); );
} }
unset($table); unset($table);
$table = new stdClass(); $table = new stdClass();
$table->styleTable = 'width: 100%';
// Print the header. // Print the header.
$table->head = []; $table->head = [];
$table->head[] = __('IP'); $table->head[] = __('IP');