Added additional exception handling for EventLog Check

This commit is contained in:
Lord Hepipud 2019-09-18 12:42:20 +02:00
parent 0d7954617c
commit ac459d7fda
2 changed files with 9 additions and 3 deletions

View file

@ -11,7 +11,8 @@
[hashtable]$Inputs = @{ [hashtable]$Inputs = @{
PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.';
EventLog = 'Failed to fetch EventLog information. Please specify a LogName.'; EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.';
EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.';
}; };
<# <#

View file

@ -56,10 +56,15 @@ function Get-IcingaEventLog()
$EventLogArguments.Add('Before', $Before); $EventLogArguments.Add('Before', $Before);
} }
$events = Get-EventLog @EventLogArguments; try {
$events = Get-EventLog @EventLogArguments;
} catch {
Exit-IcingaThrowException -InputString $_.Exception -StringPattern 'ParameterBindingValidationException' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.EventLog;
Exit-IcingaThrowException -InputString $_.Exception -StringPattern 'System.InvalidOperationException' -CustomMessage (-Join $LogName) -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.EventLogLogName;
Exit-IcingaThrowException -InputString $_.Exception -ExceptionType 'Unhandled' -Force;
}
if ($null -ne $ExcludeEventId -Or $null -ne $ExcludeUsername -Or $null -ne $ExcludeEntryType -Or $null -ne $ExcludeMessage) { if ($null -ne $ExcludeEventId -Or $null -ne $ExcludeUsername -Or $null -ne $ExcludeEntryType -Or $null -ne $ExcludeMessage) {
Write-Host 'Filtering started!'
$filteredEvents = @(); $filteredEvents = @();
foreach ($event in $events) { foreach ($event in $events) {
# Filter out excluded event IDs # Filter out excluded event IDs