mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #271 from Icinga:fix/StackOverflowException
Fix: StackOverflowException on invalid ThresholdInterval By using an invalid `-ThresholdInterval` argument, PowerShell will terminate itself with `StackOverflowException`, caused by a loop while creating default threshold values.
This commit is contained in:
commit
e4dcd9f9f5
3 changed files with 19 additions and 10 deletions
|
|
@ -63,6 +63,8 @@ function Compare-IcingaPluginThresholds()
|
||||||
$TimeInterval,
|
$TimeInterval,
|
||||||
$MinuteInterval
|
$MinuteInterval
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return $IcingaThresholds;
|
||||||
}
|
}
|
||||||
} <#else {
|
} <#else {
|
||||||
# The symbol splitting our threshold from the time index value
|
# The symbol splitting our threshold from the time index value
|
||||||
|
|
@ -130,12 +132,14 @@ function Compare-IcingaPluginThresholds()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Calculate % value from base value of set
|
# Calculate % value from base value of set
|
||||||
if ($null -ne $BaseValue -And $IcingaThresholds.Unit -eq '%') {
|
if ([string]::IsNullOrEmpty($BaseValue) -eq $FALSE -And $BaseValue -ne 0 -And $IcingaThresholds.Unit -eq '%') {
|
||||||
$InputValue = $InputValue / $BaseValue * 100;
|
$InputValue = $InputValue / $BaseValue * 100;
|
||||||
$UseDynamicPercentage = $TRUE;
|
$UseDynamicPercentage = $TRUE;
|
||||||
} elseif ($null -eq $BaseValue -And $IcingaThresholds.Unit -eq '%') {
|
} elseif (([string]::IsNullOrEmpty($BaseValue) -eq $TRUE -Or $BaseValue -eq 0) -And $IcingaThresholds.Unit -eq '%') {
|
||||||
$IcingaThresholds.HasError = $TRUE;
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
$IcingaThresholds.ErrorMessage = 'This argument does not support the % unit';
|
$IcingaThresholds.ErrorMessage = 'This argument does not support the % unit';
|
||||||
|
|
||||||
|
return $IcingaThresholds;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Always override our InputValue, case we might have change it
|
# Always override our InputValue, case we might have change it
|
||||||
|
|
@ -386,6 +390,8 @@ function Compare-IcingaPluginThresholds()
|
||||||
$Threshold
|
$Threshold
|
||||||
);
|
);
|
||||||
$IcingaThresholds.HasError = $TRUE;
|
$IcingaThresholds.HasError = $TRUE;
|
||||||
|
|
||||||
|
return $IcingaThresholds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,14 @@ function New-IcingaCheck()
|
||||||
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__ThresholdObject' -Value $null;
|
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__ThresholdObject' -Value $null;
|
||||||
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__TimeInterval' -Value $null;
|
$IcingaCheck | Add-Member -MemberType NoteProperty -Name '__TimeInterval' -Value $null;
|
||||||
|
|
||||||
|
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name 'Compile' -Value {
|
||||||
|
$this.__ValidateThresholdInput();
|
||||||
|
if ($null -eq $this.__ThresholdObject) {
|
||||||
|
$this.__CreateDefaultThresholdObject();
|
||||||
|
}
|
||||||
|
$this.__SetCheckOutput();
|
||||||
|
}
|
||||||
|
|
||||||
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__SetInternalTimeInterval' -Value {
|
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__SetInternalTimeInterval' -Value {
|
||||||
$CallStack = Get-PSCallStack;
|
$CallStack = Get-PSCallStack;
|
||||||
[bool]$FoundInterval = $FALSE;
|
[bool]$FoundInterval = $FALSE;
|
||||||
|
|
@ -82,8 +90,8 @@ function New-IcingaCheck()
|
||||||
|
|
||||||
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__CreateDefaultThresholdObject' -Value {
|
$IcingaCheck | Add-Member -MemberType ScriptMethod -Force -Name '__CreateDefaultThresholdObject' -Value {
|
||||||
[hashtable]$ThresholdArguments = $this.__GetBaseThresholdArguments();
|
[hashtable]$ThresholdArguments = $this.__GetBaseThresholdArguments();
|
||||||
$ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments;
|
$this.__ThresholdObject = Compare-IcingaPluginThresholds @ThresholdArguments;
|
||||||
$this.__SetCheckState($ThresholdObject, $IcingaEnums.IcingaExitCode.Ok);
|
$this.__SetCheckState($this.__ThresholdObject, $IcingaEnums.IcingaExitCode.Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Override shared function
|
# Override shared function
|
||||||
|
|
@ -94,10 +102,6 @@ function New-IcingaCheck()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($null -eq $this.__ThresholdObject) {
|
|
||||||
$this.__CreateDefaultThresholdObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
$PluginThresholds = '';
|
$PluginThresholds = '';
|
||||||
$TimeSpan = '';
|
$TimeSpan = '';
|
||||||
$PluginThresholds = $this.__ThresholdObject.FullMessage;
|
$PluginThresholds = $this.__ThresholdObject.FullMessage;
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,8 @@ function New-IcingaCheckBaseObject()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Shared function
|
||||||
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
||||||
$this.__ValidateThresholdInput();
|
|
||||||
$this.__SetCheckOutput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetVerbosity' -Value {
|
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetVerbosity' -Value {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue