Adds attempt to provide proper error handling for WMI exceptions

Implements #80
This commit is contained in:
Christian Stein 2020-07-28 09:26:12 +02:00
parent 27312d3152
commit 2d7cb5ea34

View file

@ -49,13 +49,13 @@ function Get-IcingaWindowsInformation()
$ErrorMessage = $_.Exception.Message; $ErrorMessage = $_.Exception.Message;
$ErrorCode = ($_.Exception.HResult -band 0xFFFF); $ErrorCode = ($_.Exception.HResult -band 0xFFFF);
switch ($ErrorCode) { switch ($ErrorName) {
# Permission error # Permission error
5376 { 'InvalidOperation' {
Exit-IcingaThrowException -ExceptionType 'Permission' -ExceptionThrown $IcingaExceptions.Permission.WMIObject -CustomMessage $ClassName -Force; Exit-IcingaThrowException -ExceptionType 'Permission' -ExceptionThrown $IcingaExceptions.Permission.WMIObject -CustomMessage $ClassName -Force;
}; };
# InvalidClass # Invalid Class
5377 { 'InvalidType' {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.WmiObjectClassUnknown -CustomMessage $ClassName -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.WmiObjectClassUnknown -CustomMessage $ClassName -Force;
}; };
# All other errors # All other errors