From 821a797ac90602fd03290b7879c17bdf0933af65 Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 16 Dec 2015 20:56:58 +0000 Subject: [PATCH] Moved system polling module to core to centralise some snmpget calls --- doc/Support/Poller Support.md | 1 - includes/defaults.inc.php | 1 - includes/polling/core.inc.php | 124 +++++++++++++++++ includes/polling/functions.inc.php | 3 + includes/polling/os/avaya-ers.inc.php | 4 +- includes/polling/os/datacom.inc.php | 2 +- includes/polling/os/dlink.inc.php | 2 +- includes/polling/os/engenius.inc.php | 4 +- includes/polling/os/ibmnos.inc.php | 2 +- includes/polling/os/infinity.inc.php | 2 +- includes/polling/os/merakimr.inc.php | 2 +- includes/polling/os/merakims.inc.php | 2 +- includes/polling/os/merakimx.inc.php | 2 +- includes/polling/os/pbn.inc.php | 2 +- includes/polling/os/pulse.inc.php | 2 +- includes/polling/os/vyatta.inc.php | 2 +- .../polling/processors/powerconnect.inc.php | 2 +- includes/polling/system.inc.php | 125 ------------------ 18 files changed, 142 insertions(+), 142 deletions(-) create mode 100644 includes/polling/core.inc.php diff --git a/doc/Support/Poller Support.md b/doc/Support/Poller Support.md index 616698630..ad99c4219 100644 --- a/doc/Support/Poller Support.md +++ b/doc/Support/Poller Support.md @@ -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; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 407402746..7e820d111 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -662,7 +662,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; diff --git a/includes/polling/core.inc.php b/includes/polling/core.inc.php new file mode 100644 index 000000000..b7d3af08b --- /dev/null +++ b/includes/polling/core.inc.php @@ -0,0 +1,124 @@ + $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); + + $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); +} diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 72332250e..501c8dd78 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -201,6 +201,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')) { diff --git a/includes/polling/os/avaya-ers.inc.php b/includes/polling/os/avaya-ers.inc.php index 163c82c18..97afaab5b 100644 --- a/includes/polling/os/avaya-ers.inc.php +++ b/includes/polling/os/avaya-ers.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); diff --git a/includes/polling/os/datacom.inc.php b/includes/polling/os/datacom.inc.php index 9d2d5aea3..ebf0bf538 100644 --- a/includes/polling/os/datacom.inc.php +++ b/includes/polling/os/datacom.inc.php @@ -1,5 +1,5 @@ $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); - - $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); -}