Skip to content

Commit bb435dc

Browse files
committed
Get-IcingaCheckCommandConfig: move -C from every single command to template
1 parent 5d7824b commit bb435dc

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
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

2020
### Enhancements
2121

22+
* [#631](https://github.com/Icinga/icinga-powershell-framework/pull/631) Deduplicates `-C try { Use-Icinga ...` boilerplate by adding it to the `PowerShell Base` template and removing it from every single command
2223
* [#679](https://github.com/Icinga/icinga-powershell-framework/pull/679) Adds a new data provider for fetching process information of Windows systems, while sorting all objects based on a process name and their process id
2324

2425
## 1.11.2 (tbd)

lib/core/tools/Get-IcingaCheckCommandConfig.psm1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
.NOTES
7070
#>
7171

72+
[string]$PsBaseCArg = [string]::Format('try {{ Use-Icinga -Minimal; }} catch {{ Write-Output {0}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{0}; Write-Output {0}Error:{0} $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable {0}icinga-powershell-*{0} )`r`n{0}Module-Path:{0}`r`n$$($$Env:PSModulePath); exit 3; }}; Exit-IcingaExecutePlugin -Command {0}$ifw_api_command${0} ', "'");
73+
7274
function Get-IcingaCheckCommandConfig()
7375
{
7476
param(
@@ -114,6 +116,10 @@ function Get-IcingaCheckCommandConfig()
114116
'order' = '-1';
115117
'value' = '$IcingaPowerShellBase_String_ExecutionPolicy$';
116118
};
119+
'-C' = @{
120+
'order' = '0';
121+
'value' = $PsBaseCArg;
122+
};
117123
};
118124
'command' = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
119125
'disabled' = $FALSE;
@@ -201,13 +207,7 @@ function Get-IcingaCheckCommandConfig()
201207
# Add command Structure
202208
$Basket.Command.Add(
203209
$check, @{
204-
'arguments' = @{
205-
# Set the Command handling for every check command
206-
'-C' = @{
207-
'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, "'");
208-
'order' = '0';
209-
};
210-
}
210+
'arguments' = @{ }
211211
'fields' = @();
212212
'imports' = @( 'PowerShell Base' );
213213
'object_name' = $check;
@@ -694,6 +694,10 @@ function Write-IcingaPlainConfigurationFiles()
694694
$PowerShellBase += [string]::Format(' ]{0}', (New-IcingaNewLine));
695695
$PowerShellBase += [string]::Format(' timeout = 3m{0}', (New-IcingaNewLine));
696696
$PowerShellBase += [string]::Format(' arguments += {{{0}', (New-IcingaNewLine));
697+
$PowerShellBase += [string]::Format(' "-C" = {{{0}', (New-IcingaNewLine));
698+
$PowerShellBase += [string]::Format(' order = 0{0}', (New-IcingaNewLine));
699+
$PowerShellBase += [string]::Format(' value = "{0}"{1}', $PsBaseCArg, (New-IcingaNewLine));
700+
$PowerShellBase += [string]::Format(' }}{0}', (New-IcingaNewLine));
697701
$PowerShellBase += [string]::Format(' "-ExecutionPolicy" = {{{0}', (New-IcingaNewLine));
698702
$PowerShellBase += [string]::Format(' order = -1{0}', (New-IcingaNewLine));
699703
$PowerShellBase += [string]::Format(' value = "$IcingaPowerShellBase_String_ExecutionPolicy$"{0}', (New-IcingaNewLine));

0 commit comments

Comments
 (0)