From 95ea8cf28f107b3a89dca201696ad7415d496ee0 Mon Sep 17 00:00:00 2001 From: Crited Date: Fri, 13 Sep 2019 14:29:38 +0200 Subject: [PATCH] Changed Invoke-IcingaCheckService.psm1 to support multiple inputs --- lib/plugins/Invoke-IcingaCheckService.psm1 | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/plugins/Invoke-IcingaCheckService.psm1 b/lib/plugins/Invoke-IcingaCheckService.psm1 index 86cc058..2d86bb1 100644 --- a/lib/plugins/Invoke-IcingaCheckService.psm1 +++ b/lib/plugins/Invoke-IcingaCheckService.psm1 @@ -5,10 +5,28 @@ Import-IcingaLib icinga\plugin; function Invoke-IcingaCheckService() { param( + [array]$Service, [string]$Status, - [string]$Service + [int]$Verbose ); + $ServicesPackage = New-IcingaCheckPackage -Name 'Services' -OperatorAnd -Verbose $Verbose; + + if ($Service.Count -ne 1) { + foreach ($services in $Service) { + $IcingaCheck = $null; + + $FoundService = Get-IcingaServices -Service $services; + $ServiceName = Get-IcingaServiceCheckName -ServiceInput $services -Service $FoundService; + $ConvertedStatus = ConvertTo-ServiceStatusCode -Status $Status; + $StatusRaw = $FoundService.Values.configuration.Status.raw; + + $IcingaCheck = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName; + $IcingaCheck.CritIfNotMatch($ConvertedStatus) | Out-Null; + $ServicesPackage.AddCheck($IcingaCheck) + } + } else { + $FoundService = Get-IcingaServices -Service $Service; $ServiceName = Get-IcingaServiceCheckName -ServiceInput $Service -Service $FoundService; $Status = ConvertTo-ServiceStatusCode -Status $Status; @@ -16,6 +34,8 @@ function Invoke-IcingaCheckService() $IcingaCheck = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName; $IcingaCheck.CritIfNotMatch($Status) | Out-Null; + $ServicesPackage.AddCheck($IcingaCheck); - exit (New-IcingaCheckResult -Check $IcingaCheck -NoPerfData $TRUE -Compile); + } + exit (New-IcingaCheckResult -Name 'Services' -Check $ServicesPackage -NoPerfData $TRUE -Compile); }