From e7c341e30a18238782bc132ac24016b98ecae14a Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 1 Mar 2021 12:02:39 +0100 Subject: [PATCH] Fix wrong plugin not installed unknown checkresult --- doc/31-Changelog.md | 1 + lib/core/framework/Invoke-IcingaInternalServiceCall.psm1 | 9 +++++++-- lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1 | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index e97f6c8..2453f65 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -34,6 +34,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#208](https://github.com/Icinga/icinga-powershell-framework/pull/208) Fixes `Convert-IcingaPluginThresholds` which sometimes did not return proper numeric usable values for our internal functions, causing issues on plugin calls. In addition the function now also supports the handling for % units. * [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Fixed possible crash on `Get-IcingaAgentFeatures` if PowerShell is not running as administrator and therefor the command `icinga2 feature list` can not be processed * [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Fixed `ConvertTo-IcingaSecureString` to return `$null` for empty strings instead of throwing an exception +* [#214](https://github.com/Icinga/icinga-powershell-framework/pull/214) Fixes wrong `[Unknown] PluginNotInstalled` exception because of new plugin configuration and wrong checking against APi result in case feature is enabled ### Experimental diff --git a/lib/core/framework/Invoke-IcingaInternalServiceCall.psm1 b/lib/core/framework/Invoke-IcingaInternalServiceCall.psm1 index 2441f7e..bb81ef4 100644 --- a/lib/core/framework/Invoke-IcingaInternalServiceCall.psm1 +++ b/lib/core/framework/Invoke-IcingaInternalServiceCall.psm1 @@ -101,12 +101,17 @@ function Invoke-IcingaInternalServiceCall() $IcingaCR = ''; # In case we didn't receive a check result, fallback to local execution - if ($null -eq $IcingaResult.$Command.checkresult) { + if ([string]::IsNullOrEmpty($IcingaResult.$Command.checkresult)) { Write-IcingaEventMessage -Namespace 'Framework' -EventId 1553 -Objects 'The check result for the executed command was empty', $Command, $DebugArguments; return; } - $IcingaCR = ($IcingaResult.$Command.checkresult.Replace("`r`n", "`n")); + if ([string]::IsNullOrEmpty($IcingaResult.$Command.exitcode)) { + Write-IcingaEventMessage -Namespace 'Framework' -EventId 1553 -Objects 'The check result for the executed command was empty', $Command, $DebugArguments; + return; + } + + $IcingaCR = ($IcingaResult.$Command.checkresult.Replace("`r`n", "`n")); if ($IcingaResult.$Command.perfdata.Count -ne 0) { $IcingaCR += ' | '; diff --git a/lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1 b/lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1 index 95d3e27..b295a13 100644 --- a/lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1 +++ b/lib/icinga/plugin/Exit-IcingaExecutePlugin.psm1 @@ -4,8 +4,6 @@ function Exit-IcingaExecutePlugin() [string]$Command = '' ); - Exit-IcingaPluginNotInstalled -Command $Command; - Invoke-IcingaInternalServiceCall -Command $Command -Arguments $args; try { @@ -14,6 +12,8 @@ function Exit-IcingaExecutePlugin() Use-Icinga; } + Exit-IcingaPluginNotInstalled -Command $Command; + exit (& $Command @args); } catch { $ExMsg = $_.Exception.Message;