2019-07-18 11:54:39 -04:00
|
|
|
Import-IcingaLib icinga\enums;
|
|
|
|
|
|
|
|
|
|
function New-IcingaCheckresult()
|
|
|
|
|
{
|
2019-07-19 13:38:09 -04:00
|
|
|
param(
|
|
|
|
|
$Check,
|
2019-07-22 07:16:14 -04:00
|
|
|
[bool]$NoPerfData,
|
2019-07-19 13:38:09 -04:00
|
|
|
[switch]$Compile
|
|
|
|
|
);
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
$CheckResult = New-Object -TypeName PSObject;
|
|
|
|
|
$CheckResult | Add-Member -membertype NoteProperty -name 'check' -value $Check;
|
|
|
|
|
$CheckResult | Add-Member -membertype NoteProperty -name 'noperfdata' -value $NoPerfData;
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
$CheckResult | Add-Member -membertype ScriptMethod -name 'Compile' -value {
|
2019-07-24 11:21:10 -04:00
|
|
|
if ($null -eq $this.check) {
|
2019-07-19 13:38:09 -04:00
|
|
|
return $IcingaEnums.IcingaExitCode.Unknown;
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
# Compile the check / package if not already done
|
2019-07-22 12:01:12 -04:00
|
|
|
$this.check.Compile($TRUE) | Out-Null;
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2019-07-22 03:02:33 -04:00
|
|
|
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
|
2019-07-19 14:02:41 -04:00
|
|
|
Write-Host ([string]::Format('| {0}', $this.check.GetPerfData()));
|
|
|
|
|
}
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
return $this.check.exitcode;
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
if ($Compile) {
|
|
|
|
|
return $CheckResult.Compile();
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
return $CheckResult;
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|