Adds support to set check state by function call

This commit is contained in:
Lord Hepipud 2020-05-19 17:30:50 +02:00
parent 7860818be1
commit c4179338a1

View file

@ -94,6 +94,22 @@ function New-IcingaCheck()
return $this.unknownchecks; return $this.unknownchecks;
} }
$Check | Add-Member -membertype ScriptMethod -name 'SetUnknown' -value {
$this.AddInternalCheckMessage(
$IcingaEnums.IcingaExitCode.Unknown,
$null,
$null
);
}
$Check | Add-Member -membertype ScriptMethod -name 'SetWarning' -value {
$this.AddInternalCheckMessage(
$IcingaEnums.IcingaExitCode.Warning,
$null,
$null
);
}
$Check | Add-Member -membertype ScriptMethod -name 'WarnOutOfRange' -value { $Check | Add-Member -membertype ScriptMethod -name 'WarnOutOfRange' -value {
param($warning); param($warning);
@ -296,6 +312,14 @@ function New-IcingaCheck()
return $this; return $this;
} }
$Check | Add-Member -membertype ScriptMethod -name 'SetCritical' -value {
$this.AddInternalCheckMessage(
$IcingaEnums.IcingaExitCode.Critical,
$null,
$null
);
}
$Check | Add-Member -membertype ScriptMethod -name 'CritOutOfRange' -value { $Check | Add-Member -membertype ScriptMethod -name 'CritOutOfRange' -value {
param($critical); param($critical);
@ -534,17 +558,25 @@ function New-IcingaCheck()
} }
$this.SetExitCode($state); $this.SetExitCode($state);
$this.AddMessage(
[string]::Format( if ($null -eq $value -And $null -eq $type) {
'{0}: Value "{1}{4}" is {2} threshold "{3}{4}"', $this.AddMessage(
$this.name, $this.name,
$this.TranslateValue($this.value), $state
$type, );
$this.TranslateValue($value), } else {
$this.unit $this.AddMessage(
), [string]::Format(
$state '{0}: Value "{1}{4}" is {2} threshold "{3}{4}"',
); $this.name,
$this.TranslateValue($this.value),
$type,
$this.TranslateValue($value),
$this.unit
),
$state
);
}
switch ($state) { switch ($state) {
$IcingaEnums.IcingaExitCode.Warning { $IcingaEnums.IcingaExitCode.Warning {