fix: take another crack at fixing uptime (#6705)

* fix: take another crack at fixing uptime
It looks like we weren't using sysUpTime before???
Simplify the code and just max all the time values.

* inline bad checks
This commit is contained in:
Tony Murray
2017-05-22 11:55:52 -05:00
committed by Neil Lathwood
parent db3a0c2623
commit c728e4b0cf
2 changed files with 15 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ type: server
text: 'Microsoft Windows' text: 'Microsoft Windows'
ifname: 1 ifname: 1
processor_stacked: 1 processor_stacked: 1
bad_hrSystemUptime: true
discovery: discovery:
- sysObjectId: .1.3.6.1.4.1.311.1.1.3 - sysObjectId: .1.3.6.1.4.1.311.1.1.3
- sysDescr: Windows - sysDescr: Windows

View File

@@ -14,8 +14,6 @@
use LibreNMS\RRD\RrdDefinition; use LibreNMS\RRD\RrdDefinition;
unset($poll_device);
$snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysObjectID.0', '-OQnUst', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB'); $snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysObjectID.0', '-OQnUst', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$poll_device = $snmpdata[0]; $poll_device = $snmpdata[0];
$poll_device['sysName'] = strtolower($poll_device['sysName']); $poll_device['sysName'] = strtolower($poll_device['sysName']);
@@ -26,32 +24,20 @@ if (!empty($agent_data['uptime'])) {
list($uptime) = explode(' ', $agent_data['uptime']); list($uptime) = explode(' ', $agent_data['uptime']);
$uptime = round($uptime); $uptime = round($uptime);
echo "Using UNIX Agent Uptime ($uptime)\n"; echo "Using UNIX Agent Uptime ($uptime)\n";
} else {
$uptime_data = snmp_get_multi($device, 'snmpEngineTime.0 hrSystemUptime.0', '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$uptime = max(
round($poll_device['sysUpTime'] / 100),
$config['os'][$device['os']]['bad_snmpEngineTime'] ? 0 : $uptime_data[0]['snmpEngineTime'],
$config['os'][$device['os']]['bad_hrSystemUptime'] ? 0 : round($uptime_data[0]['hrSystemUptime'] / 100)
);
d_echo("Uptime seconds: $uptime\n");
} }
if (empty($uptime)) { if ($uptime != 0 && $config['os'][$device['os']]['bad_uptime'] !== true) {
$snmp_data = snmp_get_multi($device, 'snmpEngineTime.0 hrSystemUptime.0', '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$uptime_data = $snmp_data[0];
$snmp_uptime = (integer)$uptime_data['snmpEngineTime'];
$hrSystemUptime = $uptime_data['hrSystemUptime'];
if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && ($device['os'] != 'windows')) {
$uptime = floor($hrSystemUptime / 100);
echo 'Using hrSystemUptime (' . $uptime . "s)\n";
} else {
$uptime = floor($poll_device['sysUpTime'] / 100);
echo 'Using SNMP Agent Uptime (' . $uptime . "s)\n ";
}//end if
}//end if
if ($config['os'][$device['os']]['bad_snmpEngineTime'] !== true) {
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) && ($config['os'][$device['os']]['bad_uptime'] !== true)) {
if ($uptime < $device['uptime']) { if ($uptime < $device['uptime']) {
log_event('Device rebooted after ' . formatUptime($device['uptime']) . ' -> ' . $uptime, $device, 'reboot', 4, $device['uptime']); log_event('Device rebooted after ' . formatUptime($device['uptime']) . " -> {$uptime}s", $device, 'reboot', 4, $device['uptime']);
} }
$tags = array( $tags = array(
@@ -61,7 +47,7 @@ if (is_numeric($uptime) && ($config['os'][$device['os']]['bad_uptime'] !== true)
$graphs['uptime'] = true; $graphs['uptime'] = true;
echo 'Uptime: ' . formatUptime($uptime) . "\n"; echo 'Uptime: ' . formatUptime($uptime) . PHP_EOL;
$update_array['uptime'] = $uptime; $update_array['uptime'] = $uptime;
}//end if }//end if
@@ -104,3 +90,5 @@ if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocat
if ($config['geoloc']['latlng'] === true) { if ($config['geoloc']['latlng'] === true) {
location_to_latlng($device); location_to_latlng($device);
} }
unset($snmpdata, $uptime_data, $uptime, $tags);