*
* 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) $lastpoll_seconds = ($interval * 60);
(integer) $interface_count = $widget_settings['interface_count'];
$params = array('user' => $_SESSION['user_id'], 'lastpoll' => array($lastpoll_seconds), 'count' => array($interface_count), 'filter' => ($widget_settings['interface_filter']?:(int)1));
if (is_admin() || is_read()) {
$query = '
SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total
FROM ports as p
INNER JOIN devices ON p.device_id = devices.device_id
AND unix_timestamp() - p.poll_time <= :lastpoll
AND ( p.ifType = :filter || 1 = :filter )
AND ( p.ifInOctets_rate > 0 || p.ifOutOctets_rate > 0 )
ORDER BY total DESC
LIMIT :count
';
}
else {
$query = '
SELECT ports.*, devices.hostname, ports.ifInOctets_rate + ports.ifOutOctets_rate as total
FROM ports
INNER JOIN devices ON ports.device_id = devices.device_id
LEFT JOIN ports_perms ON ports.port_id = ports_perms.port_id
LEFT JOIN devices_perms ON devices.device_id = devices_perms.device_id
WHERE ( ports_perms.user_id = :user || devices_perms.user_id = :user )
AND unix_timestamp() - ports.poll_time <= :lastpoll
AND ( ports.ifType = :filter || 1 = :filter )
AND ( ports.ifInOctets_rate > 0 || ports.ifOutOctets_rate > 0 )
GROUP BY ports.port_id
ORDER BY total DESC
LIMIT :count
';
}
$common_output[] = '
Top '.$interface_count.' interfaces polled within '.$interval.' minutes
Device
Interface
Total traffic
';
foreach (dbFetchRows($query, $params) as $result) {
$common_output[] = '