Skip to content

Commit

Permalink
Merge pull request #744 from Icinga:feature/allows_setting_windowseve…
Browse files Browse the repository at this point in the history
…ntlog_config_for_agent

Feature: Adds cmdlet `Write-IcingaAgentEventLogConfig` to update eventlog severity and defaults to `warning`during installation and migration

Adds cmdlet `Write-IcingaAgentEventLogConfig` to update eventlog severity and defaults to `warning`during installation and migration tasks while updating to Icinga for Windows v1.13.0
  • Loading branch information
LordHepipud authored Aug 14, 2024
2 parents 6ffc7b7 + e84b511 commit fad86f9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

### Enhancements

* [#711](https://github.com/Icinga/icinga-powershell-framework/issues/711) Adds cmdlet `Write-IcingaAgentEventLogConfig` to update eventlog severity and defaults to `warning` during installation and migration
* [#732](https://github.com/Icinga/icinga-powershell-framework/pull/732) Adds support for TLS 1.3 and improves startup response
* [#735](https://github.com/Icinga/icinga-powershell-framework/pull/735) Adds support to provide occuring problem event id's for the Eventlog and corresponding acknowledgement id's, providing an indicator if certain issues are resolved or still present
* [#739](https://github.com/Icinga/icinga-powershell-framework/pull/739) Adds support to check the encoding of files to ensure we can properly load them and throw errors for unsupported encoding
Expand Down
2 changes: 2 additions & 0 deletions lib/core/framework/Invoke-IcingaForWindowsMigration.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ function Invoke-IcingaForWindowsMigration()

# Updates certificate renew task to handle changes made which now stores the Icinga CA inside the cert store
Start-IcingaWindowsScheduledTaskRenewCertificate;
# Ensure the Icinga Agent is not spamming the Application log by default
Write-IcingaAgentEventLogConfig -Severity 'warning';

Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.0');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ function Start-IcingaAgentInstallWizard()
# First cleanup the system by removing all old Firewalls
Enable-IcingaFirewall -IcingaPort $CAPort -Force;
}
# Ensure the Icinga Agent is not spamming the Application log by default
Write-IcingaAgentEventLogConfig -Severity 'warning';
Test-IcingaAgent;
if ($InstallFrameworkService) {
Restart-IcingaForWindows;
Expand Down
38 changes: 38 additions & 0 deletions lib/core/icingaagent/writers/Write-IcingaAgentEventLogConfig.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.SYNOPSIS
Writes the Icinga Agent Event Log configuration.
.DESCRIPTION
The Write-IcingaAgentEventLogConfig function is used to write the configuration for the Icinga Agent Event Log. It creates a configuration file with the specified severity level for the Windows Event Log Logger.
.PARAMETER Severity
Specifies the severity level for the Windows Event Log Logger. Valid values are 'debug', 'notice', 'information', 'warning', and 'critical'. The default value is 'information'.
.EXAMPLE
Write-IcingaAgentEventLogConfig -Severity 'warning'
This example writes the Icinga Agent Event Log configuration with the severity level set to 'warning'.
.NOTES
Please make sure to restart the Icinga Agent after applying any changes to the configuration.
#>

function Write-IcingaAgentEventLogConfig()
{
param (
[ValidateSet('debug', 'notice', 'information', 'warning', 'critical')]
[string]$Severity = 'information'
);

$EventLogConf = New-Object System.Text.StringBuilder;

$EventLogConf.AppendLine('/**') | Out-Null;
$EventLogConf.AppendLine(' * The WindowsEventLogLogger type writes log information to the Windows Event Log.') | Out-Null;
$EventLogConf.AppendLine(' */') | Out-Null;
$EventLogConf.AppendLine('') | Out-Null;
$EventLogConf.AppendLine('object WindowsEventLogLogger "windowseventlog" {') | Out-Null;
$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-IcingaConsoleNotice 'Windows Eventlog configuration has been written successfully to use severity level: {0} - Please restart the Icinga Agent to apply this change' -Objects $Severity;
}
2 changes: 2 additions & 0 deletions lib/core/installer/Start-IcingaForWindowsInstallation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function Start-IcingaForWindowsInstallation()
Set-IcingaUserPermissions -IcingaUser $ServiceUser;
Install-IcingaAgentBaseFeatures;
Write-IcingaAgentApiConfig -Port $IcingaPort;
# Ensure the Icinga Agent is not spamming the Application log by default
Write-IcingaAgentEventLogConfig -Severity 'warning';

# Fixes an issue with the local Icinga for Windows listen port and the defined ports for communicating with the Icinga Parent/CA Nodes
# This will check if we provided a custom port for the endpoints and use this one instead of the configured listen port if Icinga for Windows
Expand Down

0 comments on commit fad86f9

Please sign in to comment.