mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Adds proper handling for invalid inputs on byte conversion for plugin usage
This commit is contained in:
parent
ac98e88626
commit
bec3459231
4 changed files with 21 additions and 19 deletions
|
|
@ -30,11 +30,12 @@ function Convert-Bytes()
|
||||||
|
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit};
|
return @{'value' = $FinalValue; 'pastunit' = $CurrentUnit; 'endunit' = $Unit};
|
||||||
}
|
}
|
||||||
Throw 'Invalid input';
|
|
||||||
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ function ConvertTo-ByteIEC()
|
||||||
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ function ConvertTo-ByteSI()
|
||||||
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
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; }
|
{ 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
||||||
default {
|
default {
|
||||||
if (-Not $boolOption) {
|
if (-Not $boolOption) {
|
||||||
Throw 'Invalid input';
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
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.';
|
||||||
EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid 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.';
|
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".';
|
||||||
};
|
};
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue