From 7860818be1ee8983454ee74e438212787875353c Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 19 May 2020 17:29:42 +0200 Subject: [PATCH] Adds new exception messages and custom exception handling --- .../exception/Exit-IcingaThrowException.psm1 | 14 +++++++++--- .../Icinga_IcingaExceptionEnums.psm1 | 22 ++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/icinga/exception/Exit-IcingaThrowException.psm1 b/lib/icinga/exception/Exit-IcingaThrowException.psm1 index 95a63df..b9b8027 100644 --- a/lib/icinga/exception/Exit-IcingaThrowException.psm1 +++ b/lib/icinga/exception/Exit-IcingaThrowException.psm1 @@ -5,7 +5,7 @@ function Exit-IcingaThrowException() [string]$StringPattern, [string]$CustomMessage, [string]$ExceptionThrown, - [ValidateSet('Permission','Input','Unhandled')] + [ValidateSet('Permission','Input','Configuration','Unhandled','Custom')] [string]$ExceptionType = 'Unhandled', [switch]$Force ); @@ -32,9 +32,16 @@ function Exit-IcingaThrowException() $ExceptionTypeString = 'Invalid Input'; $ExceptionMessageLib = $IcingaExceptions.Inputs; }; + 'Configuration' { + $ExceptionTypeString = 'Invalid Configuration'; + $ExceptionMessageLib = $IcingaExceptions.Configuration; + }; 'Unhandled' { $ExceptionTypeString = 'Unhandled'; }; + 'Custom' { + $ExceptionTypeString = 'Custom'; + }; } [string]$ExceptionName = ''; @@ -47,9 +54,10 @@ function Exit-IcingaThrowException() } } } else { - $ExceptionName = 'Unhandled Exception'; + $ExceptionName = [string]::Format('{0} Exception', $ExceptionTypeString); $ExceptionThrown = [string]::Format( - 'Unhandled exception occured:{0}{1}', + '{0} exception occured:{1}{2}', + $ExceptionTypeString, "`r`n", $InputString ); diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index 5422093..35158d4 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -5,17 +5,22 @@ #> [hashtable]$Permission = @{ - PerformanceCounter = 'A Plugin failed to fetch Performance Counter information. This may be caused when the used Service User is not permitted to access these information. To fix this, please add the User the Icinga Agent is running on into the "Performance Log Users" group and restart the service.'; - CacheFolder = "A plugin failed to write new data into the configured cache directory. Please update the permissions of this folder to allow write access for the user the Icinga Service is running with or use another folder as cache directory."; + PerformanceCounter = 'A Plugin failed to fetch Performance Counter information. This may be caused when the used Service User is not permitted to access these information. To fix this, please add the User the Icinga Agent is running on into the "Performance Log Users" group and restart the service.'; + CacheFolder = "A plugin failed to write new data into the configured cache directory. Please update the permissions of this folder to allow write access for the user the Icinga Service is running with or use another folder as cache directory."; }; [hashtable]$Inputs = @{ - PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; - 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.'; - ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".'; + PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; + 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.'; + ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".'; }; +[hashtable]$Configuration = @{ + PluginArgumentConflict = 'Your plugin argument configuration is causing a conflict. Mostly this error is caused by missmatching configurations by enabling multiple switch arguments which are resulting in a conflicting configuration for the plugin.'; + PluginArgumentmissing = 'Your plugin argument configuration is missing mandatory arguments. This is error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.'; +} + <# # Once we defined a new enum hashtable above, simply add it to this list # to make it available within the entire module. @@ -24,8 +29,9 @@ # $IcingaExceptionEnums.IcingaExecptionHandlers.PerformanceCounter #> [hashtable]$IcingaExceptions = @{ - Permission = $Permission; - Inputs = $Inputs; + Permission = $Permission; + Inputs = $Inputs; + Configuration = $Configuration; } Export-ModuleMember -Variable @( 'IcingaExceptions' );