Handle bad uptime input (#13899)

* Handle bad uptime input
devices returning non-numeric strings or strings with garbage would cause an exception before

* Update Core.php

* Update Core.php
This commit is contained in:
Tony Murray
2022-04-15 10:19:54 -05:00
committed by GitHub
parent 68b49a0df1
commit 4ccd6d3937

View File

@@ -32,6 +32,7 @@ use LibreNMS\Interfaces\Module;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\Compare;
use LibreNMS\Util\Number;
use LibreNMS\Util\Time;
use Log;
use SnmpQuery;
@@ -236,9 +237,9 @@ class Core implements Module
$uptime_data = SnmpQuery::make()->get(['SNMP-FRAMEWORK-MIB::snmpEngineTime.0', 'HOST-RESOURCES-MIB::hrSystemUptime.0'])->values();
$uptime = max(
round($sysUpTime / 100),
Config::get("os.$device->os.bad_snmpEngineTime") ? 0 : $uptime_data['SNMP-FRAMEWORK-MIB::snmpEngineTime.0'] ?? 0,
Config::get("os.$device->os.bad_hrSystemUptime") ? 0 : round(($uptime_data['HOST-RESOURCES-MIB::hrSystemUptime.0'] ?? 0) / 100)
round(Number::cast($sysUpTime) / 100),
Config::get("os.$device->os.bad_snmpEngineTime") ? 0 : Number::cast($uptime_data['SNMP-FRAMEWORK-MIB::snmpEngineTime.0'] ?? 0),
Config::get("os.$device->os.bad_hrSystemUptime") ? 0 : round(Number::cast($uptime_data['HOST-RESOURCES-MIB::hrSystemUptime.0'] ?? 0) / 100)
);
Log::debug("Uptime seconds: $uptime\n");
}