mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added ability to filter top interfaces by type
This commit is contained in:
@@ -294,6 +294,28 @@ if (isset($_REQUEST['search'])) {
|
|||||||
}//end foreach
|
}//end foreach
|
||||||
}//end if
|
}//end if
|
||||||
|
|
||||||
|
$json = json_encode($device);
|
||||||
|
die($json);
|
||||||
|
}
|
||||||
|
else if ($_REQUEST['type'] == 'iftype') {
|
||||||
|
// Device search
|
||||||
|
if (is_admin() === true || is_read() === true) {
|
||||||
|
$results = dbFetchRows("SELECT `ports`.ifType FROM `ports` WHERE `ifType` LIKE '%".$search."%' GROUP BY ifType ORDER BY ifType LIMIT 8");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$results = dbFetchRows("SELECT `I`.ifType FROM `ports` AS `I`, `devices` AS `D`, `devices_perms` AS `P`, `ports_perms` AS `PP` WHERE ((`P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id`) OR (`PP`.`user_id` = ? AND `PP`.`port_id` = `I`.`port_id` AND `I`.`device_id` = `D`.`device_id`)) AND `D`.`device_id` = `I`.`device_id` AND (`ifType` LIKE '%".$search."%') GROUP BY ifType ORDER BY ifType LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id']));
|
||||||
|
}
|
||||||
|
if (count($results)) {
|
||||||
|
$found = 1;
|
||||||
|
$devices = count($results);
|
||||||
|
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$device[] = array(
|
||||||
|
'filter' => $result['ifType'],
|
||||||
|
);
|
||||||
|
}//end foreach
|
||||||
|
}//end if
|
||||||
|
|
||||||
$json = json_encode($device);
|
$json = json_encode($device);
|
||||||
die($json);
|
die($json);
|
||||||
}//end if
|
}//end if
|
||||||
|
@@ -27,74 +27,110 @@
|
|||||||
|
|
||||||
if( defined('show_settings') || empty($widget_settings) ) {
|
if( defined('show_settings') || empty($widget_settings) ) {
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
<form class="form-horizontal" onsubmit="widget_settings(this); return false;">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-6">
|
<label for="interface_count" class="col-sm-5 control-label">Number of Interfaces: </label>
|
||||||
<label for="graph_type" class="control-label">Number of Interfaces: </label>
|
<div class="col-sm-7">
|
||||||
</div>
|
<input class="form-control" type="number" min="0" step="1" name="interface_count" id="input_count_'.$unique_id.'" placeholder="ie. 5" value="'.$widget_settings['interface_count'].'">
|
||||||
<div class="col-sm-4">
|
|
||||||
<input class="form-control" name="interface_count" id="input_count_'.$unique_id.'" placeholder="ie. 5" value="'.$widget_settings['interface_count'].'">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<label for="graph_type" class="control-label">Time interval (minutes): </label>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-4">
|
|
||||||
<input class="form-control" name="time_interval" id="input_time_'.$unique_id.'" placeholder="ie. 15" value="'.$widget_settings['time_interval'].'">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-2">
|
<label for="time_interval" class="col-sm-5 control-label">Last Polled within (minutes): </label>
|
||||||
|
<div class="col-sm-7">
|
||||||
|
<input class="form-control" type="number" min="5" step="1" name="time_interval" id="input_time_'.$unique_id.'" placeholder="ie. 15" value="'.$widget_settings['time_interval'].'">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="interface_filter" class="col-sm-5 control-label">Interface Type: </label>
|
||||||
|
<div class="col-sm-7">
|
||||||
|
<input class="form-control" name="interface_filter" id="input_filter_'.$unique_id.'" placeholder="Any" value="'.$widget_settings['interface_filter'].'">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-5 col-sm-7">
|
||||||
<button type="submit" class="btn btn-default">Set</button>
|
<button type="submit" class="btn btn-default">Set</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var '.$unique_id.'_filter = new Bloodhound({
|
||||||
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace("name"),
|
||||||
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||||
|
remote: {
|
||||||
|
url: "ajax_search.php?search=%QUERY&type=iftype",
|
||||||
|
filter: function (output) {
|
||||||
|
return $.map(output, function (item) {
|
||||||
|
return {
|
||||||
|
filter: item.filter
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
wildcard: "%QUERY"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
'.$unique_id.'_filter.initialize();
|
||||||
|
$("#input_filter_'.$unique_id.'").typeahead({
|
||||||
|
hint: true,
|
||||||
|
highlight: true,
|
||||||
|
minLength: 1,
|
||||||
|
classNames: {
|
||||||
|
menu: "typeahead-left"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '.$unique_id.'_filter.ttAdapter(),
|
||||||
|
async: false,
|
||||||
|
display: "filter",
|
||||||
|
templates: {
|
||||||
|
header: "<h5><strong> Interface Types</strong></h5>",
|
||||||
|
suggestion: Handlebars.compile("<p>{{filter}}</p>")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
.twitter-typeahead {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$interval = $widget_settings['time_interval'];
|
$interval = $widget_settings['time_interval'];
|
||||||
(integer) $interval_seconds = ($interval * 60);
|
(integer) $lastpoll_seconds = ($interval * 60);
|
||||||
(integer) $interface_count = $widget_settings['interface_count'];
|
(integer) $interface_count = $widget_settings['interface_count'];
|
||||||
$common_output[] = '
|
$params = array('user' => $_SESSION['user_id'], 'lastpoll' => array($lastpoll_seconds), 'count' => array($interface_count), 'filter' => ($widget_settings['interface_filter']?:(int)1));
|
||||||
<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
|
||||||
WHERE d.device_id = p.device_id
|
INNER JOIN devices ON p.device_id = devices.device_id
|
||||||
AND unix_timestamp() - p.poll_time < :interval
|
AND unix_timestamp() - p.poll_time <= :lastpoll
|
||||||
AND ( p.ifInOctets_rate > 0
|
AND ( p.ifType = :filter || 1 = :filter )
|
||||||
OR p.ifOutOctets_rate > 0 )
|
AND ( p.ifInOctets_rate > 0 || p.ifOutOctets_rate > 0 )
|
||||||
ORDER BY total desc
|
ORDER BY total DESC
|
||||||
LIMIT :count
|
LIMIT :count
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = '
|
$query = '
|
||||||
SELECT ports.*, devices.hostname, ports.ifInOctets_rate + ports.ifOutOctets_rate as total
|
SELECT ports.*, devices.hostname, ports.ifInOctets_rate + ports.ifOutOctets_rate as total
|
||||||
FROM devices, ports
|
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 ports_perms ON ports.port_id = ports_perms.port_id
|
||||||
WHERE ports_perms.user_id = :user
|
LEFT JOIN devices_perms ON devices.device_id = devices_perms.device_id
|
||||||
AND unix_timestamp() - ports.poll_time < :interval
|
WHERE ( ports_perms.user_id = :user || devices_perms.user_id = :user )
|
||||||
AND (ports.ifInOctets_rate > 0 OR ports.ifOutOctets_rate > 0)
|
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
|
GROUP BY ports.port_id
|
||||||
UNION ALL
|
ORDER BY total DESC
|
||||||
SELECT ports.*, devices.hostname, ports.ifInOctets_rate + ports.ifOutOctets_rate as total
|
LIMIT :count
|
||||||
FROM ports, devices LEFT JOIN devices_perms ON devices.device_id = devices_perms.device_id
|
|
||||||
WHERE devices_perms.user_id = :user
|
|
||||||
AND ports.device_id = devices.device_id
|
|
||||||
AND unix_timestamp() - ports.poll_time < :interval
|
|
||||||
AND (ports.ifInOctets_rate > 0 OR ports.ifOutOctets_rate > 0)
|
|
||||||
GROUP BY ports.port_id
|
|
||||||
ORDER BY total DESC LIMIT :count
|
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
|
||||||
$common_output[] = '
|
$common_output[] = '
|
||||||
|
<h4>Top '.$interface_count.' interfaces polled within '.$interval.' minutes</h4>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-hover table-condensed table-striped bootgrid-table">
|
<table class="table table-hover table-condensed table-striped bootgrid-table">
|
||||||
<thead>
|
<thead>
|
||||||
|
Reference in New Issue
Block a user