Merge pull request #264 from Icinga:feature/add_first_handling_for_network_speed_units

Feature: Adds first handling for Framework link speeds

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.
This commit is contained in:
Lord Hepipud 2021-05-29 14:27:19 +02:00 committed by GitHub
commit 7ade142966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 16 deletions

View file

@ -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. * [#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 * [#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 * [#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 ### Bugfixes

View file

@ -23,6 +23,10 @@ function Convert-IcingaPluginValueToString()
} }
switch ($OriginalUnit) { 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") } { { ($_ -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')); return (ConvertTo-BytesNextUnit -Value $Value -Unit $Unit -Units @('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'));
}; };

View file

@ -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;
}

View file

@ -36,6 +36,14 @@
'GB' = 'Gigabytes'; 'GB' = 'Gigabytes';
'TB' = 'Terabytes'; 'TB' = 'Terabytes';
'c' = 'counter'; 'c' = 'counter';
'Kbit' = 'Kilobit';
'Mbit' = 'Megabit';
'Gbit' = 'Gigabit';
'Tbit' = 'Terabit';
'Pbit' = 'Petabit';
'Ebit' = 'Exabit';
'Zbit' = 'Zettabit';
'Ybit' = 'Yottabit';
}; };
<################################################################################################## <##################################################################################################

View file

@ -148,9 +148,8 @@ function Compare-IcingaPluginThresholds()
$IcingaThresholds.InRange = $FALSE; $IcingaThresholds.InRange = $FALSE;
$IcingaThresholds.Message = 'is matching threshold'; $IcingaThresholds.Message = 'is matching threshold';
$IcingaThresholds.Range = [string]::Format( $IcingaThresholds.Range = [string]::Format(
'{0}{1}', '{0}',
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue), (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit))
$IcingaThresholds.Unit
); );
} }
} elseif ($NotMatches) { } elseif ($NotMatches) {
@ -159,9 +158,8 @@ function Compare-IcingaPluginThresholds()
$IcingaThresholds.InRange = $FALSE; $IcingaThresholds.InRange = $FALSE;
$IcingaThresholds.Message = 'is not matching threshold'; $IcingaThresholds.Message = 'is not matching threshold';
$IcingaThresholds.Range = [string]::Format( $IcingaThresholds.Range = [string]::Format(
'{0}{1}', '{0}',
(ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $ThresholdValue), (ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value (Convert-IcingaPluginValueToString -Unit $IcingaThresholds.Unit -Value $ThresholdValue -OriginalUnit $IcingaThresholds.OriginalUnit))
$IcingaThresholds.Unit
); );
} }
} elseif ($IsBetween) { } elseif ($IsBetween) {