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;
|
2020-08-04 08:48:32 -04:00
|
|
|
$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
|
|
|
|
2020-08-04 08:48:32 -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-10-05 15:59:37 -04:00
|
|
|
$CheckCommand = (Get-PSCallStack)[2].Command;
|
2019-09-28 15:45:59 -04:00
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
# Compile the check / package if not already done
|
2019-09-28 15:45:59 -04:00
|
|
|
$this.check.AssignCheckCommand($CheckCommand);
|
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-11-05 06:39:54 -05:00
|
|
|
Write-IcingaPluginPerfData -PerformanceData ($this.check.GetPerfData()) -CheckCommand $CheckCommand;
|
2019-07-19 14:02:41 -04:00
|
|
|
}
|
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
|
|
|
}
|