diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index 421b8a5..b2e484a 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -30,11 +30,12 @@ function Convert-Bytes() default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit}; } - Throw 'Invalid input'; + + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } \ No newline at end of file diff --git a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 index ec9256c..d1ac06b 100644 --- a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 @@ -14,7 +14,7 @@ function ConvertTo-ByteIEC() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -38,7 +38,7 @@ function ConvertTo-KibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -62,7 +62,7 @@ function ConvertTo-MibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -86,7 +86,7 @@ function ConvertTo-GibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -110,7 +110,7 @@ function ConvertTo-TibiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -134,7 +134,7 @@ function ConvertTo-PitiByte() { 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } diff --git a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 index 2602611..c01bdd9 100644 --- a/lib/core/tools/ConvertTo-ByteUnitSI.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitSI.psm1 @@ -30,7 +30,7 @@ function ConvertTo-ByteSI() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -70,7 +70,7 @@ function ConvertTo-KiloByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -110,7 +110,7 @@ function ConvertTo-MegaByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -150,7 +150,7 @@ function ConvertTo-GigaByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -190,7 +190,7 @@ function ConvertTo-TeraByte() { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } @@ -230,7 +230,7 @@ function ConvertTo-PetaByte() { 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { - Throw 'Invalid input'; + Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; } } } diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index 41b8cbb..18c80ed 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -5,14 +5,15 @@ #> [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.'; + 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, PT, Kibi, Mibi, Gibi, Tibi, Piti".'; }; <#