Added support to check if objects exist on icinga checks

This commit is contained in:
Lord Hepipud 2019-07-24 17:10:16 +02:00
parent 521ed5eb09
commit d3862eccdb

View file

@ -9,6 +9,7 @@ function New-IcingaCheck()
$Unit = $null, $Unit = $null,
[string]$Minimum = '', [string]$Minimum = '',
[string]$Maximum = '', [string]$Maximum = '',
$ObjectExists = -1,
[switch]$NoPerfData [switch]$NoPerfData
); );
@ -30,6 +31,7 @@ function New-IcingaCheck()
$Check | Add-Member -membertype NoteProperty -name 'critical' -value ''; $Check | Add-Member -membertype NoteProperty -name 'critical' -value '';
$Check | Add-Member -membertype NoteProperty -name 'minimum' -value $Minimum; $Check | Add-Member -membertype NoteProperty -name 'minimum' -value $Minimum;
$Check | Add-Member -membertype NoteProperty -name 'maximum' -value $Maximum; $Check | Add-Member -membertype NoteProperty -name 'maximum' -value $Maximum;
$Check | Add-Member -membertype NoteProperty -name 'objectexists' -value $ObjectExists;
$Check | Add-Member -membertype NoteProperty -name 'checks' -value $null; $Check | Add-Member -membertype NoteProperty -name 'checks' -value $null;
$Check | Add-Member -membertype NoteProperty -name 'completed' -value $FALSE; $Check | Add-Member -membertype NoteProperty -name 'completed' -value $FALSE;
@ -404,6 +406,14 @@ function New-IcingaCheck()
$Check | Add-Member -membertype ScriptMethod -name 'AddInternalCheckMessage' -value { $Check | Add-Member -membertype ScriptMethod -name 'AddInternalCheckMessage' -value {
param($state, $value, $type); param($state, $value, $type);
if ($this.objectexists -ne -1 -And $null -eq $this.objectexists) {
$this.SetExitCode($IcingaEnums.IcingaExitCode.Unknown);
$this.AddMessage([string]::Format(
'{0} does not exist', $this.name
), $IcingaEnums.IcingaExitCode.Unknown);
return;
}
$this.SetExitCode($state); $this.SetExitCode($state);
$this.AddMessage([string]::Format( $this.AddMessage([string]::Format(
'{0} {1}{4} is {2} {3}{4}', $this.name, $this.value, $type, $value, $this.unit '{0} {1}{4} is {2} {3}{4}', $this.name, $this.value, $type, $value, $this.unit