mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #2637 from laf/snmp-perf
Moved system polling module to core to centralise some snmpget calls
This commit is contained in:
@@ -39,7 +39,6 @@ disable it for one device then you can do this within the WebUI -> Settings -> M
|
||||
|
||||
```php
|
||||
$config['poller_modules']['unix-agent'] = 0;
|
||||
$config['poller_modules']['system'] = 1;
|
||||
$config['poller_modules']['os'] = 1;
|
||||
$config['poller_modules']['ipmi'] = 1;
|
||||
$config['poller_modules']['sensors'] = 1;
|
||||
|
@@ -675,7 +675,6 @@ $config['warn']['ifdown'] = true;
|
||||
// List of poller modules. Need to be in the array to be
|
||||
// considered for execution.
|
||||
$config['poller_modules']['unix-agent'] = 0;
|
||||
$config['poller_modules']['system'] = 1;
|
||||
$config['poller_modules']['os'] = 1;
|
||||
$config['poller_modules']['ipmi'] = 1;
|
||||
$config['poller_modules']['sensors'] = 1;
|
||||
|
129
includes/polling/core.inc.php
Normal file
129
includes/polling/core.inc.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Observium Network Management and Monitoring System
|
||||
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* See COPYING for more details.
|
||||
*/
|
||||
|
||||
unset($poll_device);
|
||||
|
||||
$snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysDescr.0 sysObjectID.0 snmpEngineTime.0 hrSystemUptime.0', '-OQnUs', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
|
||||
$poll_device = $snmpdata[0];
|
||||
$poll_device['sysName'] = strtolower($poll_device['sysName']);
|
||||
|
||||
if (!empty($agent_data['uptime'])) {
|
||||
list($uptime) = explode(' ', $agent_data['uptime']);
|
||||
$uptime = round($uptime);
|
||||
echo "Using UNIX Agent Uptime ($uptime)\n";
|
||||
}
|
||||
|
||||
if (empty($uptime)) {
|
||||
$snmp_uptime = (integer) $poll_device['snmpEngineTime'];
|
||||
$hrSystemUptime = $poll_device['hrSystemUptime'];
|
||||
if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && ($device['os'] != 'windows')) {
|
||||
echo 'Using hrSystemUptime ('.$hrSystemUptime.")\n";
|
||||
$agent_uptime = $uptime;
|
||||
// Move uptime into agent_uptime
|
||||
// HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65
|
||||
$hrSystemUptime = str_replace('(', '', $hrSystemUptime);
|
||||
$hrSystemUptime = str_replace(')', '', $hrSystemUptime);
|
||||
list($days,$hours, $mins, $secs) = explode(':', $hrSystemUptime);
|
||||
list($secs, $microsecs) = explode('.', $secs);
|
||||
$hours = ($hours + ($days * 24));
|
||||
$mins = ($mins + ($hours * 60));
|
||||
$secs = ($secs + ($mins * 60));
|
||||
$uptime = $secs;
|
||||
}
|
||||
else {
|
||||
echo 'Using SNMP Agent Uptime ('.$poll_device['sysUpTime'].")\n";
|
||||
// SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31
|
||||
$poll_device['sysUpTime'] = str_replace('(', '', $poll_device['sysUpTime']);
|
||||
$poll_device['sysUpTime'] = str_replace(')', '', $poll_device['sysUpTime']);
|
||||
list($days, $hours, $mins, $secs) = explode(':', $poll_device['sysUpTime']);
|
||||
list($secs, $microsecs) = explode('.', $secs);
|
||||
$hours = ($hours + ($days * 24));
|
||||
$mins = ($mins + ($hours * 60));
|
||||
$secs = ($secs + ($mins * 60));
|
||||
$uptime = $secs;
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
if ($snmp_uptime > $uptime && is_numeric($snmp_uptime)) {
|
||||
$uptime = $snmp_uptime;
|
||||
d_echo('hrSystemUptime or sysUpTime looks like to have rolled, using snmpEngineTime instead');
|
||||
}
|
||||
|
||||
if (is_numeric($uptime)) {
|
||||
if ($uptime < $device['uptime']) {
|
||||
log_event('Device rebooted after '.formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
|
||||
}
|
||||
|
||||
$uptime_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/uptime.rrd';
|
||||
|
||||
if (!is_file($uptime_rrd)) {
|
||||
rrdtool_create($uptime_rrd, 'DS:uptime:GAUGE:600:0:U '.$config['rrd_rra']);
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'uptime' => $uptime,
|
||||
);
|
||||
|
||||
rrdtool_update($uptime_rrd, $fields);
|
||||
|
||||
$measurement = 'uptime';
|
||||
$tags = array();
|
||||
|
||||
influx_update($device,$measurement,$tags,$fields);
|
||||
|
||||
$graphs['uptime'] = true;
|
||||
|
||||
echo 'Uptime: '.formatUptime($uptime)."\n";
|
||||
|
||||
$update_array['uptime'] = $uptime;
|
||||
}//end if
|
||||
|
||||
$poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
|
||||
|
||||
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
|
||||
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\');
|
||||
|
||||
// Rewrite sysLocation if there is a mapping array (database too?)
|
||||
if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) {
|
||||
$poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
|
||||
}
|
||||
|
||||
$poll_device['sysContact'] = str_replace('"', '', $poll_device['sysContact']);
|
||||
|
||||
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
|
||||
$poll_device['sysContact'] = trim($poll_device['sysContact'], '\\');
|
||||
|
||||
|
||||
foreach (array('sysLocation', 'sysContact') as $elem) {
|
||||
if ($poll_device[$elem] == 'not set') {
|
||||
$poll_device[$elem] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Save results of various polled values to the database
|
||||
foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) {
|
||||
if ($poll_device[$elem] && $poll_device[$elem] != $device[$elem]) {
|
||||
$update_array[$elem] = $poll_device[$elem];
|
||||
log_event("$elem -> ".$poll_device[$elem], $device, 'system');
|
||||
}
|
||||
}
|
||||
|
||||
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] && $device['override_sysLocation'] == 0) {
|
||||
$update_array['location'] = $poll_device['sysLocation'];
|
||||
log_event('Location -> '.$poll_device['sysLocation'], $device, 'system');
|
||||
}
|
||||
|
||||
if ($config['geoloc']['latlng'] === true) {
|
||||
location_to_latlng($device);
|
||||
}
|
@@ -204,6 +204,9 @@ function poll_device($device, $options) {
|
||||
$graphs = array();
|
||||
$oldgraphs = array();
|
||||
|
||||
// we always want the core module to be included
|
||||
include 'includes/polling/core.inc.php';
|
||||
|
||||
if ($options['m']) {
|
||||
foreach (explode(',', $options['m']) as $module) {
|
||||
if (is_file('includes/polling/'.$module.'.inc.php')) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
echo 'Doing Nortel/Avaya ERS ';
|
||||
|
||||
$sysObjectID = snmp_get($device, 'sysObjectID.0', '-Oqvn');
|
||||
$sysObjectID = $poll_device['sysObjectID'];
|
||||
|
||||
// Try multiple ways of getting firmware version
|
||||
$version = snmp_get($device, 'SNMPv2-SMI::enterprises.2272.1.1.7.0', '-Oqvn');
|
||||
@@ -17,7 +17,7 @@ if ($version == '') {
|
||||
}
|
||||
|
||||
// Get hardware details
|
||||
$sysDescr = snmp_get($device, 'SNMPv2-MIB::sysDescr.0', '-Oqvn');
|
||||
$sysDescr = $poll_device['sysDescr'];
|
||||
|
||||
$details = explode(' ', $sysDescr);
|
||||
$details = str_replace('ERS-', 'Ethernet Routing Switch ', $details);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
$hardware = 'Datacom '.str_replace('dmSwitch', 'DM', snmp_get($device, 'swChassisModel.0', '-Ovq', 'DMswitch-MIB'));
|
||||
$version = snmp_get($device, 'swFirmwareVer.1', '-Ovq', 'DMswitch-MIB');
|
||||
$features = snmp_get($device, 'sysDescr.0', '-Oqv', 'SNMPv2-MIB');
|
||||
$features = $poll_device['sysDescr'];
|
||||
$serial = snmp_get($device, 'DMswitch-MIB::swSerialNumber.1', '-Ovq', 'DMswitch-MIB');
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$Descr_string = snmp_get($device, 'sysDescr.0', '-Oqv', 'SNMPv2-MIB');
|
||||
$Descr_string = $poll_device['sysDescr'];
|
||||
$Descr_chopper = preg_split('/[ ]+/', "$Descr_string");
|
||||
|
||||
$version = 'Firmware '.$Descr_chopper[1];
|
||||
|
@@ -14,10 +14,10 @@ $serial = trim(snmp_get($device, "1.3.6.1.4.1.14125.100.1.7.0", "-OQv"),'" ');
|
||||
# There doesn't seem to be a real hardware identification.. sysName will have to do?
|
||||
$hw_response = snmp_get($device, "1.3.6.1.4.1.14125.100.1.6.0", "-OQv");
|
||||
if(!empty($hw_response)) {
|
||||
$hardware = str_replace("EnGenius ","",snmp_get($device,"sysName.0", "-OQv")) . " v" . trim(snmp_get($device, "1.3.6.1.4.1.14125.100.1.6.0", "-OQv"),'" .');
|
||||
$hardware = str_replace("EnGenius ","",$poll_device['sysName']) . " v" . trim(snmp_get($device, "1.3.6.1.4.1.14125.100.1.6.0", "-OQv"),'" .');
|
||||
}
|
||||
else {
|
||||
$hardware = snmp_get($device,"sysName.0", "-OQv") . trim(snmp_get($device, "1.3.6.1.4.1.14125.3.1.1.5.0", "-OQv"),'" .');
|
||||
$hardware = $poll_device['sysName'] . trim(snmp_get($device, "1.3.6.1.4.1.14125.3.1.1.5.0", "-OQv"),'" .');
|
||||
}
|
||||
|
||||
$mode = snmp_get($device, "1.3.6.1.4.1.14125.100.1.4.0", "-OQv");
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
$sysdescr_value = snmp_get($device, 'sysDescr.0', '-Ovq');
|
||||
$sysdescr_value = $poll_device['sysDescr'];
|
||||
if (strpos($sysdescr_value, 'IBM Networking Operating System') !== false) {
|
||||
$hardware = str_replace('IBM Networking Operating System', '', $sysdescr_value);
|
||||
if (strpos($sysdescr_value, 'G8052') !== false) {
|
||||
|
@@ -10,6 +10,6 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$version = snmp_get($device, 'SNMPv2-MIB::sysDescr.0', '-Ovq');
|
||||
$version = $poll_device['sysDescr'];
|
||||
$version = explode(' ', $version)[2];
|
||||
$hardware = snmp_get($device, 'IEEE802dot11-MIB::dot11manufacturerProductName.5', '-Ovq');
|
||||
|
@@ -11,5 +11,5 @@
|
||||
*/
|
||||
|
||||
if (empty($hardware)) {
|
||||
$hardware = snmp_get($device, 'sysDescr.0', '-Osqv', 'SNMPv2-MIB');
|
||||
$hardware = $poll_device['sysDescr'];
|
||||
}
|
||||
|
@@ -11,5 +11,5 @@
|
||||
*/
|
||||
|
||||
if (empty($hardware)) {
|
||||
$hardware = snmp_get($device, 'sysDescr.0', '-Osqv', 'SNMPv2-MIB');
|
||||
$hardware = $poll_device['sysDescr'];
|
||||
}
|
||||
|
@@ -11,5 +11,5 @@
|
||||
*/
|
||||
|
||||
if (empty($hardware)) {
|
||||
$hardware = snmp_get($device, 'sysDescr.0', '-Osqv', 'SNMPv2-MIB');
|
||||
$hardware = $poll_device['sysDescr'];
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ if (preg_match('/^Pacific Broadband Networks .+\n.+ Version ([^,]+), .+\n.+\n.+\
|
||||
|
||||
// for PBN CPE 120/121
|
||||
}
|
||||
else if (strstr(snmp_get($device, 'SNMPv2-MIB::sysObjectID.0', '-Ovqn'), '.1.3.6.1.4.1.11606.24.1.1.10')) {
|
||||
else if (strstr($poll_device['sysObjectID'], '.1.3.6.1.4.1.11606.24.1.1.10')) {
|
||||
$version = str_replace(array('"'), '', snmp_get($device, '1.3.6.1.4.1.11606.24.1.1.6.0', '-Ovq'));
|
||||
$hardware = str_replace(array('"'), '', snmp_get($device, '1.3.6.1.4.1.11606.24.1.1.7.0', '-Ovq'));
|
||||
$features = str_replace(array('"'), '', snmp_get($device, '1.3.6.1.4.1.11606.24.1.1.10.0', '-Ovq'));
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
$version = trim(snmp_get($device, "productVersion.0", "-OQv", "PULSESECURE-PSG-MIB"),'"');
|
||||
$hardware = "Juniper " . trim(snmp_get($device, "productName.0", "-OQv", "PULSESECURE-PSG-MIB"),'"');
|
||||
$hostname = trim(snmp_get($device, "sysName.0", "-OQv", "SNMPv2-MIB"),'"');
|
||||
$hostname = trim($poll_device['sysName'],'"');
|
||||
|
||||
$usersrrd = $config['rrd_dir'].'/'.$device['hostname'].'/pulse_users.rrd';
|
||||
$users = snmp_get($device, 'PULSESECURE-PSG-MIB::iveConcurrentUsers.0', '-OQv');
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<?php
|
||||
|
||||
list($features, $version) = explode('-', trim(str_replace('Vyatta', '', snmp_get($device, 'SNMPv2-MIB::sysDescr.0', '-Oqv', 'SNMPv2-MIB'))), 2);
|
||||
list($features, $version) = explode('-', trim(str_replace('Vyatta', '', $poll_device['sysDescr'])), 2);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
$sysObjectId = snmp_get($device, 'SNMPv2-MIB::sysObjectID.0', '-Ovqn');
|
||||
$sysObjectId = $poll_device['sysObjectID'];
|
||||
switch ($sysObjectId) {
|
||||
case '.1.3.6.1.4.1.674.10895.3031':
|
||||
/*
|
||||
|
@@ -1,132 +1,2 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Observium Network Management and Monitoring System
|
||||
* Copyright (C) 2006-2011, Observium Developers - http://www.observium.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* See COPYING for more details.
|
||||
*/
|
||||
|
||||
unset($poll_device);
|
||||
|
||||
$snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0', '-OQUs', 'SNMPv2-MIB');
|
||||
$poll_device = $snmpdata[0];
|
||||
|
||||
$poll_device['sysDescr'] = snmp_get($device, 'sysDescr.0', '-Oqv', 'SNMPv2-MIB');
|
||||
$poll_device['sysObjectID'] = snmp_get($device, 'sysObjectID.0', '-Oqvn', 'SNMPv2-MIB');
|
||||
$poll_device['sysName'] = strtolower($poll_device['sysName']);
|
||||
|
||||
if (!empty($agent_data['uptime'])) {
|
||||
list($uptime) = explode(' ', $agent_data['uptime']);
|
||||
$uptime = round($uptime);
|
||||
echo "Using UNIX Agent Uptime ($uptime)\n";
|
||||
}
|
||||
|
||||
if (empty($uptime)) {
|
||||
$snmp_uptime = (integer) snmp_get($device, 'snmpEngineTime.0', '-OUqv', 'SNMP-FRAMEWORK-MIB');
|
||||
$hrSystemUptime = snmp_get($device, 'hrSystemUptime.0', '-Oqv', 'HOST-RESOURCES-MIB');
|
||||
if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && ($device['os'] != 'windows')) {
|
||||
echo 'Using hrSystemUptime ('.$hrSystemUptime.")\n";
|
||||
$agent_uptime = $uptime;
|
||||
// Move uptime into agent_uptime
|
||||
// HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65
|
||||
$hrSystemUptime = str_replace('(', '', $hrSystemUptime);
|
||||
$hrSystemUptime = str_replace(')', '', $hrSystemUptime);
|
||||
list($days,$hours, $mins, $secs) = explode(':', $hrSystemUptime);
|
||||
list($secs, $microsecs) = explode('.', $secs);
|
||||
$hours = ($hours + ($days * 24));
|
||||
$mins = ($mins + ($hours * 60));
|
||||
$secs = ($secs + ($mins * 60));
|
||||
$uptime = $secs;
|
||||
}
|
||||
else {
|
||||
echo 'Using SNMP Agent Uptime ('.$poll_device['sysUpTime'].")\n";
|
||||
// SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31
|
||||
$poll_device['sysUpTime'] = str_replace('(', '', $poll_device['sysUpTime']);
|
||||
$poll_device['sysUpTime'] = str_replace(')', '', $poll_device['sysUpTime']);
|
||||
list($days, $hours, $mins, $secs) = explode(':', $poll_device['sysUpTime']);
|
||||
list($secs, $microsecs) = explode('.', $secs);
|
||||
$hours = ($hours + ($days * 24));
|
||||
$mins = ($mins + ($hours * 60));
|
||||
$secs = ($secs + ($mins * 60));
|
||||
$uptime = $secs;
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
if ($snmp_uptime > $uptime && is_numeric($snmp_uptime)) {
|
||||
$uptime = $snmp_uptime;
|
||||
d_echo('hrSystemUptime or sysUpTime looks like to have rolled, using snmpEngineTime instead');
|
||||
}
|
||||
|
||||
if (is_numeric($uptime)) {
|
||||
if ($uptime < $device['uptime']) {
|
||||
log_event('Device rebooted after '.formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
|
||||
}
|
||||
|
||||
$uptime_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/uptime.rrd';
|
||||
|
||||
if (!is_file($uptime_rrd)) {
|
||||
rrdtool_create($uptime_rrd, 'DS:uptime:GAUGE:600:0:U '.$config['rrd_rra']);
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'uptime' => $uptime,
|
||||
);
|
||||
|
||||
rrdtool_update($uptime_rrd, $fields);
|
||||
|
||||
$measurement = 'uptime';
|
||||
$tags = array();
|
||||
|
||||
influx_update($device,$measurement,$tags,$fields);
|
||||
|
||||
$graphs['uptime'] = true;
|
||||
|
||||
echo 'Uptime: '.formatUptime($uptime)."\n";
|
||||
|
||||
$update_array['uptime'] = $uptime;
|
||||
}//end if
|
||||
|
||||
$poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
|
||||
|
||||
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
|
||||
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\');
|
||||
|
||||
// Rewrite sysLocation if there is a mapping array (database too?)
|
||||
if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) {
|
||||
$poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
|
||||
}
|
||||
|
||||
$poll_device['sysContact'] = str_replace('"', '', $poll_device['sysContact']);
|
||||
|
||||
// Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
|
||||
$poll_device['sysContact'] = trim($poll_device['sysContact'], '\\');
|
||||
|
||||
|
||||
foreach (array('sysLocation', 'sysContact') as $elem) {
|
||||
if ($poll_device[$elem] == 'not set') {
|
||||
$poll_device[$elem] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Save results of various polled values to the database
|
||||
foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) {
|
||||
if ($poll_device[$elem] && $poll_device[$elem] != $device[$elem]) {
|
||||
$update_array[$elem] = $poll_device[$elem];
|
||||
log_event("$elem -> ".$poll_device[$elem], $device, 'system');
|
||||
}
|
||||
}
|
||||
|
||||
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] && $device['override_sysLocation'] == 0) {
|
||||
$update_array['location'] = $poll_device['sysLocation'];
|
||||
log_event('Location -> '.$poll_device['sysLocation'], $device, 'system');
|
||||
}
|
||||
|
||||
if ($config['geoloc']['latlng'] === true) {
|
||||
location_to_latlng($device);
|
||||
}
|
||||
|
Reference in New Issue
Block a user