Fixed crash on check execution while running in daemon mode

This commit is contained in:
Lord Hepipud 2019-10-06 10:46:11 +02:00
parent 0e1940325a
commit 7e23ea76df
3 changed files with 17 additions and 4 deletions

View file

@ -40,11 +40,18 @@ function New-IcingaCheck()
$Check | Add-Member -membertype ScriptMethod -name 'HandleDaemon' -value {
# Only apply this once the checkcommand is set
if ([string]::IsNullOrEmpty($this.checkcommand) -Or $global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) {
return;
}
if ($global:IcingaDaemonData.ContainsKey('BackgroundDaemon') -eq $FALSE) {
return;
}
if ($global:IcingaDaemonData.BackgroundDaemon.ContainsKey('ServiceCheckScheduler') -eq $FALSE) {
return;
}
if ($global:IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($this.checkcommand)) {
if ($global:IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$this.checkcommand]['results'].ContainsKey($this.name) -eq $FALSE) {
$global:IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$this.checkcommand]['results'].Add(

View file

@ -7,6 +7,8 @@ function Write-IcingaPluginOutput()
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) {
Write-Host $Output;
} else {
$IcingaThreadContent['Scheduler']['PluginCache'] += $Output;
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginCache'] += $Output;
}
}
}

View file

@ -37,7 +37,9 @@ function Get-IcingaPluginPerfDataContent()
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value);
if ($AsObject) {
$global:IcingaThreadContent['Scheduler']['PluginPerfData'] += $cachedresult;
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $cachedresult;
}
}
$PerfDataOutput += $cachedresult;
}
@ -46,7 +48,9 @@ function Get-IcingaPluginPerfDataContent()
$compiledPerfData = (New-IcingaPerformanceDataEntry $data);
if ($AsObject) {
$global:IcingaThreadContent['Scheduler']['PluginPerfData'] += $compiledPerfData;
if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) {
$global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $compiledPerfData;
}
}
$PerfDataOutput += $compiledPerfData;
}