1<?php
2/*
3 * LibreNMS module to capture statistics from the CISCO-NTP-MIB
4 *
5 * Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.  Please see LICENSE.txt at the top level of
11 * the source code distribution for details.
12 */
13
14$component = new LibreNMS\Component();
15$options = [];
16$options['filter']['ignore'] = ['=', 0];
17$options['type'] = 'ntp';
18$components = $component->getComponents(null, $options);
19
20print_optionbar_start();
21
22$view_options = [
23    'all'       => 'All',
24    'error'     => 'Error',
25];
26if (! $vars['view']) {
27    $vars['view'] = 'all';
28}
29
30$graph_options = [
31    'none'          => 'No Graphs',
32    'stratum'       => 'Stratum',
33    'offset'        => 'Offset',
34    'delay'         => 'Delay',
35    'dispersion'    => 'Dispersion',
36];
37if (! $vars['graph']) {
38    $vars['graph'] = 'none';
39}
40
41echo '<span style="font-weight: bold;">NTP Peers</span> &#187; ';
42
43// The menu option - on the left
44$sep = '';
45foreach ($view_options as $option => $text) {
46    if (empty($vars['view'])) {
47        $vars['view'] = $option;
48    }
49    echo $sep;
50    if ($vars['view'] == $option) {
51        echo "<span class='pagemenu-selected'>";
52    }
53    echo generate_link($text, $vars, ['view' => $option]);
54    if ($vars['view'] == $option) {
55        echo '</span>';
56    }
57    $sep = ' | ';
58}
59
60// The status option - on the right
61echo '<div class="pull-right">';
62$sep = '';
63foreach ($graph_options as $option => $text) {
64    if (empty($vars['graph'])) {
65        $vars['graph'] = $option;
66    }
67    echo $sep;
68    if ($vars['graph'] == $option) {
69        echo "<span class='pagemenu-selected'>";
70    }
71
72    echo generate_link($text, $vars, ['graph' => $option]);
73    if ($vars['graph'] == $option) {
74        echo '</span>';
75    }
76    $sep = ' | ';
77}
78unset($sep);
79echo '</div>';
80print_optionbar_end();
81
82?>
83<table id='ntp-table' class='table table-condensed table-responsive table-striped'>
84    <thead>
85    <tr>
86        <th data-column-id="device">Device</th>
87        <th data-column-id="peer">Peer</th>
88        <th data-column-id="stratum" data-type="numeric">Stratum</th>
89        <th data-column-id="error">Error</th>
90    </tr>
91    </thead>
92</table>
93<script>
94    $("#ntp-table").bootgrid({
95        ajax: true,
96        post: function ()
97        {
98            return {
99                id: "app_ntp",
100                view: '<?php echo $vars['view']; ?>',
101                graph: '<?php echo $vars['graph']; ?>',
102            };
103        },
104        url: "ajax_table.php",
105    });
106</script>
107