mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
* Added proper sorting for checks, packages and check results by name * Fixed perf data formating to be supported by Icinga 2 * Fixed label naming by removing all invalid characters * Fixed displaying of values by rounding to 2 digits on floats
35 lines
1 KiB
PowerShell
35 lines
1 KiB
PowerShell
Import-IcingaLib icinga\enums;
|
|
|
|
function New-IcingaCheckresult()
|
|
{
|
|
param(
|
|
$Check,
|
|
[bool]$NoPerfData,
|
|
[switch]$Compile
|
|
);
|
|
|
|
$CheckResult = New-Object -TypeName PSObject;
|
|
$CheckResult | Add-Member -membertype NoteProperty -name 'check' -value $Check;
|
|
$CheckResult | Add-Member -membertype NoteProperty -name 'noperfdata' -value $NoPerfData;
|
|
|
|
$CheckResult | Add-Member -membertype ScriptMethod -name 'Compile' -value {
|
|
if ($null -eq $this.check) {
|
|
return $IcingaEnums.IcingaExitCode.Unknown;
|
|
}
|
|
|
|
# Compile the check / package if not already done
|
|
$this.check.Compile($TRUE) | Out-Null;
|
|
|
|
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
|
|
Write-Host ([string]::Format('| {0}', $this.check.GetPerfData().perfdata));
|
|
}
|
|
|
|
return $this.check.exitcode;
|
|
}
|
|
|
|
if ($Compile) {
|
|
return $CheckResult.Compile();
|
|
}
|
|
|
|
return $CheckResult;
|
|
}
|