mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge branch 'testing' of https://github.com/LordHepipud/icinga-module-windows into testing
This commit is contained in:
commit
6aa72e4930
3 changed files with 83 additions and 28 deletions
|
|
@ -9,6 +9,8 @@ function New-IcingaCheck()
|
|||
$Unit = $null,
|
||||
[string]$Minimum = '',
|
||||
[string]$Maximum = '',
|
||||
$ObjectExists = -1,
|
||||
$Translation = $null,
|
||||
[switch]$NoPerfData
|
||||
);
|
||||
|
||||
|
|
@ -30,6 +32,8 @@ function New-IcingaCheck()
|
|||
$Check | Add-Member -membertype NoteProperty -name 'critical' -value '';
|
||||
$Check | Add-Member -membertype NoteProperty -name 'minimum' -value $Minimum;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'maximum' -value $Maximum;
|
||||
$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 'completed' -value $FALSE;
|
||||
|
||||
|
|
@ -401,13 +405,49 @@ function New-IcingaCheck()
|
|||
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 {
|
||||
param($state, $value, $type);
|
||||
|
||||
$this.SetExitCode($state);
|
||||
if ($this.objectexists -ne -1 -And $null -eq $this.objectexists) {
|
||||
$this.SetExitCode($IcingaEnums.IcingaExitCode.Unknown);
|
||||
$this.AddMessage([string]::Format(
|
||||
'{0} {1}{4} is {2} {3}{4}', $this.name, $this.value, $type, $value, $this.unit
|
||||
), $state);
|
||||
'{0} does not exist', $this.name
|
||||
), $IcingaEnums.IcingaExitCode.Unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
$this.SetExitCode($state);
|
||||
$this.AddMessage(
|
||||
[string]::Format(
|
||||
'{0} {1}{4} is {2} {3}{4}',
|
||||
$this.name,
|
||||
$this.TranslateValue($this.value),
|
||||
$type,
|
||||
$this.TranslateValue($value),
|
||||
$this.unit
|
||||
),
|
||||
$state
|
||||
);
|
||||
|
||||
switch ($state) {
|
||||
$IcingaEnums.IcingaExitCode.Warning {
|
||||
|
|
@ -552,7 +592,15 @@ function New-IcingaCheck()
|
|||
$Check | Add-Member -membertype ScriptMethod -name 'AddOkOutput' -value {
|
||||
if ([int]$this.exitcode -eq -1) {
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function New-IcingaCheckresult()
|
|||
$CheckResult | Add-Member -membertype NoteProperty -name 'noperfdata' -value $NoPerfData;
|
||||
|
||||
$CheckResult | Add-Member -membertype ScriptMethod -name 'Compile' -value {
|
||||
if ($this.check -eq $null) {
|
||||
if ($null -eq $this.check) {
|
||||
return $IcingaEnums.IcingaExitCode.Unknown;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,20 @@ function Invoke-IcingaCheckProcessCount()
|
|||
|
||||
$ProcessPackage = New-icingaCheckPackage -Name "Process Check" -OperatorAnd -Verbose $Verbose -NoPerfData $NoPerfData;
|
||||
|
||||
if ($Process.Count -eq 0) {
|
||||
$ProcessCount = $ProcessInformation['Process Count'];
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Process Count')) -Value $ProcessCount;
|
||||
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
$ProcessPackage.AddCheck($IcingaCheck);
|
||||
} else {
|
||||
foreach ($proc in $process) {
|
||||
$ProcessCount = $ProcessInformation."Processes".$proc.processlist.Count;
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Process Count "{0}"', $proc)) -Value $ProcessCount;
|
||||
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
$ProcessPackage.AddCheck($IcingaCheck);
|
||||
}
|
||||
|
||||
|
||||
exit (New-IcingaCheckResult -Check $ProcessPackage -NoPerfData $TRUE -Compile);
|
||||
}
|
||||
|
||||
|
||||
exit (New-IcingaCheckResult -Check $ProcessPackage -NoPerfData $NoPerfData -Compile);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue