icinga-powershell-framework/lib/icinga/plugin/New-IcingaCheckResult.psm1

36 lines
1,013 B
PowerShell
Raw Normal View History

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,
[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 {
if ($this.check -eq $null) {
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-19 14:01:15 -04:00
$this.check.Compile() | Out-Null;
2019-07-18 11:54:39 -04:00
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
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
}