webui: Added Pagination and server side search via Ajax to NTP (#4330)

webui: Added Pagination and server side search via Ajax to NTP (#4330)
This commit is contained in:
Aaron Daniels 2016-09-05 01:32:03 +10:00 committed by Neil Lathwood
parent 96fc6a8ff8
commit 705a73bda2
4 changed files with 129 additions and 80 deletions

View File

@ -0,0 +1,108 @@
<?php
$component = new LibreNMS\Component();
$options = array();
$options['filter']['ignore'] = array('=',0);
$options['type'] = 'ntp';
$components = $component->getComponents(null, $options);
$first = $_POST['current']-1; // Which record do we start on.
$last = $first + $_POST['rowCount']; // Which record do we end on.
$count = 0;
// Loop through each device in the component array
foreach ($components as $devid => $comp) {
$device = device_by_id_cache($devid);
// Loop through each component
foreach ($comp as $compid => $array) {
$display = true;
if ($_POST['view'] == 'error') {
// Only display peers with errors
if ($array['status'] != 2) {
$display = false;
}
}
if ($array['status'] == 2) {
$status = 'class="danger"';
} else {
$status = '';
}
// Let's process some searching..
if (($display === true) && ($_POST['searchPhrase'] != "")) {
$searchfound = false;
$searchdata = array($device['hostname'],$array['peer'],$array['stratum'],$array['error']);
foreach ($searchdata as $value) {
if (strstr($value, $_POST['searchPhrase'])) {
$searchfound = true;
}
}
// If we didnt match this record while searching, we should exclude it from the results.
if ($searchfound === false) {
$display = false;
}
}
if ($display === true) {
$count++;
// If this record is in the range we want.
if (($count > $first) && ($count <= $last)) {
$device_link = generate_device_link($device, null, array('tab' => 'apps', 'app' => 'ntp'));
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['width'] = 80;
$graph_array['height'] = 20;
// Which graph type do we want?
if ($_POST['graph'] == "stratum") {
$graph_array['type'] = 'device_ntp_stratum';
} elseif ($_POST['graph'] == "offset") {
$graph_array['type'] = 'device_ntp_offset';
} elseif ($_POST['graph'] == "delay") {
$graph_array['type'] = 'device_ntp_delay';
} elseif ($_POST['graph'] == "dispersion") {
$graph_array['type'] = 'device_ntp_dispersion';
} else {
// No Graph
unset($graph_array);
}
$response[] = array(
'device' => $device_link,
'peer' => $array['peer'],
'stratum' => $array['stratum'],
'error' => $array['error'],
);
// Do we want a graphrow.
if (is_array($graph_array)) {
$return_data = true;
require 'includes/print-graphrow.inc.php';
unset($return_data);
$response[] = array(
'device' => $graph_data[0],
'peer' => $graph_data[1],
'stratum' => $graph_data[2],
'error' => $graph_data[3],
);
}
} // End if in range
} // End if display
} // End foreach component
} // End foreach device
// If there are no results, let the user know.
if ($count == 0) {
$response = array();
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $count,
);
echo _json_encode($output);

View File

@ -80,86 +80,27 @@ echo '</div>';
print_optionbar_end();
?>
<table id='table' class='table table-condensed table-responsive table-striped'>
<table id='ntp-table' class='table table-condensed table-responsive table-striped'>
<thead>
<tr>
<th>Device</th>
<th>Peer</th>
<th>Stratum</th>
<th>Error</th>
<th data-column-id="device">Device</th>
<th data-column-id="peer">Peer</th>
<th data-column-id="stratum" data-type="numeric">Stratum</th>
<th data-column-id="error">Error</th>
</tr>
</thead>
<?php
$count = 0;
// Loop through each device in the componenet array
foreach ($components as $devid => $comp) {
$device = device_by_id_cache($devid);
// Loop through each component
foreach ($comp as $compid => $array) {
$display = true;
if ($vars['view'] == 'error') {
// Only display peers with errors
if ($array['status'] != 2) {
$display = false;
}
}
if ($array['status'] == 2) {
$status = 'class="danger"';
} else {
$status = '';
}
if ($display === true) {
$link = generate_device_link($device, null, array('tab' => 'apps', 'app' => 'ntp'));
$count++;
?>
<tr <?php echo $status; ?>>
<td><?php echo $link; ?></td>
<td><?php echo $array['peer']; ?></td>
<td><?php echo $array['stratum']; ?></td>
<td><?php echo $array['error']; ?></td>
</tr>
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
// Which graph type do we want?
if ($vars['graph'] == "stratum") {
$graph_array['type'] = 'device_ntp_stratum';
} elseif ($vars['graph'] == "offset") {
$graph_array['type'] = 'device_ntp_offset';
} elseif ($vars['graph'] == "delay") {
$graph_array['type'] = 'device_ntp_delay';
} elseif ($vars['graph'] == "dispersion") {
$graph_array['type'] = 'device_ntp_dispersion';
} else {
// No Graph
unset($graph_array);
}
// Do we want a graph.
if (is_array($graph_array)) {
echo '<tr>';
echo '<td colspan="4">';
require 'includes/print-graphrow.inc.php';
echo '</td>';
echo '</tr>';
}
} // End if display
} // End foreach component
} // End foreach device
// If there are no results, let the user know.
if ($count == 0) {
?>
<tr>
<td colspan="4" align="center">No Matching NTP Peers</td>
</tr>
<?php
}
?>
</table>
<script>
$("#ntp-table").bootgrid({
ajax: true,
post: function ()
{
return {
id: "app_ntp",
view: '<?php echo $vars['view']; ?>',
graph: '<?php echo $vars['graph']; ?>',
};
},
url: "ajax_table.php",
});
</script>

View File

@ -26,5 +26,5 @@
*/
if ($device['os_group'] == 'cisco') {
require_once 'includes/discovery/ntp/cisco.inc.php';
include 'includes/discovery/ntp/cisco.inc.php';
}

View File

@ -19,5 +19,5 @@
*/
if ($device['os_group'] == 'cisco') {
require_once 'includes/polling/ntp/cisco.inc.php';
include 'includes/polling/ntp/cisco.inc.php';
}