mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Added support to translate check values to speaking values on output
This commit is contained in:
parent
318966e392
commit
c37a6cbfe2
1 changed files with 42 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ function New-IcingaCheck()
|
||||||
[string]$Minimum = '',
|
[string]$Minimum = '',
|
||||||
[string]$Maximum = '',
|
[string]$Maximum = '',
|
||||||
$ObjectExists = -1,
|
$ObjectExists = -1,
|
||||||
|
$Translation = $null,
|
||||||
[switch]$NoPerfData
|
[switch]$NoPerfData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ function New-IcingaCheck()
|
||||||
$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 'objectexists' -value $ObjectExists;
|
||||||
|
$Check | Add-Member -membertype NoteProperty -name 'translation' -value $Translation;
|
||||||
$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;
|
||||||
|
|
||||||
|
|
@ -403,6 +405,26 @@ function New-IcingaCheck()
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Check | Add-Member -membertype ScriptMethod -name 'TranslateValue' -value {
|
||||||
|
param($value);
|
||||||
|
|
||||||
|
if ($null -eq $this.translation -Or $null -eq $value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkValue = $value;
|
||||||
|
|
||||||
|
if ((Test-Numeric $checkValue)) {
|
||||||
|
$checkValue = [int]$checkValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this.translation.ContainsKey($checkValue)) {
|
||||||
|
return $this.translation[$checkValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
$Check | Add-Member -membertype ScriptMethod -name 'AddInternalCheckMessage' -value {
|
$Check | Add-Member -membertype ScriptMethod -name 'AddInternalCheckMessage' -value {
|
||||||
param($state, $value, $type);
|
param($state, $value, $type);
|
||||||
|
|
||||||
|
|
@ -415,9 +437,17 @@ function New-IcingaCheck()
|
||||||
}
|
}
|
||||||
|
|
||||||
$this.SetExitCode($state);
|
$this.SetExitCode($state);
|
||||||
$this.AddMessage([string]::Format(
|
$this.AddMessage(
|
||||||
'{0} {1}{4} is {2} {3}{4}', $this.name, $this.value, $type, $value, $this.unit
|
[string]::Format(
|
||||||
), $state);
|
'{0} {1}{4} is {2} {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 {
|
||||||
|
|
@ -562,7 +592,15 @@ function New-IcingaCheck()
|
||||||
$Check | Add-Member -membertype ScriptMethod -name 'AddOkOutput' -value {
|
$Check | Add-Member -membertype ScriptMethod -name 'AddOkOutput' -value {
|
||||||
if ([int]$this.exitcode -eq -1) {
|
if ([int]$this.exitcode -eq -1) {
|
||||||
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
|
$this.exitcode = $IcingaEnums.IcingaExitCode.Ok;
|
||||||
$this.AddMessage([string]::Format('{0} is {1}{2}', $this.name, $this.value, $this.unit), $IcingaEnums.IcingaExitCode.Ok);
|
$this.AddMessage(
|
||||||
|
[string]::Format(
|
||||||
|
'{0} is {1}{2}',
|
||||||
|
$this.name,
|
||||||
|
$this.TranslateValue($this.value),
|
||||||
|
$this.unit
|
||||||
|
),
|
||||||
|
$IcingaEnums.IcingaExitCode.Ok
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue