Check Packages will now return Unknown if no check is assigned

This commit is contained in:
Lord Hepipud 2019-07-24 13:01:50 +02:00
parent 5840e0ca05
commit 9b46d63fd0

View file

@ -70,33 +70,37 @@ function New-IcingaCheckPackage()
return; return;
} }
if ($this.opand) { if ($this.checks.Count -ne 0) {
if ($this.CheckAllOk() -eq $FALSE) { if ($this.opand) {
$this.GetWorstExitCode(); if ($this.CheckAllOk() -eq $FALSE) {
} $this.GetWorstExitCode();
} elseif($this.opor) { }
if ($this.CheckOneOk() -eq $FALSE) { } elseif($this.opor) {
$this.GetWorstExitCode(); if ($this.CheckOneOk() -eq $FALSE) {
} $this.GetWorstExitCode();
} elseif($this.opnone) { }
if ($this.CheckOneOk() -eq $TRUE) { } elseif($this.opnone) {
$this.GetWorstExitCode(); if ($this.CheckOneOk() -eq $TRUE) {
$this.exitcode = $IcingaEnums.IcingaExitCode.Critical; $this.GetWorstExitCode();
} else { $this.exitcode = $IcingaEnums.IcingaExitCode.Critical;
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok; } else {
} $this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
} elseif([int]$this.opmin -ne -1) { }
if ($this.CheckMinimumOk() -eq $FALSE) { } elseif([int]$this.opmin -ne -1) {
$this.GetWorstExitCode(); if ($this.CheckMinimumOk() -eq $FALSE) {
} else { $this.GetWorstExitCode();
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok; } else {
} $this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
} elseif([int]$this.opmax -ne -1) { }
if ($this.CheckMaximumOk() -eq $FALSE) { } elseif([int]$this.opmax -ne -1) {
$this.GetWorstExitCode(); if ($this.CheckMaximumOk() -eq $FALSE) {
} else { $this.GetWorstExitCode();
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok; } else {
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
}
} }
} else {
$this.exitcode = $IcingaEnums.IcingaExitCode.Unknown;
} }
if ([int]$this.exitcode -eq -1) { if ([int]$this.exitcode -eq -1) {
@ -219,6 +223,20 @@ function New-IcingaCheckPackage()
} }
} }
$Check | Add-Member -membertype ScriptMethod -name 'PrintNoChecksConfigured' -value {
if ($this.checks.Count -eq 0) {
Write-Host (
[string]::Format(
'{0}{1}: No checks configured for package "{2}"',
(New-StringTree ($this.spacing + 1)),
$IcingaEnums.IcingaExitCodeText.($this.exitcode),
$this.name
)
)
return;
}
}
$Check | Add-Member -membertype ScriptMethod -name 'WritePackageOutputStatus' -value { $Check | Add-Member -membertype ScriptMethod -name 'WritePackageOutputStatus' -value {
[string]$outputMessage = '{0}{1}: Check package "{2}" is {1}'; [string]$outputMessage = '{0}{1}: Check package "{2}" is {1}';
if ($this.verbose -ne 0) { if ($this.verbose -ne 0) {
@ -252,14 +270,17 @@ function New-IcingaCheckPackage()
} }
} }
$this.WritePackageOutputStatus(); $this.WritePackageOutputStatus();
if ($printAll) { if ($printAll) {
$this.WriteAllOutput(); $this.WriteAllOutput();
$this.PrintNoChecksConfigured();
} elseif ($printDetails) { } elseif ($printDetails) {
# Now print Non-Ok Check outputs in case our package is not Ok # Now print Non-Ok Check outputs in case our package is not Ok
if ([int]$this.exitcode -ne $IcingaEnums.IcingaExitCode.Ok) { if ([int]$this.exitcode -ne $IcingaEnums.IcingaExitCode.Ok) {
$this.WriteCheckErrors(); $this.WriteCheckErrors();
$this.PrintNoChecksConfigured();
} }
} }
} }