Changed Invoke-IcingaCheckService.psm1 to support multiple inputs

This commit is contained in:
Crited 2019-09-13 14:29:38 +02:00
parent d7fdeba915
commit 95ea8cf28f

View file

@ -5,10 +5,28 @@ Import-IcingaLib icinga\plugin;
function Invoke-IcingaCheckService() function Invoke-IcingaCheckService()
{ {
param( param(
[array]$Service,
[string]$Status, [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; $FoundService = Get-IcingaServices -Service $Service;
$ServiceName = Get-IcingaServiceCheckName -ServiceInput $Service -Service $FoundService; $ServiceName = Get-IcingaServiceCheckName -ServiceInput $Service -Service $FoundService;
$Status = ConvertTo-ServiceStatusCode -Status $Status; $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 = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName;
$IcingaCheck.CritIfNotMatch($Status) | Out-Null; $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);
} }