icinga-powershell-framework/lib/icinga/checkresult/New-IcingaCheckResult.psm1
2019-07-19 19:38:09 +02:00

33 lines
877 B
PowerShell

Import-IcingaLib icinga\enums;
function New-IcingaCheckresult()
{
param(
$Check,
[switch]$NoPerfData,
[switch]$Compile
);
$CheckResult = New-Object -TypeName PSObject;
$CheckResult | Add-Member -membertype NoteProperty -name 'check' -value $Check;
$CheckResult | Add-Member -membertype NoteProperty -name 'noperfdata' -value $NoPerfData;
$CheckResult | Add-Member -membertype ScriptMethod -name 'Compile' -value {
if ($this.check -eq $null) {
return $IcingaEnums.IcingaExitCode.Unknown;
}
# Compile the check / package if not already done
$this.check.Compile();
Write-Host ([string]::Format('| {0}', $this.check.GetPerfData()));
return $this.check.exitcode;
}
if ($Compile) {
return $CheckResult.Compile();
}
return $CheckResult;
}