2021-05-07 08:38:10 -04:00
|
|
|
function New-IcingaCheckResult()
|
2019-07-18 11:54:39 -04:00
|
|
|
{
|
2021-05-07 08:38:10 -04:00
|
|
|
param (
|
2019-07-19 13:38:09 -04:00
|
|
|
$Check,
|
2021-05-07 08:38:10 -04:00
|
|
|
[bool]$NoPerfData = $FALSE,
|
|
|
|
|
[switch]$Compile = $FALSE
|
2019-07-19 13:38:09 -04:00
|
|
|
);
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2021-05-07 08:38:10 -04:00
|
|
|
$IcingaCheckResult = New-Object -TypeName PSObject;
|
|
|
|
|
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'Check' -Value $Check;
|
|
|
|
|
$IcingaCheckResult | Add-Member -MemberType NoteProperty -Name 'NoPerfData' -Value $NoPerfData;
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2021-05-07 08:38:10 -04:00
|
|
|
$IcingaCheckResult | Add-Member -MemberType ScriptMethod -Name 'Compile' -Value {
|
|
|
|
|
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
|
2021-05-07 08:38:10 -04:00
|
|
|
$this.Check.Compile();
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2021-05-07 08:38:10 -04:00
|
|
|
Write-IcingaPluginOutput -Output ($this.Check.__GetCheckOutput());
|
|
|
|
|
|
|
|
|
|
if ($this.NoPerfData -eq $FALSE) {
|
|
|
|
|
Write-IcingaPluginPerfData -IcingaCheck $this.Check;
|
2019-07-19 14:02:41 -04:00
|
|
|
}
|
2019-07-18 11:54:39 -04:00
|
|
|
|
2021-05-07 08:38:10 -04:00
|
|
|
# Ensure we reset our internal cache once the plugin was executed
|
|
|
|
|
$Global:Icinga.ThresholdCache[$this.Check.__GetCheckCommand()] = $null;
|
|
|
|
|
|
|
|
|
|
return $this.Check.__GetCheckState();
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-19 13:38:09 -04:00
|
|
|
if ($Compile) {
|
2021-05-07 08:38:10 -04:00
|
|
|
return $IcingaCheckResult.Compile();
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-07 08:38:10 -04:00
|
|
|
return $IcingaCheckResult;
|
2019-07-18 11:54:39 -04:00
|
|
|
}
|