diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 457c11b..92bab00 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -23,6 +23,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#248](https://github.com/Icinga/icinga-powershell-framework/pull/248) Improves `Test-IcingaPerformanceCounterCategory` by creating an object for the Performance Counter category provided and checking if it is a valid object instead of relying on the registry which might not contain all categories in the correct language. * [#249](https://github.com/Icinga/icinga-powershell-framework/pull/249) Improves internal exception handler to get rid if misplaced `:` and adds all fields properly * [#250](https://github.com/Icinga/icinga-powershell-framework/pull/250) Improve error handling on plugin execution by informing the user if the plugin is simply not installed or the entire module was not loaded because of errors or missing dependencies +* [#264](https://github.com/Icinga/icinga-powershell-framework/pull/264) Adds initial handling for handling link speeds or anything else by using new units and conversions, which were formerly used inside the Network plugin and corresponding provider ### Bugfixes diff --git a/lib/core/tools/Convert-IcingaPluginValueToString.psm1 b/lib/core/tools/Convert-IcingaPluginValueToString.psm1 index 75be75c..c8c9928 100644 --- a/lib/core/tools/Convert-IcingaPluginValueToString.psm1 +++ b/lib/core/tools/Convert-IcingaPluginValueToString.psm1 @@ -23,6 +23,10 @@ function Convert-IcingaPluginValueToString() } switch ($OriginalUnit) { + { ($_ -eq "Kbit") -or ($_ -eq "Mbit") -or ($_ -eq "Gbit") -or ($_ -eq "Tbit") -or ($_ -eq "Pbit") -or ($_ -eq "Ebit") -or ($_ -eq "Zbit") -or ($_ -eq "Ybit") } { + $TransferSpeed = Get-IcingaNetworkInterfaceUnits -Value $Value; + return ([string]::Format('{0}{1}', $TransferSpeed.LinkSpeed, $TransferSpeed.Unit)); + }; { ($_ -eq "B") -or ($_ -eq "KiB") -or ($_ -eq "MiB") -or ($_ -eq "GiB") -or ($_ -eq "TiB") -or ($_ -eq "PiB") -or ($_ -eq "EiB") -or ($_ -eq "ZiB") -or ($_ -eq "YiB") } { return (ConvertTo-BytesNextUnit -Value $Value -Unit $Unit -Units @('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')); }; diff --git a/lib/core/tools/Get-IcingaNetworkInterfaceUnits.psm1 b/lib/core/tools/Get-IcingaNetworkInterfaceUnits.psm1 new file mode 100644 index 0000000..2861df2 --- /dev/null +++ b/lib/core/tools/Get-IcingaNetworkInterfaceUnits.psm1 @@ -0,0 +1,24 @@ +function Get-IcingaNetworkInterfaceUnits() +{ + param ( + [long]$Value + ); + + [hashtable]$InterfaceData = @{ + 'RawValue' = $Value; + 'LinkSpeed' = 0; + 'Unit' = 'Mbit' + }; + + [decimal]$result = ($Value / [Math]::Pow(10, 6)); + + if ($result -ge 1000) { + $InterfaceData.LinkSpeed = [decimal]($result / 1000); + $InterfaceData.Unit = 'Gbit'; + } else { + $InterfaceData.LinkSpeed = $result; + $InterfaceData.Unit = 'Mbit'; + } + + return $InterfaceData; +} diff --git a/lib/icinga/enums/Icinga_IcingaEnums.psm1 b/lib/icinga/enums/Icinga_IcingaEnums.psm1 index 4d4f5d8..0e70992 100644 --- a/lib/icinga/enums/Icinga_IcingaEnums.psm1 +++ b/lib/icinga/enums/Icinga_IcingaEnums.psm1 @@ -26,16 +26,24 @@ }; [hashtable]$IcingaMeasurementUnits = @{ - 's' = 'seconds'; - 'ms' = 'milliseconds'; - 'us' = 'microseconds'; - '%' = 'percent'; - 'B' = 'bytes'; - 'KB' = 'Kilobytes'; - 'MB' = 'Megabytes'; - 'GB' = 'Gigabytes'; - 'TB' = 'Terabytes'; - 'c' = 'counter'; + 's' = 'seconds'; + 'ms' = 'milliseconds'; + 'us' = 'microseconds'; + '%' = 'percent'; + 'B' = 'bytes'; + 'KB' = 'Kilobytes'; + 'MB' = 'Megabytes'; + 'GB' = 'Gigabytes'; + 'TB' = 'Terabytes'; + 'c' = 'counter'; + 'Kbit' = 'Kilobit'; + 'Mbit' = 'Megabit'; + 'Gbit' = 'Gigabit'; + 'Tbit' = 'Terabit'; + 'Pbit' = 'Petabit'; + 'Ebit' = 'Exabit'; + 'Zbit' = 'Zettabit'; + 'Ybit' = 'Yottabit'; }; <################################################################################################## diff --git a/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 b/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 index facfe7c..8147aec 100644 --- a/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 +++ b/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 @@ -148,9 +148,8 @@ function Compare-IcingaPluginThresholds() $IcingaThresholds.InRange = $FALSE; $IcingaThresholds.Message = 'is matching threshold'; $IcingaThresholds.Range = [string]::Format( - '{0}{1}', - (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue), - $IcingaThresholds.Unit + '{0}', + (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit)) ); } } elseif ($NotMatches) { @@ -159,9 +158,8 @@ function Compare-IcingaPluginThresholds() $IcingaThresholds.InRange = $FALSE; $IcingaThresholds.Message = 'is not matching threshold'; $IcingaThresholds.Range = [string]::Format( - '{0}{1}', - (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue), - $IcingaThresholds.Unit + '{0}', + (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit)) ); } } elseif ($IsBetween) {