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 {
|
2022-05-24 10:44:52 -04:00
|
|
|
# Always ensure our cache is cleared before compiling new check data
|
|
|
|
|
Get-IcingaCheckSchedulerPluginOutput | Out-Null;
|
|
|
|
|
Get-IcingaCheckSchedulerPerfData | Out-Null;
|
|
|
|
|
|
2021-05-07 08:38: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
|
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
|
2021-09-06 09:30:23 -04:00
|
|
|
$CheckCommand = $this.Check.__GetCheckCommand();
|
2021-12-09 11:42:06 -05:00
|
|
|
if ([string]::IsNullOrEmpty($CheckCommand) -eq $FALSE -And $Global:Icinga.Private.Scheduler.ThresholdCache.ContainsKey($CheckCommand)) {
|
|
|
|
|
$Global:Icinga.Private.Scheduler.ThresholdCache[$CheckCommand] = $null;
|
2021-09-06 09:30:23 -04:00
|
|
|
}
|
2021-07-15 09:37:53 -04:00
|
|
|
# Reset the current execution date
|
2021-09-06 09:30:23 -04:00
|
|
|
$Global:Icinga.CurrentDate = $null;
|
2021-05-07 08:38:10 -04:00
|
|
|
|
2021-07-16 05:31:41 -04:00
|
|
|
$ExitCode = $this.Check.__GetCheckState();
|
|
|
|
|
|
|
|
|
|
Set-IcingaInternalPluginExitCode -ExitCode $ExitCode;
|
|
|
|
|
|
|
|
|
|
return $ExitCode;
|
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
|
|
|
}
|