mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -30,6 +30,7 @@ use App\Models\Plugin;
|
||||
use Exception;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Collection;
|
||||
use LibreNMS\Util\Notifications;
|
||||
use Log;
|
||||
|
||||
class PluginManager
|
||||
@@ -107,16 +108,22 @@ class PluginManager
|
||||
*/
|
||||
public function call(string $hookType, array $args = [], ?string $plugin = null): Collection
|
||||
{
|
||||
try {
|
||||
return $this->hooksFor($hookType, $args, $plugin)
|
||||
->map(function ($hook) use ($args) {
|
||||
return $this->hooksFor($hookType, $args, $plugin)
|
||||
->map(function ($hook) use ($args, $hookType) {
|
||||
try {
|
||||
return app()->call([$hook['instance'], 'handle'], $this->fillArgs($args, $hook['plugin_name']));
|
||||
});
|
||||
} catch (Exception $e) {
|
||||
Log::error("Error calling hook $hookType: " . $e->getMessage());
|
||||
} catch (Exception|\Error $e) {
|
||||
$name = $hook['plugin_name'];
|
||||
Log::error("Error calling hook $hookType for $name: " . $e->getMessage());
|
||||
|
||||
return new Collection;
|
||||
}
|
||||
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]);
|
||||
|
||||
return 'HOOK FAILED';
|
||||
}
|
||||
})->filter(function ($hook) {
|
||||
return $hook === 'HOOK FAILED';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user