2019-07-24 04:01:34 -04:00
|
|
|
Import-IcingaLib provider\services;
|
2019-07-24 08:28:53 -04:00
|
|
|
Import-IcingaLib provider\enums;
|
2019-07-24 04:01:34 -04:00
|
|
|
Import-IcingaLib icinga\plugin;
|
|
|
|
|
|
|
|
|
|
function Invoke-IcingaCheckService()
|
|
|
|
|
{
|
|
|
|
|
param(
|
2019-09-13 08:29:38 -04:00
|
|
|
[array]$Service,
|
2019-07-24 04:01:34 -04:00
|
|
|
[string]$Status,
|
2019-09-13 08:29:38 -04:00
|
|
|
[int]$Verbose
|
2019-07-24 04:01:34 -04:00
|
|
|
);
|
|
|
|
|
|
2019-09-13 08:29:38 -04:00
|
|
|
$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 {
|
|
|
|
|
|
2019-07-24 04:01:34 -04:00
|
|
|
$FoundService = Get-IcingaServices -Service $Service;
|
2019-07-24 08:28:53 -04:00
|
|
|
$ServiceName = Get-IcingaServiceCheckName -ServiceInput $Service -Service $FoundService;
|
2019-07-24 05:44:33 -04:00
|
|
|
$Status = ConvertTo-ServiceStatusCode -Status $Status;
|
2019-07-24 04:01:34 -04:00
|
|
|
$StatusRaw = $FoundService.Values.configuration.Status.raw;
|
|
|
|
|
|
2019-07-24 08:28:53 -04:00
|
|
|
$IcingaCheck = New-IcingaCheck -Name $ServiceName -Value $StatusRaw -ObjectExists $FoundService -Translation $ProviderEnums.ServiceStatusName;
|
2019-07-24 04:01:34 -04:00
|
|
|
$IcingaCheck.CritIfNotMatch($Status) | Out-Null;
|
2019-09-13 08:29:38 -04:00
|
|
|
$ServicesPackage.AddCheck($IcingaCheck);
|
2019-07-24 04:01:34 -04:00
|
|
|
|
2019-09-13 08:29:38 -04:00
|
|
|
}
|
|
|
|
|
exit (New-IcingaCheckResult -Name 'Services' -Check $ServicesPackage -NoPerfData $TRUE -Compile);
|
2019-07-24 04:01:34 -04:00
|
|
|
}
|