Skip to content

Commit b5e5995

Browse files
authored
Merge pull request #646 from Icinga:fix/allow_rest_api_to_handle_args_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 `-`
2 parents 57b21ef + 014aae1 commit b5e5995

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

doc/100-General/10-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1919
* [#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
2020
* [#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems
2121
* [#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
22+
* [#646](https://github.com/Icinga/icinga-powershell-framework/pull/646) Fixes REST-Api to allow arguments for check execution with and without leading `-`
2223

2324
### Enhancements
2425

lib/daemons/modules/ApiChecks/Invoke-IcingaApiChecksRESTCall.psm1

+9-3
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ function Invoke-IcingaApiChecksRESTCall()
9999
# a valid hashtable, allowing us to parse arguments
100100
# to our check command
101101
$PSArguments.PSObject.Properties | ForEach-Object {
102-
$CmdArgValue = $_.Value;
102+
$CmdArgValue = $_.Value;
103+
[string]$CmdArgName = $_.Name;
104+
105+
# Ensure we can use both, `-MyArgument` and `MyArgument` as valid input
106+
if ($CmdArgName[0] -eq '-') {
107+
$CmdArgName = $CmdArgName.Substring(1, $CmdArgName.Length - 1);
108+
}
103109

104110
# Ensure we convert strings to SecureString, in case the plugin argument requires it
105-
if ($CommandDetails.ContainsKey($_.Name) -And $CommandDetails[$_.Name] -Like 'SecureString') {
111+
if ($CommandDetails.ContainsKey($CmdArgName) -And $CommandDetails[$CmdArgName] -Like 'SecureString') {
106112
$CmdArgValue = ConvertTo-IcingaSecureString -String $_.Value;
107113
}
108114

109115
Add-IcingaHashtableItem `
110116
-Hashtable $Arguments `
111-
-Key $_.Name `
117+
-Key $CmdArgName `
112118
-Value $CmdArgValue | Out-Null;
113119
};
114120

0 commit comments

Comments
 (0)