Skip to content

Commit aac9cab

Browse files
authored
Merge pull request #569 from Icinga:feature/allow_filtering_for_messages_with_eventlog_parser
Feature: Adds filtering options for EventLog parser Adds `-Include` and `-Exclude` filter for EventLog CLI parser, to only contain certain messages or exclude them from the output.
2 parents 0291f5a + 4fb4c6a commit aac9cab

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
4242
* [#534](https://github.com/Icinga/icinga-powershell-framework/pull/534) Improves Icinga and Director configuration generator, by wrapping PowerShell arrays inside `@()` instead of simply writing them comma separated
4343
* [#536](https://github.com/Icinga/icinga-powershell-framework/pull/536) Adds new function `Test-IcingaArrayFilter` for easier include and exclude filtering during plugin runtime and to allow filtering of array content for intended values only
4444
* [#560](https://github.com/Icinga/icinga-powershell-framework/pull/560) Improves handling for Icinga Management Console which will now terminate itself during full uninstallation and restarts after updating the Icinga PowerShell Framework, to apply changes directly
45+
* [#569](https://github.com/Icinga/icinga-powershell-framework/pull/569) Adds `-Include` and `-Exclude` filter for EventLog CLI parser, to only contain certain messages or exclude them from the output
4546

4647
## 1.9.2 (2022-06-03)
4748

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
function Read-IcingaForWindowsLog()
22
{
33
param (
4-
[array]$Source = @()
4+
[array]$Source = @(),
5+
[array]$Include = @(),
6+
[array]$Exclude = @()
57
);
68

7-
Read-IcingaWindowsEventLog -LogName 'Icinga for Windows' -Source $Source -MaxEntries 500;
9+
Read-IcingaWindowsEventLog -LogName 'Icinga for Windows' -Source $Source -MaxEntries 500 -Include $Include -Exclude $Exclude;
810
}

lib/core/framework/Read-IcingaWindowsEventLog.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function Read-IcingaWindowsEventLog()
33
param (
44
[string]$LogName = 'Application',
55
[array]$Source = @(),
6+
[array]$Include = @(),
7+
[array]$Exclude = @(),
68
[int]$MaxEntries = 500
79
);
810

@@ -17,7 +19,7 @@ function Read-IcingaWindowsEventLog()
1719
$MaxEvents = 40000;
1820

1921
while ($TRUE) {
20-
[array]$IcingaEvents = Get-WinEvent -LogName $LogName -MaxEvents $MaxEvents -ErrorAction Stop;
22+
[array]$IcingaEvents = Get-WinEvent -LogName $LogName -MaxEvents $MaxEvents -ErrorAction SilentlyContinue;
2123
[int]$CurrentIndex = $MaxEntries;
2224
[array]$CollectedEvents = @();
2325

@@ -43,6 +45,10 @@ function Read-IcingaWindowsEventLog()
4345
break;
4446
}
4547

48+
if ((Test-IcingaArrayFilter -InputObject $event.Message -Include $Include -Exclude $Exclude) -eq $FALSE) {
49+
continue;
50+
}
51+
4652
$CollectedEvents += $event;
4753
}
4854

lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
function Read-IcingaAgentLogFile()
22
{
3+
param (
4+
[array]$Include = @(),
5+
[array]$Exclude = @()
6+
);
7+
38
if ((Test-IcingaAgentFeatureEnabled -Feature 'windowseventlog') -And ([version](Get-IcingaAgentVersion).Full) -ge (New-IcingaVersionObject -Version '2.13.0')) {
49

510
# Icinga 2.13.0 and beyond will log directly into the EventLog
6-
Read-IcingaWindowsEventLog -LogName 'Application' -Source 'Icinga 2' -MaxEntries 500;
11+
Read-IcingaWindowsEventLog -LogName 'Application' -Source 'Icinga 2' -MaxEntries 500 -Include $Include -Exclude $Exclude;
712
} else {
813
$Logfile = Join-Path -Path (Get-IcingaAgentLogDirectory) -ChildPath 'icinga2.log';
914
if ((Test-Path $Logfile) -eq $FALSE) {

0 commit comments

Comments
 (0)