mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
- Made module generic, not cisco specific.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
* LibreNMS module to display captured NTP statistics
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$options['filter']['type'] = array('=','ntp');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
* LibreNMS module to display captured NTP statistics
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$options['filter']['type'] = array('=','ntp');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
* LibreNMS module to display captured NTP statistics
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$options['filter']['type'] = array('=','ntp');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture statistics from the CISCO-NTP-MIB
|
||||
* LibreNMS module to display captured NTP statistics
|
||||
*
|
||||
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
|
||||
*
|
||||
@@ -14,7 +14,7 @@
|
||||
require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['type'] = array('=','Cisco-NTP');
|
||||
$options['filter']['type'] = array('=','ntp');
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
|
||||
// We only care about our device id.
|
@@ -15,7 +15,7 @@ require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['ignore'] = array('=',0);
|
||||
$options['type'] = 'Cisco-NTP';
|
||||
$options['type'] = 'ntp';
|
||||
$components = $component->getComponents(null,$options);
|
||||
|
||||
print_optionbar_start();
|
||||
@@ -112,7 +112,7 @@ print_optionbar_end();
|
||||
}
|
||||
|
||||
if ($display === true) {
|
||||
$link = generate_device_link($device,null,array('tab' => 'apps', 'app' => 'cisco-ntp'));
|
||||
$link = generate_device_link($device,null,array('tab' => 'apps', 'app' => 'ntp'));
|
||||
$count++;
|
||||
?>
|
||||
<tr <?php echo $status; ?>>
|
||||
@@ -130,13 +130,13 @@ print_optionbar_end();
|
||||
|
||||
// Which graph type do we want?
|
||||
if ($vars['graph'] == "stratum") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_stratum';
|
||||
$graph_array['type'] = 'device_ntp_stratum';
|
||||
} elseif ($vars['graph'] == "offset") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_offset';
|
||||
$graph_array['type'] = 'device_ntp_offset';
|
||||
} elseif ($vars['graph'] == "delay") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_delay';
|
||||
$graph_array['type'] = 'device_ntp_delay';
|
||||
} elseif ($vars['graph'] == "dispersion") {
|
||||
$graph_array['type'] = 'device_cisco-ntp_dispersion';
|
||||
$graph_array['type'] = 'device_ntp_dispersion';
|
||||
} else {
|
||||
// No Graph
|
||||
unset($graph_array);
|
@@ -15,7 +15,7 @@ require_once "../includes/component.php";
|
||||
$component = new component();
|
||||
$options = array();
|
||||
$options['filter']['ignore'] = array('=',0);
|
||||
$options['type'] = 'Cisco-NTP';
|
||||
$options['type'] = 'ntp';
|
||||
$components = $component->getComponents($device['device_id'],$options);
|
||||
$components = $components[$device['device_id']];
|
||||
|
||||
@@ -64,7 +64,7 @@ global $config;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_stratum';
|
||||
$graph_array['type'] = 'device_ntp_stratum';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
@@ -83,7 +83,7 @@ global $config;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_offset';
|
||||
$graph_array['type'] = 'device_ntp_offset';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
@@ -102,7 +102,7 @@ global $config;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_delay';
|
||||
$graph_array['type'] = 'device_ntp_delay';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
||||
@@ -121,7 +121,7 @@ global $config;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['type'] = 'device_cisco-ntp_dispersion';
|
||||
$graph_array['type'] = 'device_ntp_dispersion';
|
||||
require 'includes/print-graphrow.inc.php';
|
||||
|
||||
?>
|
@@ -714,7 +714,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']['ntp'] = 1;
|
||||
$config['poller_modules']['services'] = 1;
|
||||
|
||||
// List of discovery modules. Need to be in this array to be
|
||||
@@ -752,7 +752,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['discovery_modules']['ntp'] = 1;
|
||||
|
||||
$config['modules_compat']['rfc1628']['liebert'] = 1;
|
||||
$config['modules_compat']['rfc1628']['netmanplus'] = 1;
|
||||
|
@@ -1,135 +0,0 @@
|
||||
<?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));
|
||||
}
|
||||
|
||||
}
|
30
includes/discovery/ntp.inc.php
Normal file
30
includes/discovery/ntp.inc.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture NTP statistics
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This module will display NTP details from various device types.
|
||||
* To display, modules must store data in for following format:
|
||||
* Array
|
||||
* (
|
||||
* [UID] => 9093
|
||||
* [peer] => 10.0.99.66
|
||||
* [port] => 123
|
||||
* [stratum] => 4
|
||||
* [peerref] => 131.242.253.96
|
||||
* [label] => 10.0.99.66:123
|
||||
* [status] => 0
|
||||
* [error] =>
|
||||
* )
|
||||
*/
|
||||
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
require_once 'includes/discovery/ntp/cisco.inc.php';
|
||||
}
|
131
includes/discovery/ntp/cisco.inc.php
Normal file
131
includes/discovery/ntp/cisco.inc.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
$module = '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));
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
<?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) {
|
||||
$peer = $array['peer'];
|
||||
|
||||
// Let's make sure the rrd is setup for this class.
|
||||
$rrd_name = array('ntp', $peer);
|
||||
$rrd_def = array(
|
||||
'DS:stratum:GAUGE:600:0:U',
|
||||
'DS:offset:GAUGE:600:0:U',
|
||||
'DS:delay:GAUGE:600:0:U',
|
||||
'DS:dispersion:GAUGE:600:0:U',
|
||||
);
|
||||
|
||||
$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']]);
|
||||
$tags = compact('ntp', 'rrd_name', 'rrd_def', 'peer');
|
||||
data_update($device, 'ntp', $tags, $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);
|
||||
}
|
23
includes/polling/ntp.inc.php
Normal file
23
includes/polling/ntp.inc.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS module to capture NTP statistics
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This module will display NTP details from various device types.
|
||||
* To display, modules must create rrd's named: ntp-%PEER%.rrd with the following DS':
|
||||
* DS:stratum:GAUGE:600:0:U
|
||||
* DS:offset:GAUGE:600:0:U
|
||||
* DS:delay:GAUGE:600:0:U
|
||||
* DS:dispersion:GAUGE:600:0:U
|
||||
*/
|
||||
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
require_once 'includes/polling/ntp/cisco.inc.php';
|
||||
}
|
82
includes/polling/ntp/cisco.inc.php
Normal file
82
includes/polling/ntp/cisco.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.
|
||||
*/
|
||||
|
||||
$module = '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) {
|
||||
$peer = $array['peer'];
|
||||
|
||||
// Let's make sure the rrd is setup for this class.
|
||||
$rrd_name = array('ntp', $peer);
|
||||
$rrd_def = array(
|
||||
'DS:stratum:GAUGE:600:0:U',
|
||||
'DS:offset:GAUGE:600:0:U',
|
||||
'DS:delay:GAUGE:600:0:U',
|
||||
'DS:dispersion:GAUGE:600:0:U',
|
||||
);
|
||||
|
||||
$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']]);
|
||||
$tags = compact('ntp', 'rrd_name', 'rrd_def', 'peer');
|
||||
data_update($device, 'ntp', $tags, $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