Disable plugins that have errors (#14383)

* Disable plugins that have errors
Disable plugin if a hook throws an error and set a notification
Move notification code to class, so we can access it
Clear notification when plugin is attempted to be enabled again

* fix style and lint fixes

* another lint fix and handle if property is missing
This commit is contained in:
Tony Murray
2022-09-25 22:47:58 -05:00
committed by GitHub
parent 333ba7c2cd
commit e990dfcb35
9 changed files with 222 additions and 197 deletions

View File

@@ -27,6 +27,7 @@
namespace LibreNMS;
use App\Models\Plugin;
use LibreNMS\Util\Notifications;
use Log;
/**
@@ -190,8 +191,14 @@ class Plugins
} else {
@call_user_func_array([$plugin, $hook], $params);
}
} catch (\Exception $e) {
} catch (\Exception|\Error $e) {
Log::error($e);
$class = (string) get_class($plugin);
$name = property_exists($class, 'name') ? $class::$name : basename(str_replace('\\', '/', $class));
Notifications::create("Plugin $name disabled", "$name caused an error and was disabled, please check with the plugin creator to fix the error. The error can be found in logs/librenms.log", 'plugins', 2);
Plugin::where('plugin_name', $name)->update(['plugin_active' => 0]);
}
}
}