From c0b667ebc039bc4f92f6bd51543eee326203cda4 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sat, 25 Aug 2018 15:00:03 -0500 Subject: [PATCH] Isolate poller and discovery modules (#9074) An exception in one module should not interrupt the process for other modules. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` --- includes/discovery/functions.inc.php | 11 ++++++++++- includes/polling/functions.inc.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 4a1574fe8e..48cc9310ce 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -173,7 +173,16 @@ function discover_device(&$device, $force_module = false) $module_start = microtime(true); $start_memory = memory_get_usage(); echo "\n#### Load disco module $module ####\n"; - include "includes/discovery/$module.inc.php"; + + try { + include "includes/discovery/$module.inc.php"; + } catch (Exception $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); + } + $module_time = microtime(true) - $module_start; $module_time = substr($module_time, 0, 5); $module_mem = (memory_get_usage() - $start_memory); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index dfd51c4952..63abddf26d 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -297,7 +297,16 @@ function poll_device($device, $force_module = false) $start_memory = memory_get_usage(); $module_start = microtime(true); echo "\n#### Load poller module $module ####\n"; - include "includes/polling/$module.inc.php"; + + try { + include "includes/polling/$module.inc.php"; + } catch (Exception $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); + } + $module_time = microtime(true) - $module_start; $module_mem = (memory_get_usage() - $start_memory); printf("\n>> Runtime for poller module '%s': %.4f seconds with %s bytes\n", $module, $module_time, $module_mem);