Merge pull request #390 from Icinga:fix/threshold_interval_fails_on_minute_to_hour_conversion

Fix: Thershold interval time conversion

Fixes an issue with `-ThresholdInterval` unit conversion, which causes an error if you want to convert `60m` or `1h`, as the used object is returning 0 for minutes in this matter, as the object itself moved to hours instead.

We should use `TotalMinutes` instead of `Minutes` on our `TimeSpan` object and round every single value returned to 0 digits.
This commit is contained in:
Lord Hepipud 2021-11-03 17:27:21 +01:00 committed by GitHub
commit d759a4dd31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#381](https://github.com/Icinga/icinga-powershell-framework/issues/381) Fixes Repository Hash generator for new repositories, which always returned the same hash regardless of the files inside * [#381](https://github.com/Icinga/icinga-powershell-framework/issues/381) Fixes Repository Hash generator for new repositories, which always returned the same hash regardless of the files inside
* [#386](https://github.com/Icinga/icinga-powershell-framework/pull/386) Fixes check command config generator for Icinga Director baskets/Icinga 2 conf files, in case we are using a check command with an alias as reference to a new name of a check command * [#386](https://github.com/Icinga/icinga-powershell-framework/pull/386) Fixes check command config generator for Icinga Director baskets/Icinga 2 conf files, in case we are using a check command with an alias as reference to a new name of a check command
* [#387](https://github.com/Icinga/icinga-powershell-framework/pull/387) Fixes config generator to use alias names for command arguments/parameters in case available instead of the real name * [#387](https://github.com/Icinga/icinga-powershell-framework/pull/387) Fixes config generator to use alias names for command arguments/parameters in case available instead of the real name
* [#390](https://github.com/Icinga/icinga-powershell-framework/pull/390) Fixes threshold interval time conversion by using `-ThresholdInterval` with values that cause the used `TimeSpan` object to move from minutes to hours, like `60m` and `1h`
### Enhancements ### Enhancements

View file

@ -61,7 +61,7 @@ function Compare-IcingaPluginThresholds()
if ([string]::IsNullOrEmpty($TimeInterval) -eq $FALSE -And $null -ne $ThresholdCache) { if ([string]::IsNullOrEmpty($TimeInterval) -eq $FALSE -And $null -ne $ThresholdCache) {
$TimeSeconds = ConvertTo-Seconds $TimeInterval; $TimeSeconds = ConvertTo-Seconds $TimeInterval;
$MinuteInterval = ([TimeSpan]::FromSeconds($TimeSeconds)).Minutes; $MinuteInterval = [math]::round(([TimeSpan]::FromSeconds($TimeSeconds)).TotalMinutes, 0);
$CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval); $CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval);
if ($null -ne $ThresholdCache.$CheckPerfDataLabel) { if ($null -ne $ThresholdCache.$CheckPerfDataLabel) {
@ -96,7 +96,7 @@ function Compare-IcingaPluginThresholds()
$Threshold = $TmpValue.Substring(0, $LastIndex); $Threshold = $TmpValue.Substring(0, $LastIndex);
$TimeIndex = $TmpValue.Substring($LastIndex + 1, $TmpValue.Length - $LastIndex - 1); $TimeIndex = $TmpValue.Substring($LastIndex + 1, $TmpValue.Length - $LastIndex - 1);
$TimeSeconds = ConvertTo-Seconds $TimeIndex; $TimeSeconds = ConvertTo-Seconds $TimeIndex;
$MinuteInterval = ([TimeSpan]::FromSeconds($TimeSeconds)).Minutes; $MinuteInterval = [math]::round(([TimeSpan]::FromSeconds($TimeSeconds)).TotalMinutes, 0);
$CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval); $CheckPerfDataLabel = [string]::Format('{0}_{1}', (Format-IcingaPerfDataLabel $CheckName), $MinuteInterval);