Skip to content

Commit 0e3e84c

Browse files
committed
Fixes null exception on GetBaseThresholdArguments
1 parent 7a2e8af commit 0e3e84c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1919
* [#285](https://github.com/Icinga/icinga-powershell-framework/issues/285) Fixes plain Icinga 2 conf generation for commands, which was caused by a new exception output for additional output
2020
* [#293](https://github.com/Icinga/icinga-powershell-framework/pull/293) Fixes crash on REST-Api for NULL values while parsing the REST message
2121
* [#295](https://github.com/Icinga/icinga-powershell-framework/issues/295) Fixes background service check daemon not working with arguments for plugins
22+
* [#297](https://github.com/Icinga/icinga-powershell-framework/pull/297) Fixes null exception error which can occur in certain edge cases, caused by testing `New-IcingaCheck` directly without function wrapper
2223

2324
## 1.5.0 (2021-06-02)
2425

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Get-IcingaThresholdCache()
2+
{
3+
param (
4+
[string]$CheckCommand = $null
5+
);
6+
7+
if ([string]::IsNullOrEmpty($CheckCommand)) {
8+
return $null;
9+
}
10+
11+
if ($null -eq $Global:Icinga) {
12+
return $null;
13+
}
14+
15+
if ($Global:Icinga.ContainsKey('ThresholdCache') -eq $FALSE) {
16+
return $null;
17+
}
18+
19+
if ($Global:Icinga.ThresholdCache.ContainsKey($CheckCommand) -eq $FALSE) {
20+
return $null;
21+
}
22+
23+
return $Global:Icinga.ThresholdCache[$CheckCommand];
24+
}

lib/icinga/plugin/New-IcingaCheck.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ function New-IcingaCheck()
387387
'-BaseValue' = $this.BaseValue;
388388
'-Unit' = $this.Unit;
389389
'-CheckName' = $this.__GetName();
390-
'-ThresholdCache' = $Global:Icinga.ThresholdCache[$this.__CheckCommand];
390+
'-ThresholdCache' = (Get-IcingaThresholdCache -CheckCommand $this.__CheckCommand);
391391
'-Translation' = $this.Translation;
392392
'-TimeInterval' = $this.__TimeInterval;
393393
};

0 commit comments

Comments
 (0)