-
Notifications
You must be signed in to change notification settings - Fork 31
Description
I am using Get-IcingaCheckCommandConfig -IcingaConfig to create a command-plugins-powershell.conf for manual distribution.
Starting with V1.5.0, the output has syntax errors due to wrong double- vs single-quote escaping.
With V 1.4.1, everything worked fine.
Expected Behavior
Get-IcingaCheckCommandConfig -IcingaConfig output should be a well-formed conf-file
Quoting of Powershell code should be revised.
Current Behavior
Output contains a line like the following within each CeckCommand declaration:
value = "try { Use-Icinga -Minimal; } catch { Write-Output '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'; Write-Output "Error: $$($$_.Exception.Message)Components:rn$$( Get-Module -ListAvailable "icinga-powershell-*" )rnModule-Path:rn$$($$Env:PSModulePath)"; exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheckMPIO' "
E.g. look at "icinga-powershell-*" - it's a double-quoted string within the overall double-quoted string, but the inner double-quotes are not escaped. Consequently, errors are reported by
icinga2 daemon -C
Possible Solution
I worked around by running a script and -replace the snippet by a wellformed one:
$Directory = "$env:ProgramFiles\ICINGA2\share\icinga2\include"
Get-IcingaCheckCommandConfig -IcingaConfig -OutDirectory $Directory -FileName 'command-plugins-powershell-ori'
$snippet_original = "Write-Output ""Error: `$`$(`$`$_.Exception.Message)Components:``r``n`$`$( Get-Module -ListAvailable ""icinga-powershell-*"" )``r``nModule-Path:``r``n`$`$(`$`$Env:PSModulePath)""; exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheck"
$snippet_no_doublequotes = "Write-Output 'Error: '+`$`$`$`$_.Exception.Message+'Components:``r``n'+( Get-Module -ListAvailable 'icinga-powershell-*' )+'``r``nModule-Path:``r``n'+`$`$`$`$Env:PSModulePath; exit 3; }; Exit-IcingaExecutePlugin -Command 'Invoke-IcingaCheck"
((Get-Content "$Directory\command-plugins-powershell-ori.conf" -Raw) -replace [regex]::escape($snippet_original),$snippet_no_doublequotes ) | Set-Content -Path "$Directory\command-plugins-powershell.conf"
Remove-Item "$Directory\command-plugins-powershell-ori.conf" -Force
Steps to Reproduce (for bugs)
$Directory = "$env:ProgramFiles\ICINGA2\share\icinga2\include"Get-IcingaCheckCommandConfig -IcingaConfig -OutDirectory $Directory -FileName 'command-plugins-powershell'- Add the following to
$Directory\windows-plugins:
include "PowerShell_Base.conf"
include "command-plugins-powershell.conf"
$Env:ProgramFiles\ICINGA2\sbin\icinga2.exe daemon -C
Context
I am trying to use the Icinga Powershell Plugins without Director.
V 1.5.0 introduced the (at least for me) crucial feature to set -ThresholdInterval from Icinga 2 conf.
Your Environment
-
PowerShell Version used (
$PSVersionTable.PSVersion): Windows PowerShell V5.1 -
Operating System and version (
Get-IcingaWindowsInformation Win32_OperatingSystem | Select-Object Version, BuildNumber, Caption): Microsoft Windows Server 2016 Standard 10.0.14393