*
* This widget is based on legacy frontpage module created by Paul Gear.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see . */
/**
* Top interfaces by traffic
* @author Sergiusz Paprzycki
* @copyright 2015 Sergiusz Paprzycki
* @license GPL
* @package LibreNMS
* @subpackage Widgets
*/
if( defined('show_settings') || empty($widget_settings) ) {
$common_output[] = '
';
}
else {
$interval = $widget_settings['time_interval'];
(integer) $interval_seconds = ($interval * 60);
(integer) $interface_count = $widget_settings['interface_count'];
$common_output[] = '
Top '.$interface_count.' interfaces (last '.$interval.' minutes)
';
$params = array('user' => $_SESSION['user_id'], 'interval' => array($interval_seconds), 'count' => array($interface_count));
if (is_admin() || is_read()) {
$query = '
SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total
FROM ports as p, devices as d
WHERE d.device_id = p.device_id
AND unix_timestamp() - p.poll_time < :interval
AND ( p.ifInOctets_rate > 0
OR p.ifOutOctets_rate > 0 )
ORDER BY total desc
LIMIT :count
';
// $params = array(array($interval_seconds), array($interface_count));
}
else {
$query = '
SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total
FROM ports as I, devices as d,
`devices_perms` AS `P`, `ports_perms` AS `PP`
WHERE ((`P`.`user_id` = :user AND `P`.`device_id` = `d`.`device_id`)
OR (`PP`.`user_id` = :user AND `PP`.`port_id` = `I`.`port_id`
AND `I`.`device_id` = `d`.`device_id`)) AND
d.device_id = I.device_id
AND unix_timestamp() - I.poll_time < :interval
AND ( I.ifInOctets_rate > 0
OR I.ifOutOctets_rate > 0 )
ORDER BY total desc
LIMIT :count
';
// $params = array($_SESSION['user_id'], $_SESSION['user_id'], array($interval_seconds), array($interface_count));
}
$common_output[] = '
Device
Interface
Total traffic
';
foreach (dbFetchRows($query, $params) as $result) {
$common_output[] = '