Skip to content

Commit 36d1d7b

Browse files
committed
Fixes service daemon not working with arguments
1 parent a6f3ada commit 36d1d7b

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818
* [#284](https://github.com/Icinga/icinga-powershell-framework/issues/284) Fixes exception while creating default threshold objects
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
21+
* [#295](https://github.com/Icinga/icinga-powershell-framework/issues/295) Fixes background service check daemon not working with arguments for plugins
2122

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

lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ function Start-IcingaServiceCheckDaemon()
3939
continue;
4040
}
4141

42-
Start-IcingaServiceCheckTask -CheckId $service -CheckCommand $RegisteredServices[$service].CheckCommand -Arguments $RegisteredServices[$service].Arguments -Interval $RegisteredServices[$service].Interval -TimeIndexes $RegisteredServices[$service].TimeIndexes;
42+
[hashtable]$ServiceArgs = @{ };
43+
44+
if ($null -ne $RegisteredServices[$service].Arguments) {
45+
foreach ($property in $RegisteredServices[$service].Arguments.PSObject.Properties) {
46+
if ($ServiceArgs.ContainsKey($property.Name)) {
47+
continue;
48+
}
49+
50+
$ServiceArgs.Add($property.Name, $property.Value)
51+
}
52+
}
53+
54+
Start-IcingaServiceCheckTask -CheckId $service -CheckCommand $RegisteredServices[$service].CheckCommand -Arguments $ServiceArgs -Interval $RegisteredServices[$service].Interval -TimeIndexes $RegisteredServices[$service].TimeIndexes;
4355
}
4456
Start-Sleep -Seconds 1;
4557
}

lib/icinga/plugin/New-IcingaCheckBaseObject.psm1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ function New-IcingaCheckBaseObject()
2525
}
2626
}
2727

28+
if ([string]::IsNullOrEmpty($this.__CheckCommand)) {
29+
return;
30+
}
31+
2832
if ($null -eq $Global:Icinga) {
2933
$Global:Icinga = @{ };
3034
}
@@ -33,14 +37,15 @@ function New-IcingaCheckBaseObject()
3337
$Global:Icinga.Add('ThresholdCache', @{ });
3438
}
3539

36-
if ($Global:Icinga.ThresholdCache.ContainsKey($this.__CheckCommand)) {
40+
if ($Global:Icinga.ThresholdCache.ContainsKey($this.__CheckCommand) -eq $FALSE) {
41+
$Global:Icinga.ThresholdCache.Add($this.__CheckCommand, $null);
42+
}
43+
44+
if ($null -ne $Global:Icinga.ThresholdCache[$this.__CheckCommand]) {
3745
return;
3846
}
3947

40-
$Global:Icinga.ThresholdCache.Add(
41-
$this.__CheckCommand,
42-
(Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $this.__CheckCommand)
43-
);
48+
$Global:Icinga.ThresholdCache[$this.__CheckCommand] = (Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $this.__CheckCommand);
4449
}
4550

4651
$IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetParent' -Value {

0 commit comments

Comments
 (0)