From 9f423d060f4c186baf5df452a99abc9808cb50fb Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 30 Jun 2021 11:27:36 +0200 Subject: [PATCH] Fixes service daemon not working with arguments --- doc/31-Changelog.md | 1 + .../Start-IcingaServiceCheckDaemon.psm1 | 14 +++++++++++++- lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 | 15 ++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 2ca9459..60c01a8 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -22,6 +22,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#284](https://github.com/Icinga/icinga-powershell-framework/issues/284) Fixes exception while creating default threshold objects * [#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 * [#293](https://github.com/Icinga/icinga-powershell-framework/pull/293) Fixes crash on REST-Api for NULL values while parsing the REST message +* [#295](https://github.com/Icinga/icinga-powershell-framework/issues/295) Fixes background service check daemon not working with arguments for plugins ## 1.5.0 (2021-06-02) diff --git a/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 b/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 index a58a06a..f650892 100644 --- a/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 @@ -39,7 +39,19 @@ function Start-IcingaServiceCheckDaemon() continue; } - Start-IcingaServiceCheckTask -CheckId $service -CheckCommand $RegisteredServices[$service].CheckCommand -Arguments $RegisteredServices[$service].Arguments -Interval $RegisteredServices[$service].Interval -TimeIndexes $RegisteredServices[$service].TimeIndexes; + [hashtable]$ServiceArgs = @{ }; + + if ($null -ne $RegisteredServices[$service].Arguments) { + foreach ($property in $RegisteredServices[$service].Arguments.PSObject.Properties) { + if ($ServiceArgs.ContainsKey($property.Name)) { + continue; + } + + $ServiceArgs.Add($property.Name, $property.Value) + } + } + + Start-IcingaServiceCheckTask -CheckId $service -CheckCommand $RegisteredServices[$service].CheckCommand -Arguments $ServiceArgs -Interval $RegisteredServices[$service].Interval -TimeIndexes $RegisteredServices[$service].TimeIndexes; } Start-Sleep -Seconds 1; } diff --git a/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 b/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 index 99048f4..76faf06 100644 --- a/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 +++ b/lib/icinga/plugin/New-IcingaCheckBaseObject.psm1 @@ -25,6 +25,10 @@ function New-IcingaCheckBaseObject() } } + if ([string]::IsNullOrEmpty($this.__CheckCommand)) { + return; + } + if ($null -eq $Global:Icinga) { $Global:Icinga = @{ }; } @@ -33,14 +37,15 @@ function New-IcingaCheckBaseObject() $Global:Icinga.Add('ThresholdCache', @{ }); } - if ($Global:Icinga.ThresholdCache.ContainsKey($this.__CheckCommand)) { + if ($Global:Icinga.ThresholdCache.ContainsKey($this.__CheckCommand) -eq $FALSE) { + $Global:Icinga.ThresholdCache.Add($this.__CheckCommand, $null); + } + + if ($null -ne $Global:Icinga.ThresholdCache[$this.__CheckCommand]) { return; } - $Global:Icinga.ThresholdCache.Add( - $this.__CheckCommand, - (Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $this.__CheckCommand) - ); + $Global:Icinga.ThresholdCache[$this.__CheckCommand] = (Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $this.__CheckCommand); } $IcingaCheckBaseObject | Add-Member -MemberType ScriptMethod -Name '__SetParent' -Value {