Catch all module errors (#13542)

* Catch all module errors
As of PHP 7.1, we can now catch errors and exceptions by catching throwable.
Also, log the errors in a consistent way with the entire stack trace

* Log event and improve messages

* call from facade because event might not exist on logger
This commit is contained in:
Tony Murray
2021-11-23 02:52:52 -06:00
committed by GitHub
parent 69b49d0eff
commit 4a5836f64e
3 changed files with 12 additions and 11 deletions

View File

@@ -327,11 +327,10 @@ function poll_device($device, $force_module = false)
try {
include "includes/polling/$module.inc.php";
} catch (Exception $e) {
} catch (Throwable $e) {
// isolate module exceptions so they don't disrupt the polling process
echo $e->getTraceAsString() . PHP_EOL;
c_echo("%rError in $module module.%n " . $e->getMessage() . PHP_EOL);
logfile("Error in $module module. " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
Log::error("%rError polling $module module for {$device['hostname']}.%n " . $e->getMessage() . PHP_EOL . $e->getTraceAsString(), ['color' => true]);
Log::event("Error polling $module module. Check log file for more details.", $device['device_id'], 'poller', Alert::ERROR);
}
$module_time = microtime(true) - $module_start;