From 72db17da305802bc3d3df61e4f5f5946269e5a5f Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 19 Dec 2022 10:44:23 +0100 Subject: [PATCH] Fixes invalid perf data for service plugin --- doc/31-Changelog.md | 4 ++++ plugins/Invoke-IcingaCheckService.psm1 | 7 ++++++- provider/private/services/Add-IcingaServiceSummary.psm1 | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index dd4d3efe..19465016 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -9,6 +9,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ## 1.10.1 (2022-12-20) +### Bugfixes + +* [#323](https://github.com/Icinga/icinga-powershell-plugins/issues/323) Fixes `Invoke-IcingaCheckService` to write invalid performance data in case one service is actively checked and returning `UNKNOWN` because it does not exist + ### Enhancements * [#322](https://github.com/Icinga/icinga-powershell-plugins/issues/322) Adds flag `-IgnoreService` for plugin `Invoke-IcingaCheckTimeSync` to ignore the time service being evaluated during check runtime diff --git a/plugins/Invoke-IcingaCheckService.psm1 b/plugins/Invoke-IcingaCheckService.psm1 index fe44fbbf..b71757bc 100644 --- a/plugins/Invoke-IcingaCheckService.psm1 +++ b/plugins/Invoke-IcingaCheckService.psm1 @@ -138,6 +138,11 @@ function Invoke-IcingaCheckService() } } + # Fix invalid performance data in case only one service was checked and the service does not exist + if ($null -eq $ServiceSummary) { + $ServiceSummary = Add-IcingaServiceSummary; + } + # Check our included services and add an unknown state for each service which was not found on the system foreach ($ServiceArg in $Service) { if ($null -eq $FetchedServices -Or $FetchedServices.ContainsKey($ServiceArg) -eq $FALSE) { @@ -163,7 +168,7 @@ function Invoke-IcingaCheckService() } $ServicesPackage.AddCheck( - (New-IcingaCheck -Name ([string]::Format('{0}: Service not found', $ServiceArg))).SetUnknown() + (New-IcingaCheck -Name ([string]::Format('{0}: Service not found', $ServiceArg)) -NoPerfData).SetUnknown() ); } } diff --git a/provider/private/services/Add-IcingaServiceSummary.psm1 b/provider/private/services/Add-IcingaServiceSummary.psm1 index 89a72d6e..b8d24238 100644 --- a/provider/private/services/Add-IcingaServiceSummary.psm1 +++ b/provider/private/services/Add-IcingaServiceSummary.psm1 @@ -52,7 +52,7 @@ function Add-IcingaServiceSummary() } } - switch($ServiceStatus) { + switch ($ServiceStatus) { $ProviderEnums.ServiceStatus.Stopped { $ServiceData.StoppedCount += 1; };