Added additional exception handling for EventLog Check

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

View file

@ -11,7 +11,8 @@
[hashtable]$Inputs = @{
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);
}
$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) {
Write-Host 'Filtering started!'
$filteredEvents = @();
foreach ($event in $events) {
# Filter out excluded event IDs