mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Extended Second conversion with Icinga threshold handling
This commit is contained in:
parent
c37de3cfa1
commit
7890b69e4c
1 changed files with 45 additions and 0 deletions
|
|
@ -7,9 +7,14 @@ function ConvertTo-Seconds()
|
||||||
[string]$Value
|
[string]$Value
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($Value)) {
|
||||||
|
return $Value;
|
||||||
|
}
|
||||||
|
|
||||||
[string]$NumberPart = '';
|
[string]$NumberPart = '';
|
||||||
[string]$UnitPart = '';
|
[string]$UnitPart = '';
|
||||||
[bool]$Negate = $FALSE;
|
[bool]$Negate = $FALSE;
|
||||||
|
[bool]$hasUnit = $FALSE;
|
||||||
|
|
||||||
foreach($char in $Value.ToCharArray()) {
|
foreach($char in $Value.ToCharArray()) {
|
||||||
if ((Test-Numeric $char)) {
|
if ((Test-Numeric $char)) {
|
||||||
|
|
@ -21,10 +26,15 @@ function ConvertTo-Seconds()
|
||||||
$NumberPart += '.';
|
$NumberPart += '.';
|
||||||
} else {
|
} else {
|
||||||
$UnitPart += $char;
|
$UnitPart += $char;
|
||||||
|
$hasUnit = $TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-Not $hasUnit) {
|
||||||
|
return $Value;
|
||||||
|
}
|
||||||
|
|
||||||
[single]$ValueSplitted = $NumberPart;
|
[single]$ValueSplitted = $NumberPart;
|
||||||
$result = 0;
|
$result = 0;
|
||||||
|
|
||||||
|
|
@ -60,3 +70,38 @@ function ConvertTo-Seconds()
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ConvertTo-SecondsFromIcingaThresholds()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Threshold
|
||||||
|
);
|
||||||
|
|
||||||
|
[array]$Content = $Threshold.Split(':');
|
||||||
|
[array]$NewContent = @();
|
||||||
|
|
||||||
|
foreach ($entry in $Content) {
|
||||||
|
$NewContent += (Get-IcingaThresholdsAsSeconds -Value $entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return [string]::Join(':', $NewContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-IcingaThresholdsAsSeconds()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[string]$Value
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($Value.Contains('~')) {
|
||||||
|
$Value = $Value.Replace('~', '');
|
||||||
|
return [string]::Format('~{0}', (ConvertTo-Seconds $Value));
|
||||||
|
} elseif ($Value.Contains('@')) {
|
||||||
|
$Value = $Value.Replace('@', '');
|
||||||
|
return [string]::Format('@{0}', (ConvertTo-Seconds $Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ConvertTo-Seconds $Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Export-ModuleMember -Function @( 'ConvertTo-Seconds', 'ConvertTo-SecondsFromIcingaThresholds' );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue