Merge pull request #252 from Icinga:fix/improve_module_error_handling

Feature: Inform the user if plugins are executed which are not meeting dependency requirements

Improve error handling on plugin execution by informing the user if the plugin is simply not installed or the entire module was not loaded because of errors or missing dependencies

Fixes #250
This commit is contained in:
Lord Hepipud 2021-05-21 11:37:31 +02:00 committed by GitHub
commit 56c2ab4188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#241](https://github.com/Icinga/icinga-powershell-framework/pull/241) Ensures we use TLS 1.1 and 1.2 for REST-Api calls, as used certificates in general are created with these * [#241](https://github.com/Icinga/icinga-powershell-framework/pull/241) Ensures we use TLS 1.1 and 1.2 for REST-Api calls, as used certificates in general are created with these
* [#243](https://github.com/Icinga/icinga-powershell-framework/pull/243) Adds stacktrace output for exceptions in case plugin execution fails * [#243](https://github.com/Icinga/icinga-powershell-framework/pull/243) Adds stacktrace output for exceptions in case plugin execution fails
* [#248](https://github.com/Icinga/icinga-powershell-framework/pull/248) Improves `Test-IcingaPerformanceCounterCategory` by creating an object for the Performance Counter category provided and checking if it is a valid object instead of relying on the registry which might not contain all categories in the correct language. * [#248](https://github.com/Icinga/icinga-powershell-framework/pull/248) Improves `Test-IcingaPerformanceCounterCategory` by creating an object for the Performance Counter category provided and checking if it is a valid object instead of relying on the registry which might not contain all categories in the correct language.
* [#250](https://github.com/Icinga/icinga-powershell-framework/pull/250) Improve error handling on plugin execution by informing the user if the plugin is simply not installed or the entire module was not loaded because of errors or missing dependencies
### Bugfixes ### Bugfixes

View file

@ -24,9 +24,27 @@
function Exit-IcingaPluginNotInstalled() function Exit-IcingaPluginNotInstalled()
{ {
param ( param (
$Command [string]$Command
); );
$PowerShellModule = Get-Module 'icinga-powershell-*' -ListAvailable |
ForEach-Object {
foreach ($cmd in $_.ExportedCommands.Values) {
if ($Command.ToLower() -eq $cmd.Name.ToLower()) {
return $cmd.Source;
}
}
}
if ([string]::IsNullOrEmpty($PowerShellModule) -eq $FALSE) {
try {
Import-Module $PowerShellModule -ErrorAction Stop;
} catch {
$ExMsg = $_.Exception.Message;
Exit-IcingaThrowException -CustomMessage 'Module not loaded' -ExceptionType 'Configuration' -ExceptionThrown $ExMsg -Force;
}
}
if ([string]::IsNullOrEmpty($Command)) { if ([string]::IsNullOrEmpty($Command)) {
Exit-IcingaThrowException -CustomMessage 'Null-Command' -ExceptionType 'Configuration' -ExceptionThrown $IcingaExceptions.Configuration.PluginNotAssigned -Force; Exit-IcingaThrowException -CustomMessage 'Null-Command' -ExceptionType 'Configuration' -ExceptionThrown $IcingaExceptions.Configuration.PluginNotAssigned -Force;
} }