From 014aae198581463a74259ab1e779c6267a0f8f8f Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 24 Jul 2023 11:51:59 +0200 Subject: [PATCH] Fixes REST-Api to allow args with and without leading - --- doc/100-General/10-Changelog.md | 1 + .../ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1 | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 35ca6da..cd1d93e 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#617](https://github.com/Icinga/icinga-powershell-framework/issues/617) Fixes failing calls for plugins which use a switch argument like `-NoPerfData`, which is followed directly by the `-ThresholdInterval` argument * [#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems * [#645](https://github.com/Icinga/icinga-powershell-framework/pull/645) Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin for example +* [#646](https://github.com/Icinga/icinga-powershell-framework/pull/646) Fixes REST-Api to allow arguments for check execution with and without leading `-` ### Enhancements diff --git a/lib/daemons/modules/ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1 b/lib/daemons/modules/ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1 index 8a2f604..0dcbe65 100644 --- a/lib/daemons/modules/ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1 +++ b/lib/daemons/modules/ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1 @@ -99,16 +99,22 @@ function Invoke-IcingaApiChecksRESTCall() # a valid hashtable, allowing us to parse arguments # to our check command $PSArguments.PSObject.Properties | ForEach-Object { - $CmdArgValue = $_.Value; + $CmdArgValue = $_.Value; + [string]$CmdArgName = $_.Name; + + # Ensure we can use both, `-MyArgument` and `MyArgument` as valid input + if ($CmdArgName[0] -eq '-') { + $CmdArgName = $CmdArgName.Substring(1, $CmdArgName.Length - 1); + } # Ensure we convert strings to SecureString, in case the plugin argument requires it - if ($CommandDetails.ContainsKey($_.Name) -And $CommandDetails[$_.Name] -Like 'SecureString') { + if ($CommandDetails.ContainsKey($CmdArgName) -And $CommandDetails[$CmdArgName] -Like 'SecureString') { $CmdArgValue = ConvertTo-IcingaSecureString -String $_.Value; } Add-IcingaHashtableItem ` -Hashtable $Arguments ` - -Key $_.Name ` + -Key $CmdArgName ` -Value $CmdArgValue | Out-Null; };