Adds first handling for Framework link speeds

This commit is contained in:
Lord Hepipud 2021-05-29 14:25:06 +02:00
parent 411ce69223
commit 28b78c1ec1
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.
* [#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

View file

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

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

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

View file

@ -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) {