Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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