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

52 lines
1.7 KiB
PowerShell
Raw Normal View History

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 {
# 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-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
$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;
}
# Reset the current execution date
$Global:Icinga.CurrentDate = $null;
2021-05-07 08:38:10 -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
}