Skip to content

Commit ba941c1

Browse files
authored
Merge pull request #386 from Icinga:fix/check_generator_for_alias_checks
Fix: Check command generator for aliases In case we are using aliases for check commands, to keep backwards compatibility, we have to ensure that check commands actually use the name of the alias for custom variables, to not break the naming and prevent wrong usage of custom variables.
2 parents 97ebe46 + 6cb7743 commit ba941c1

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1717
* [#376](https://github.com/Icinga/icinga-powershell-framework/pull/376) Fixes IMC error handling on invalid JSON for installation command/file
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
20+
* [#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
2021

2122
### Enhancements
2223

lib/core/tools/Get-IcingaCheckCommandConfig.psm1

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ function Get-IcingaCheckCommandConfig()
168168
# Loop through ${CheckName}, to get information on every command specified/all commands.
169169
foreach ($check in $CheckName) {
170170

171+
[string]$check = [string]$check;
172+
171173
# Get necessary syntax-information and more through cmdlet "Get-Help"
172174
$Data = (Get-Help $check);
173175
$ParameterList = (Get-Command -Name $check).Parameters;
174176
$CheckParamList = @( $ThresholdIntervalArg );
175-
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
177+
$PluginNameSpace = $check.Replace('Invoke-', '');
176178

177179
foreach ($entry in $Data.parameters.parameter) {
178180
foreach ($BlackListArg in $BlacklistedArguments) {
@@ -195,17 +197,17 @@ function Get-IcingaCheckCommandConfig()
195197

196198
# Add command Structure
197199
$Basket.Command.Add(
198-
$Data.Name, @{
200+
$check, @{
199201
'arguments' = @{
200202
# Set the Command handling for every check command
201203
'-C' = @{
202-
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; Write-Output {1}Error:{1} $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable {1}icinga-powershell-*{1} )`r`n{1}Module-Path:{1}`r`n$$($$Env:PSModulePath); exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $Data.Name, "'");
204+
'value' = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {1}The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details{1}; Write-Output {1}Error:{1} $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable {1}icinga-powershell-*{1} )`r`n{1}Module-Path:{1}`r`n$$($$Env:PSModulePath); exit 3; }}; Exit-IcingaExecutePlugin -Command {1}{0}{1} ', $check, "'");
203205
'order' = '0';
204206
};
205207
}
206208
'fields' = @();
207209
'imports' = @( 'PowerShell Base' );
208-
'object_name' = $Data.Name;
210+
'object_name' = $check;
209211
'object_type' = 'object';
210212
'vars' = @{ };
211213
}
@@ -238,19 +240,19 @@ function Get-IcingaCheckCommandConfig()
238240

239241
# Add arguments to a given command
240242
if ($parameter.type.name -eq 'SwitchParameter') {
241-
$Basket.Command[$Data.Name].arguments.Add(
243+
$Basket.Command[$check].arguments.Add(
242244
[string]::Format('-{0}', $parameter.Name), @{
243245
'set_if' = $IcingaCustomVariable;
244246
'set_if_format' = 'string';
245247
'order' = $Order;
246248
}
247249
);
248250

249-
$Basket.Command[$Data.Name].vars.Add($IcingaCustomVariable.Replace('$', ''), $FALSE);
251+
$Basket.Command[$check].vars.Add($IcingaCustomVariable.Replace('$', ''), $FALSE);
250252

251253
} elseif ($parameter.type.name -eq 'Array') {
252254
# Conditional whether type of parameter is array
253-
$Basket.Command[$Data.Name].arguments.Add(
255+
$Basket.Command[$check].arguments.Add(
254256
[string]::Format('-{0}', $parameter.Name), @{
255257
'value' = @{
256258
'type' = 'Function';
@@ -268,7 +270,7 @@ function Get-IcingaCheckCommandConfig()
268270
);
269271
} elseif ($parameter.type.name -eq 'SecureString') {
270272
# Convert out input string as SecureString
271-
$Basket.Command[$Data.Name].arguments.Add(
273+
$Basket.Command[$check].arguments.Add(
272274
[string]::Format('-{0}', $parameter.Name), @{
273275
'value' = (
274276
[string]::Format(
@@ -281,7 +283,7 @@ function Get-IcingaCheckCommandConfig()
281283
);
282284
} else {
283285
# Default to Object
284-
$Basket.Command[$Data.Name].arguments.Add(
286+
$Basket.Command[$check].arguments.Add(
285287
[string]::Format('-{0}', $parameter.Name), @{
286288
'value' = $IcingaCustomVariable;
287289
'order' = $Order;
@@ -388,9 +390,10 @@ function Get-IcingaCheckCommandConfig()
388390

389391
foreach ($check in $CheckName) {
390392
[int]$FieldNumeration = 0;
393+
[string]$check = [string]$check;
391394

392395
$Data = (Get-Help $check)
393-
$PluginNameSpace = $Data.Name.Replace('Invoke-', '');
396+
$PluginNameSpace = $check.Replace('Invoke-', '');
394397
$CheckParamList = @( $ThresholdIntervalArg );
395398

396399
foreach ($entry in $Data.parameters.parameter) {
@@ -409,7 +412,7 @@ function Get-IcingaCheckCommandConfig()
409412
foreach ($DataFieldID in $Basket.Datafield.Keys) {
410413
[string]$varname = $Basket.Datafield[$DataFieldID].varname;
411414
if ([string]$varname -eq [string]$IcingaCustomVariable) {
412-
$Basket.Command[$Data.Name].fields += @{
415+
$Basket.Command[$check].fields += @{
413416
'datafield_id' = [int]$DataFieldID;
414417
'is_required' = $Required;
415418
'var_filter' = $NULL;

0 commit comments

Comments
 (0)