Skip to content

Commit

Permalink
Merge pull request #646 from Icinga:fix/allow_rest_api_to_handle_args…
Browse files Browse the repository at this point in the history
…_with_and_without_leading_-

Fix: REST-Api to allow args with and without leading -

Fixes REST-Api to allow arguments for check execution with and without leading `-`
  • Loading branch information
LordHepipud committed Jul 24, 2023
2 parents 57b21ef + 014aae1 commit b5e5995
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit b5e5995

Please sign in to comment.