mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
CISCO-NTP-MIB
A new Discovery/Poller module to collect NTP statistics from devices which support the CISCO-NTP-MIB Discovered peers are stored using components and statistics are displayed using 'applications' A critical alarm is raised when a stratum of 16 is reported.
This commit is contained in:
53
html/includes/graphs/device/cisco-ntp_delay.inc.php
Normal file
53
html/includes/graphs/device/cisco-ntp_delay.inc.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
include "includes/graphs/common.inc.php";
|
||||
$rrd_options .= " -l 0 -E ";
|
||||
$rrd_options .= " COMMENT:'Delay Now Min Max\\n'";
|
||||
$rrd_additions = "";
|
||||
|
||||
$count = 0;
|
||||
foreach ($components as $id => $array) {
|
||||
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("ntp-".$array['peer'].".rrd");
|
||||
|
||||
if (file_exists($rrd_filename)) {
|
||||
// Grab a color from the array.
|
||||
if ( isset($config['graph_colours']['mixed'][$count]) ) {
|
||||
$color = $config['graph_colours']['mixed'][$count];
|
||||
} else {
|
||||
$color = $config['graph_colours']['oranges'][$count-7];
|
||||
}
|
||||
|
||||
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":delay:AVERAGE ";
|
||||
$rrd_additions .= " LINE1.25:DS" . $count . "#" . $color . ":'" . str_pad(substr($array['peer'].' (s)',0,15),15) . "'" . $stack;
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":LAST:%7.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MIN:%7.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MAX:%7.0lf\\\l ";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rrd_additions == "") {
|
||||
// We didn't add any data points.
|
||||
} else {
|
||||
$rrd_options .= $rrd_additions;
|
||||
}
|
53
html/includes/graphs/device/cisco-ntp_dispersion.inc.php
Normal file
53
html/includes/graphs/device/cisco-ntp_dispersion.inc.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
include "includes/graphs/common.inc.php";
|
||||
$rrd_options .= " -l 0 -E ";
|
||||
$rrd_options .= " COMMENT:'Dispersion Now Min Max\\n'";
|
||||
$rrd_additions = "";
|
||||
|
||||
$count = 0;
|
||||
foreach ($components as $id => $array) {
|
||||
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("ntp-".$array['peer'].".rrd");
|
||||
|
||||
if (file_exists($rrd_filename)) {
|
||||
// Grab a color from the array.
|
||||
if ( isset($config['graph_colours']['mixed'][$count]) ) {
|
||||
$color = $config['graph_colours']['mixed'][$count];
|
||||
} else {
|
||||
$color = $config['graph_colours']['oranges'][$count-7];
|
||||
}
|
||||
|
||||
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":dispersion:AVERAGE ";
|
||||
$rrd_additions .= " LINE1.25:DS" . $count . "#" . $color . ":'" . str_pad(substr($array['peer'].' (s)',0,15),15) . "'" . $stack;
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":LAST:%7.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MIN:%7.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MAX:%7.0lf\\\l ";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rrd_additions == "") {
|
||||
// We didn't add any data points.
|
||||
} else {
|
||||
$rrd_options .= $rrd_additions;
|
||||
}
|
53
html/includes/graphs/device/cisco-ntp_offset.inc.php
Normal file
53
html/includes/graphs/device/cisco-ntp_offset.inc.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
include "includes/graphs/common.inc.php";
|
||||
$rrd_options .= " -l 0 -E ";
|
||||
$rrd_options .= " COMMENT:'Offset Now Min Max\\n'";
|
||||
$rrd_additions = "";
|
||||
|
||||
$count = 0;
|
||||
foreach ($components as $id => $array) {
|
||||
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("ntp-".$array['peer'].".rrd");
|
||||
|
||||
if (file_exists($rrd_filename)) {
|
||||
// Grab a color from the array.
|
||||
if ( isset($config['graph_colours']['mixed'][$count]) ) {
|
||||
$color = $config['graph_colours']['mixed'][$count];
|
||||
} else {
|
||||
$color = $config['graph_colours']['oranges'][$count-7];
|
||||
}
|
||||
|
||||
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":offset:AVERAGE ";
|
||||
$rrd_additions .= " LINE1.25:DS" . $count . "#" . $color . ":'" . str_pad(substr($array['peer'].' (s)',0,15),15) . "'" . $stack;
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":LAST:%4.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MIN:%4.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MAX:%4.0lf\\\l ";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rrd_additions == "") {
|
||||
// We didn't add any data points.
|
||||
} else {
|
||||
$rrd_options .= $rrd_additions;
|
||||
}
|
53
html/includes/graphs/device/cisco-ntp_stratum.inc.php
Normal file
53
html/includes/graphs/device/cisco-ntp_stratum.inc.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
include "includes/graphs/common.inc.php";
|
||||
$rrd_options .= " -l 0 -E ";
|
||||
$rrd_options .= " COMMENT:'Stratum Now Min Max\\n'";
|
||||
$rrd_additions = "";
|
||||
|
||||
$count = 0;
|
||||
foreach ($components as $id => $array) {
|
||||
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("ntp-".$array['peer'].".rrd");
|
||||
|
||||
if (file_exists($rrd_filename)) {
|
||||
// Grab a color from the array.
|
||||
if ( isset($config['graph_colours']['mixed'][$count]) ) {
|
||||
$color = $config['graph_colours']['mixed'][$count];
|
||||
} else {
|
||||
$color = $config['graph_colours']['oranges'][$count-7];
|
||||
}
|
||||
|
||||
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":stratum:AVERAGE ";
|
||||
$rrd_additions .= " LINE1.25:DS" . $count . "#" . $color . ":'" . str_pad(substr($array['peer'],0,15),15) . "'" . $stack;
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":LAST:%2.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MIN:%2.0lf ";
|
||||
$rrd_additions .= " GPRINT:DS" . $count . ":MAX:%2.0lf\\\l ";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rrd_additions == "") {
|
||||
// We didn't add any data points.
|
||||
} else {
|
||||
$rrd_options .= $rrd_additions;
|
||||
}
|
167
html/pages/apps/cisco-ntp.inc.php
Normal file
167
html/pages/apps/cisco-ntp.inc.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['ignore'] = array('=',0);
|
||||
$options['type'] = 'Cisco-NTP';
|
||||
$components = $component->getComponents(null,$options);
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
$view_options = array(
|
||||
'all' => 'All',
|
||||
'error' => 'Error',
|
||||
);
|
||||
if (!$vars['view']) {
|
||||
$vars['view'] = 'all';
|
||||
}
|
||||
|
||||
$graph_options = array(
|
||||
'none' => 'No Graphs',
|
||||
'stratum' => 'Stratum',
|
||||
'offset' => 'Offset',
|
||||
'delay' => 'Delay',
|
||||
'dispersion' => 'Dispersion',
|
||||
);
|
||||
if (!$vars['graph']) {
|
||||
$vars['graph'] = 'none';
|
||||
}
|
||||
|
||||
echo '<span style="font-weight: bold;">NTP Peers</span> » ';
|
||||
|
||||
// The menu option - on the left
|
||||
$sep = '';
|
||||
foreach ($view_options as $option => $text) {
|
||||
if (empty($vars['view'])) {
|
||||
$vars['view'] = $option;
|
||||
}
|
||||
echo $sep;
|
||||
if ($vars['view'] == $option) {
|
||||
echo "<span class='pagemenu-selected'>";
|
||||
}
|
||||
echo generate_link($text, $vars, array('view' => $option));
|
||||
if ($vars['view'] == $option) {
|
||||
echo '</span>';
|
||||
}
|
||||
$sep = ' | ';
|
||||
}
|
||||
|
||||
// The status option - on the right
|
||||
echo '<div class="pull-right">';
|
||||
$sep = '';
|
||||
foreach ($graph_options as $option => $text) {
|
||||
if (empty($vars['graph'])) {
|
||||
$vars['graph'] = $option;
|
||||
}
|
||||
echo $sep;
|
||||
if ($vars['graph'] == $option) {
|
||||
echo "<span class='pagemenu-selected'>";
|
||||
}
|
||||
|
||||
echo generate_link($text, $vars, array('graph' => $option));
|
||||
if ($vars['graph'] == $option) {
|
||||
echo '</span>';
|
||||
}
|
||||
$sep = ' | ';
|
||||
}
|
||||
unset($sep);
|
||||
echo '</div>';
|
||||
print_optionbar_end();
|
||||
|
||||
?>
|
||||
<table id='table' class='table table-condensed table-responsive table-striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Device</th>
|
||||
<th>Peer</th>
|
||||
<th>Stratum</th>
|
||||
<th>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' => 'cisco-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_cisco-ntp_stratum';
|
||||
} elseif ($vars['graph'] == "offset") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_offset';
|
||||
} elseif ($vars['graph'] == "delay") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_delay';
|
||||
} elseif ($vars['graph'] == "dispersion") {
|
||||
$graph_array['type'] = 'device_cisco-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>
|
129
html/pages/device/apps/cisco-ntp.inc.php
Normal file
129
html/pages/device/apps/cisco-ntp.inc.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['ignore'] = array('=',0);
|
||||
$options['type'] = 'Cisco-NTP';
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
global $config;
|
||||
?>
|
||||
<table id='table' class='table table-condensed table-responsive table-striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Peer</th>
|
||||
<th>Stratum</th>
|
||||
<th>Peer Reference</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php
|
||||
foreach ($components as $peer) {
|
||||
$string = $peer['peer'].":".$peer['port'];
|
||||
if ($peer['status'] == 2) {
|
||||
$status = $peer['error'];
|
||||
$error = 'class="danger"';
|
||||
} else {
|
||||
$status = 'Ok';
|
||||
$error = '';
|
||||
}
|
||||
?>
|
||||
<tr <?php echo $error; ?>>
|
||||
<td><?php echo $string; ?></td>
|
||||
<td><?php echo $peer['stratum']; ?></td>
|
||||
<td><?php echo $peer['peerref']; ?></td>
|
||||
<td><?php echo $status; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<div class="panel panel-default" id="stratum">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">NTP Stratum</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_stratum';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default" id="offset">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Offset</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_offset';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default" id="delay">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Delay</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_delay';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default" id="dispersion">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Dispersion</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_dispersion';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
@ -715,6 +715,7 @@ $config['poller_modules']['cisco-voice'] = 1;
|
||||
$config['poller_modules']['cisco-cbqos'] = 1;
|
||||
$config['poller_modules']['stp'] = 1;
|
||||
$config['poller_modules']['cisco-otv'] = 1;
|
||||
$config['poller_modules']['cisco-ntp'] = 1;
|
||||
$config['poller_modules']['services'] = 1;
|
||||
|
||||
// List of discovery modules. Need to be in this array to be
|
||||
@ -752,6 +753,7 @@ $config['discovery_modules']['charge'] = 1;
|
||||
$config['discovery_modules']['cisco-cbqos'] = 0;
|
||||
$config['discovery_modules']['stp'] = 1;
|
||||
$config['discovery_modules']['cisco-otv'] = 1;
|
||||
$config['discovery_modules']['cisco-ntp'] = 1;
|
||||
|
||||
$config['modules_compat']['rfc1628']['liebert'] = 1;
|
||||
$config['modules_compat']['rfc1628']['netmanplus'] = 1;
|
||||
|
135
includes/discovery/cisco-ntp.inc.php
Normal file
135
includes/discovery/cisco-ntp.inc.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
|
||||
$module = 'Cisco-NTP';
|
||||
|
||||
require_once 'includes/component.php';
|
||||
$component = new component();
|
||||
$components = $component->getComponents($device['device_id'],array('type'=>$module));
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
// Begin our master array, all other values will be processed into this array.
|
||||
$tblComponents = array();
|
||||
|
||||
// Let's gather some data..
|
||||
// For Reference:
|
||||
// http://www.oidview.com/mibs/9/CISCO-NTP-MIB.html
|
||||
// http://www.cisco.com/c/en/us/support/docs/availability/high-availability/19643-ntpm.html
|
||||
$cntpPeersVarEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.168.1.2.1.1', 2);
|
||||
|
||||
/*
|
||||
* False == no object found - this is not an error, no objects exist
|
||||
* null == timeout or something else that caused an error, there may be objects but we couldn't get it.
|
||||
*/
|
||||
if ( is_null($cntpPeersVarEntry) ) {
|
||||
// We have to error here or we will end up deleting all our components.
|
||||
echo "Error\n";
|
||||
} else {
|
||||
// No Error, lets process things.
|
||||
d_echo("Objects Found:\n");
|
||||
|
||||
// Let's grab the index for each NTP peer
|
||||
foreach ($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][2] as $index => $value) {
|
||||
$result = array();
|
||||
$result['UID'] = (string)$index; // This is cast as a string so it can be compared with the database value.
|
||||
$result['peer'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][3][$index];
|
||||
$result['port'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][4][$index];
|
||||
$result['stratum'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][9][$index];
|
||||
$result['peerref'] = hex_to_ip($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][15][$index]);
|
||||
$result['label'] = $result['peer'].":".$result['port'];
|
||||
|
||||
// Set the status, 16 = Bad
|
||||
if ($result['stratum'] == 16) {
|
||||
$result['status'] = 2;
|
||||
$result['error'] = 'NTP Stratum is Insane';
|
||||
} else {
|
||||
$result['status'] = 0;
|
||||
$result['error'] = '';
|
||||
}
|
||||
|
||||
d_echo("NTP Peer found: ");
|
||||
d_echo($result);
|
||||
$tblComponents[] = $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ok, we have our 2 array's (Components and SNMP) now we need
|
||||
* to compare and see what needs to be added/updated.
|
||||
*
|
||||
* Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
|
||||
*/
|
||||
foreach ($tblComponents as $key => $array) {
|
||||
$component_key = false;
|
||||
|
||||
// Loop over our components to determine if the component exists, or we need to add it.
|
||||
foreach ($components as $compid => $child) {
|
||||
if ($child['UID'] === $array['UID']) {
|
||||
$component_key = $compid;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$component_key) {
|
||||
// The component doesn't exist, we need to ADD it - ADD.
|
||||
$new_component = $component->createComponent($device['device_id'],$module);
|
||||
$component_key = key($new_component);
|
||||
$components[$component_key] = array_merge($new_component[$component_key], $array);
|
||||
echo "+";
|
||||
} else {
|
||||
// The component does exist, merge the details in - UPDATE.
|
||||
$components[$component_key] = array_merge($components[$component_key], $array);
|
||||
echo ".";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop over the Component data to see if we need to DELETE any components.
|
||||
*/
|
||||
foreach ($components as $key => $array) {
|
||||
// Guilty until proven innocent
|
||||
$found = false;
|
||||
|
||||
foreach ($tblComponents as $k => $v) {
|
||||
if ($array['UID'] == $v['UID']) {
|
||||
// Yay, we found it...
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found === false) {
|
||||
// The component has not been found. we should delete it.
|
||||
echo "-";
|
||||
$component->deleteComponent($key);
|
||||
}
|
||||
}
|
||||
|
||||
// Write the Components back to the DB.
|
||||
$component->setComponentPrefs($device['device_id'],$components);
|
||||
echo "\n";
|
||||
|
||||
} // End if not error
|
||||
|
||||
$module = strtolower($module);
|
||||
if (count($components) > 0) {
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $module)) == '0') {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'app_type' => $module), 'applications');
|
||||
}
|
||||
} else {
|
||||
dbDelete('applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $module));
|
||||
}
|
||||
|
||||
}
|
82
includes/polling/cisco-ntp.inc.php
Normal file
82
includes/polling/cisco-ntp.inc.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if ($device['os_group'] == "cisco") {
|
||||
|
||||
$module = 'Cisco-NTP';
|
||||
|
||||
require_once 'includes/component.php';
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=',$module);
|
||||
$options['filter']['disabled'] = array('=',0);
|
||||
$options['filter']['ignore'] = array('=',0);
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
// Only collect SNMP data if we have enabled components
|
||||
if (count($components > 0)) {
|
||||
// Let's gather the stats..
|
||||
$cntpPeersVarEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.168.1.2.1.1', 2);
|
||||
|
||||
// Loop through the components and extract the data.
|
||||
foreach ($components as $key => &$array) {
|
||||
|
||||
// Let's make sure the rrd is setup for this class.
|
||||
$filename = "ntp-".$array['peer'].".rrd";
|
||||
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename);
|
||||
|
||||
if (!file_exists ($rrd_filename)) {
|
||||
rrdtool_create ($rrd_filename, " DS:stratum:GAUGE:600:0:U DS:offset:GAUGE:600:0:U DS:delay:GAUGE:600:0:U DS:dispersion:GAUGE:600:0:U" . $config['rrd_rra']);
|
||||
}
|
||||
|
||||
$array['stratum'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][9][$array['UID']];
|
||||
// Set the status, 16 = Bad
|
||||
if ($array['stratum'] == 16) {
|
||||
$array['status'] = 2;
|
||||
$array['error'] = 'NTP Stratum is Insane';
|
||||
} else {
|
||||
$array['status'] = 0;
|
||||
$array['error'] = '';
|
||||
}
|
||||
|
||||
// Extract the statistics and update rrd
|
||||
$rrd['stratum'] = $array['stratum'];
|
||||
$rrd['offset'] = hexdec($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][23][$array['UID']]);
|
||||
$rrd['delay'] = hexdec($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][24][$array['UID']]);
|
||||
$rrd['dispersion'] = hexdec($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][25][$array['UID']]);
|
||||
rrdtool_update ($rrd_filename, $rrd);
|
||||
|
||||
// Let's print some debugging info.
|
||||
d_echo("\n\nComponent: ".$key."\n");
|
||||
d_echo(" Index: ".$array['UID']."\n");
|
||||
d_echo(" Peer: ".$array['peer'].":".$array['port']."\n");
|
||||
d_echo(" Stratum: 1.3.6.1.4.1.9.9.168.1.2.1.1.9.".$array['UID']." = ".$rrd['stratum']."\n");
|
||||
d_echo(" Offset: 1.3.6.1.4.1.9.9.168.1.2.1.1.23.".$array['UID']." = ".$rrd['offset']."\n");
|
||||
d_echo(" Delay: 1.3.6.1.4.1.9.9.168.1.2.1.1.24.".$array['UID']." = ".$rrd['delay']."\n");
|
||||
d_echo(" Dispersion: 1.3.6.1.4.1.9.9.168.1.2.1.1.25.".$array['UID']." = ".$rrd['dispersion']."\n");
|
||||
|
||||
// Clean-up after yourself!
|
||||
unset($filename, $rrd_filename, $rrd);
|
||||
} // End foreach components
|
||||
|
||||
// Write the Components back to the DB.
|
||||
$component->setComponentPrefs($device['device_id'],$components);
|
||||
|
||||
} // end if count components
|
||||
|
||||
// Clean-up after yourself!
|
||||
unset($type, $components, $component, $options, $module);
|
||||
}
|
Reference in New Issue
Block a user