Skip to content

Commit 6e9f256

Browse files
authored
Merge pull request #387 from Icinga:fix/use_alias_for_command_args_on_config_generation_if_available
Fix: Use alias for args name on config generation In case we are using aliases for command arguments/parameters, we should always use the first alias we find as argument instead of using the real name.
2 parents ba941c1 + cf2125d commit 6e9f256

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818
* [#377](https://github.com/Icinga/icinga-powershell-framework/issues/377) Fixes overhead for testing of modules being loaded, which returned invalid path values and wrong exceptions, which was unnecessary in first place
1919
* [#381](https://github.com/Icinga/icinga-powershell-framework/issues/381) Fixes Repository Hash generator for new repositories, which always returned the same hash regardless of the files inside
2020
* [#386](https://github.com/Icinga/icinga-powershell-framework/pull/386) Fixes check command config generator for Icinga Director baskets/Icinga 2 conf files, in case we are using a check command with an alias as reference to a new name of a check command
21+
* [#387](https://github.com/Icinga/icinga-powershell-framework/pull/387) Fixes config generator to use alias names for command arguments/parameters in case available instead of the real name
2122

2223
### Enhancements
2324

lib/core/tools/Convert-IcingaCheckArgumentToPSObject.psm1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
function Convert-IcingaCheckArgumentToPSObject()
22
{
33
param (
4-
$Parameter = $null
4+
$Parameter = $null,
5+
$CheckCommand = $null
56
);
67

78
$ParamValue = New-Object -TypeName PSObject;
@@ -10,11 +11,22 @@ function Convert-IcingaCheckArgumentToPSObject()
1011
return $ParamValue;
1112
}
1213

14+
$ParameterName = $Parameter.name;
15+
16+
if ([string]::IsNullOrEmpty($CheckCommand) -eq $FALSE) {
17+
$CmdData = Get-Command $CheckCommand;
18+
if ($CmdData.Parameters.ContainsKey($ParameterName)) {
19+
if ($CmdData.Parameters[$ParameterName].Aliases.Count -ne 0) {
20+
$ParameterName = $CmdData.Parameters[$ParameterName].Aliases[0];
21+
}
22+
}
23+
}
24+
1325
$ParamValue | Add-Member -MemberType NoteProperty -Name 'type' -Value (New-Object -TypeName PSObject);
1426
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Description' -Value (New-Object -TypeName PSObject);
1527
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Attributes' -Value (New-Object -TypeName PSObject);
1628
$ParamValue | Add-Member -MemberType NoteProperty -Name 'position' -Value $Parameter.position;
17-
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Name' -Value $Parameter.name;
29+
$ParamValue | Add-Member -MemberType NoteProperty -Name 'Name' -Value $ParameterName;
1830
$ParamValue | Add-Member -MemberType NoteProperty -Name 'required' -Value $Parameter.required;
1931
$ParamValue.type | Add-Member -MemberType NoteProperty -Name 'name' -Value $Parameter.type.name;
2032
$ParamValue.Description | Add-Member -MemberType NoteProperty -Name 'Text' -Value $Parameter.Description.Text;

lib/core/tools/Get-IcingaCheckCommandConfig.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function Get-IcingaCheckCommandConfig()
183183
return;
184184
}
185185
}
186-
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry);
186+
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry -CheckCommand $check);
187187
}
188188

189189
foreach ($arg in $ParameterList.Keys) {
@@ -397,7 +397,7 @@ function Get-IcingaCheckCommandConfig()
397397
$CheckParamList = @( $ThresholdIntervalArg );
398398

399399
foreach ($entry in $Data.parameters.parameter) {
400-
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry);
400+
$CheckParamList += (Convert-IcingaCheckArgumentToPSObject -Parameter $entry -CheckCommand $check);
401401
}
402402

403403
foreach ($parameter in $CheckParamList) {

0 commit comments

Comments
 (0)