mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-02 00:32:09 +02:00
Next revision for review - 3 out of 4 queries working happily now
This commit is contained in:
@@ -55,39 +55,40 @@ if( defined('show_settings') || empty($widget_settings) ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$interval = $widget_settings['time_interval'];
|
$interval = $widget_settings['time_interval'];
|
||||||
$interval_seconds = ($interval * 60);
|
(integer) $interval_seconds = ($interval * 60);
|
||||||
$device_count = $widget_settings['device_count'];
|
(integer) $device_count = $widget_settings['device_count'];
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
<h4>Top '.$device_count.' devices (last '.$interval.' minutes)</h4>
|
<h4>Top '.$device_count.' devices (last '.$interval.' minutes)</h4>
|
||||||
';
|
';
|
||||||
|
$params = array('user' => $_SESSION['user_id'], 'interval' => array($interval_seconds), 'count' => array($device_count));
|
||||||
if (is_admin() || is_read()) {
|
if (is_admin() || is_read()) {
|
||||||
$query = '
|
$query = '
|
||||||
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
||||||
FROM ports as p, devices as d
|
FROM ports as p, devices as d
|
||||||
WHERE d.device_id = p.device_id
|
WHERE d.device_id = p.device_id
|
||||||
AND unix_timestamp() - p.poll_time < ?
|
AND unix_timestamp() - p.poll_time < :interval
|
||||||
AND ( p.ifInOctets_rate > 0
|
AND ( p.ifInOctets_rate > 0
|
||||||
OR p.ifOutOctets_rate > 0 )
|
OR p.ifOutOctets_rate > 0 )
|
||||||
GROUP BY d.device_id
|
GROUP BY d.device_id
|
||||||
ORDER BY total desc
|
ORDER BY total desc
|
||||||
LIMIT ?
|
LIMIT :count
|
||||||
';
|
';
|
||||||
$params = array($interval_seconds, $device_count);
|
// $params = array(array($interval_seconds), array($device_count));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = '
|
$query = '
|
||||||
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total
|
||||||
FROM ports as p, devices as d, `devices_perms` AS `P`
|
FROM ports as p, devices as d, `devices_perms` AS `P`
|
||||||
WHERE `P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id` AND
|
WHERE `P`.`user_id` = :user AND `P`.`device_id` = `d`.`device_id` AND
|
||||||
d.device_id = p.device_id
|
d.device_id = p.device_id
|
||||||
AND unix_timestamp() - p.poll_time < ?
|
AND unix_timestamp() - p.poll_time < :interval
|
||||||
AND ( p.ifInOctets_rate > 0
|
AND ( p.ifInOctets_rate > 0
|
||||||
OR p.ifOutOctets_rate > 0 )
|
OR p.ifOutOctets_rate > 0 )
|
||||||
GROUP BY d.device_id
|
GROUP BY d.device_id
|
||||||
ORDER BY total desc
|
ORDER BY total desc
|
||||||
LIMIT ?
|
LIMIT :count
|
||||||
';
|
';
|
||||||
$params = array($_SESSION['user_id'], $interval_seconds, $device_count);
|
// $params = array($_SESSION['user_id'], array($interval_seconds), array($device_count));
|
||||||
}
|
}
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -111,7 +112,7 @@ else {
|
|||||||
$result, $config['time']['day'],
|
$result, $config['time']['day'],
|
||||||
$config['time']['now'],
|
$config['time']['now'],
|
||||||
'device_bits',
|
'device_bits',
|
||||||
'no', 150, 21, '&', 'top10'),
|
'no', 150, 21),
|
||||||
array(), 0, 0, 0).'
|
array(), 0, 0, 0).'
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -55,40 +55,41 @@ if( defined('show_settings') || empty($widget_settings) ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$interval = $widget_settings['time_interval'];
|
$interval = $widget_settings['time_interval'];
|
||||||
$interval_seconds = ($interval * 60);
|
(integer) $interval_seconds = ($interval * 60);
|
||||||
$interface_count = $widget_settings['interface_count'];
|
(integer) $interface_count = $widget_settings['interface_count'];
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
<h4>Top '.$interface_count.' interfaces (last '.$interval.' minutes)</h4>
|
<h4>Top '.$interface_count.' interfaces (last '.$interval.' minutes)</h4>
|
||||||
';
|
';
|
||||||
|
$params = array('user' => $_SESSION['user_id'], 'interval' => array($interval_seconds), 'count' => array($interface_count));
|
||||||
if (is_admin() || is_read()) {
|
if (is_admin() || is_read()) {
|
||||||
$query = '
|
$query = '
|
||||||
SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total
|
SELECT *, p.ifInOctets_rate + p.ifOutOctets_rate as total
|
||||||
FROM ports as p, devices as d
|
FROM ports as p, devices as d
|
||||||
WHERE d.device_id = p.device_id
|
WHERE d.device_id = p.device_id
|
||||||
AND unix_timestamp() - p.poll_time < ?
|
AND unix_timestamp() - p.poll_time < :interval
|
||||||
AND ( p.ifInOctets_rate > 0
|
AND ( p.ifInOctets_rate > 0
|
||||||
OR p.ifOutOctets_rate > 0 )
|
OR p.ifOutOctets_rate > 0 )
|
||||||
ORDER BY total desc
|
ORDER BY total desc
|
||||||
LIMIT ?
|
LIMIT :count
|
||||||
';
|
';
|
||||||
$params = array($interval_seconds, $interface_count);
|
// $params = array(array($interval_seconds), array($interface_count));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = '
|
$query = '
|
||||||
SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total
|
SELECT *, I.ifInOctets_rate + I.ifOutOctets_rate as total
|
||||||
FROM ports as I, devices as d,
|
FROM ports as I, devices as d,
|
||||||
`devices_perms` AS `P`, `ports_perms` AS `PP`
|
`devices_perms` AS `P`, `ports_perms` AS `PP`
|
||||||
WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id`)
|
WHERE ((`P`.`user_id` = :user AND `P`.`device_id` = `d`.`device_id`)
|
||||||
OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id`
|
OR (`PP`.`user_id` = :user AND `PP`.`port_id` = `I`.`port_id`
|
||||||
AND `I`.`device_id` = `d`.`device_id`)) AND
|
AND `I`.`device_id` = `d`.`device_id`)) AND
|
||||||
d.device_id = I.device_id
|
d.device_id = I.device_id
|
||||||
AND unix_timestamp() - I.poll_time < ?
|
AND unix_timestamp() - I.poll_time < :interval
|
||||||
AND ( I.ifInOctets_rate > 0
|
AND ( I.ifInOctets_rate > 0
|
||||||
OR I.ifOutOctets_rate > 0 )
|
OR I.ifOutOctets_rate > 0 )
|
||||||
ORDER BY total desc
|
ORDER BY total desc
|
||||||
LIMIT ?
|
LIMIT :count
|
||||||
';
|
';
|
||||||
$params = array($_SESSION['user_id'], $interval_seconds, $device_count);
|
// $params = array($_SESSION['user_id'], $_SESSION['user_id'], array($interval_seconds), array($interface_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
|
|||||||
Reference in New Issue
Block a user