diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 76c7d10..7222b08 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -13,6 +13,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### Bugfixes +* [#752](https://github.com/Icinga/icinga-powershell-framework/pull/752) Fixes an exception for the windowseventlog feature of the Icinga Agent, in case it is not installed. + ### Enhancements ## 1.13.0 Beta-1 (2024-08-30) diff --git a/lib/core/icingaagent/writers/Write-IcingaAgentEventLogConfig.psm1 b/lib/core/icingaagent/writers/Write-IcingaAgentEventLogConfig.psm1 index b822bcc..85ec7f7 100644 --- a/lib/core/icingaagent/writers/Write-IcingaAgentEventLogConfig.psm1 +++ b/lib/core/icingaagent/writers/Write-IcingaAgentEventLogConfig.psm1 @@ -23,6 +23,13 @@ function Write-IcingaAgentEventLogConfig() [string]$Severity = 'information' ); + [string]$FilePath = (Join-Path -Path (Get-IcingaAgentConfigDirectory) -ChildPath 'features-available\windowseventlog.conf'); + + if ((Test-Path -Path $FilePath) -eq $FALSE) { + Write-IcingaConsoleNotice 'Windows Eventlog configuration for the Icinga Agent was not written. Either the Icinga Agent is not installed or your installed version does not support this feature'; + return; + } + $EventLogConf = New-Object System.Text.StringBuilder; $EventLogConf.AppendLine('/**') | Out-Null; @@ -33,6 +40,6 @@ function Write-IcingaAgentEventLogConfig() $EventLogConf.AppendLine([string]::Format(' severity = "{0}"', $Severity)) | Out-Null; $EventLogConf.Append('}') | Out-Null; - Write-IcingaFileSecure -File (Join-Path -Path (Get-IcingaAgentConfigDirectory) -ChildPath 'features-available\windowseventlog.conf') -Value $EventLogConf.ToString(); + Write-IcingaFileSecure -File $FilePath -Value $EventLogConf.ToString(); Write-IcingaConsoleNotice 'Windows Eventlog configuration has been written successfully to use severity level: {0} - Please restart the Icinga Agent to apply this change' -Objects $Severity; }