mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Prepared check plugin and perf-data output for daemon integration
This commit is contained in:
parent
5499ff399b
commit
13a54bd117
5 changed files with 92 additions and 23 deletions
|
|
@ -36,11 +36,18 @@ function New-IcingaCheck()
|
|||
$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;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'checkcommand' -value '';
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'AddSpacing' -value {
|
||||
$this.spacing += 1;
|
||||
}
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'AssignCheckCommand' -value {
|
||||
param($CheckCommand);
|
||||
|
||||
$this.checkcommand = $CheckCommand;
|
||||
}
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'WarnOutOfRange' -value {
|
||||
param($warning);
|
||||
|
||||
|
|
@ -525,7 +532,7 @@ function New-IcingaCheck()
|
|||
param($msgArray, [string]$spaces);
|
||||
|
||||
foreach ($msg in $msgArray) {
|
||||
Write-Host ([string]::Format('{0}{1}', $spaces, $msg));
|
||||
Write-IcingaPluginOutput ([string]::Format('{0}{1}', $spaces, $msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -651,8 +658,8 @@ function New-IcingaCheck()
|
|||
[string]$LabelName = (Format-IcingaPerfDataLabel $this.name);
|
||||
|
||||
return @{
|
||||
'label' = $LabelName;
|
||||
'perfdata' = [string]::Format(
|
||||
'label' = $LabelName;
|
||||
'perfdata' = [string]::Format(
|
||||
"'{0}'={1}{2};{3};{4}{5}{6} ",
|
||||
$LabelName,
|
||||
(Format-IcingaPerfDataValue $this.value),
|
||||
|
|
@ -662,6 +669,13 @@ function New-IcingaCheck()
|
|||
(Format-IcingaPerfDataValue $this.minimum),
|
||||
(Format-IcingaPerfDataValue $this.maximum)
|
||||
);
|
||||
'unit' = $this.unit;
|
||||
'value' = (Format-IcingaPerfDataValue $this.value);
|
||||
'warning' = (Format-IcingaPerfDataValue $this.warning);
|
||||
'critical' = (Format-IcingaPerfDataValue $this.critical);
|
||||
'minimum' = (Format-IcingaPerfDataValue ($this.minimum).Replace(';', ''));
|
||||
'maximum' = (Format-IcingaPerfDataValue ($this.maximum).Replace(';', ''));
|
||||
'package' = $FALSE;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,19 +16,20 @@ function New-IcingaCheckPackage()
|
|||
);
|
||||
|
||||
$Check = New-Object -TypeName PSObject;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'name' -value $Name;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'exitcode' -value -1;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'verbose' -value $Verbose;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'hidden' -value $Hidden;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'checks' -value $Checks;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opand' -value $OperatorAnd;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opor' -value $OperatorOr;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opnone' -value $OperatorNone;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opmin' -value $OperatorMin;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opmax' -value $OperatorMax;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'spacing' -value 0;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'compiled' -value $FALSE;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'perfdata' -value $FALSE;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'name' -value $Name;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'exitcode' -value -1;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'verbose' -value $Verbose;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'hidden' -value $Hidden;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'checks' -value $Checks;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opand' -value $OperatorAnd;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opor' -value $OperatorOr;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opnone' -value $OperatorNone;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opmin' -value $OperatorMin;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'opmax' -value $OperatorMax;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'spacing' -value 0;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'compiled' -value $FALSE;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'perfdata' -value $FALSE;
|
||||
$Check | Add-Member -membertype NoteProperty -name 'checkcommand' -value '';
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'Initialise' -value {
|
||||
foreach ($check in $this.checks) {
|
||||
|
|
@ -67,6 +68,16 @@ function New-IcingaCheckPackage()
|
|||
$this.checks += $check;
|
||||
}
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'AssignCheckCommand' -value {
|
||||
param($CheckCommand);
|
||||
|
||||
$this.checkcommand = $CheckCommand;
|
||||
|
||||
foreach ($check in $this.checks) {
|
||||
$check.AssignCheckCommand($CheckCommand);
|
||||
}
|
||||
}
|
||||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'Compile' -value {
|
||||
param([bool]$Verbose);
|
||||
|
||||
|
|
@ -137,7 +148,7 @@ function New-IcingaCheckPackage()
|
|||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'CheckMinimumOk' -value {
|
||||
if ($this.opmin -gt $this.checks.Count) {
|
||||
Write-Host ([string]::Format(
|
||||
Write-IcingaPluginOutput ([string]::Format(
|
||||
'Unknown: The minimum argument ({0}) is exceeding the amount of assigned checks ({1}) to this package "{2}"',
|
||||
$this.opmin, $this.checks.Count, $this.name
|
||||
));
|
||||
|
|
@ -156,7 +167,7 @@ function New-IcingaCheckPackage()
|
|||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'CheckMaximumOk' -value {
|
||||
if ($this.opmax -gt $this.checks.Count) {
|
||||
Write-Host ([string]::Format(
|
||||
Write-IcingaPluginOutput ([string]::Format(
|
||||
'Unknown: The maximum argument ({0}) is exceeding the amount of assigned checks ({1}) to this package "{2}"',
|
||||
$this.opmax, $this.checks.Count, $this.name
|
||||
));
|
||||
|
|
@ -259,7 +270,7 @@ function New-IcingaCheckPackage()
|
|||
|
||||
$Check | Add-Member -membertype ScriptMethod -name 'PrintNoChecksConfigured' -value {
|
||||
if ($this.checks.Count -eq 0) {
|
||||
Write-Host (
|
||||
Write-IcingaPluginOutput (
|
||||
[string]::Format(
|
||||
'{0}{1}: No checks configured for package "{2}"',
|
||||
(New-StringTree ($this.spacing + 1)),
|
||||
|
|
@ -281,7 +292,7 @@ function New-IcingaCheckPackage()
|
|||
$outputMessage += ' ({3})';
|
||||
}
|
||||
|
||||
Write-Host (
|
||||
Write-IcingaPluginOutput (
|
||||
[string]::Format(
|
||||
$outputMessage,
|
||||
(New-StringTree $this.spacing),
|
||||
|
|
@ -350,7 +361,7 @@ function New-IcingaCheckPackage()
|
|||
continue;
|
||||
}
|
||||
|
||||
$CollectedPerfData.Add($data.label, $data.perfdata);
|
||||
$CollectedPerfData.Add($data.label, $data);
|
||||
}
|
||||
|
||||
# Now sort the label output by name
|
||||
|
|
@ -363,7 +374,8 @@ function New-IcingaCheckPackage()
|
|||
|
||||
return @{
|
||||
'label' = $this.name;
|
||||
'perfdata' = $perfData;
|
||||
'perfdata' = $CollectedPerfData;
|
||||
'package' = $TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,14 @@ function New-IcingaCheckresult()
|
|||
return $IcingaEnums.IcingaExitCode.Unknown;
|
||||
}
|
||||
|
||||
$CheckCommand = (Get-PSCallStack)[1].Command;
|
||||
|
||||
# Compile the check / package if not already done
|
||||
$this.check.AssignCheckCommand($CheckCommand);
|
||||
$this.check.Compile($TRUE) | Out-Null;
|
||||
|
||||
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
|
||||
Write-Host ([string]::Format('| {0}', $this.check.GetPerfData().perfdata));
|
||||
Write-IcingaPluginPerfData ($this.check.GetPerfData().perfdata);
|
||||
}
|
||||
|
||||
return $this.check.exitcode;
|
||||
|
|
|
|||
8
lib/icinga/plugin/Write-IcingaPluginOutput.psm1
Normal file
8
lib/icinga/plugin/Write-IcingaPluginOutput.psm1
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
function Write-IcingaPluginOutput()
|
||||
{
|
||||
param(
|
||||
$Output
|
||||
);
|
||||
|
||||
Write-Host $Output;
|
||||
}
|
||||
32
lib/icinga/plugin/Write-IcingaPluginPerfData.psm1
Normal file
32
lib/icinga/plugin/Write-IcingaPluginPerfData.psm1
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
function Write-IcingaPluginPerfData()
|
||||
{
|
||||
param(
|
||||
$PerformanceData
|
||||
);
|
||||
|
||||
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData);
|
||||
Write-Host ([string]::Format('| {0}', $PerfDataOutput));
|
||||
}
|
||||
|
||||
function Get-IcingaPluginPerfDataContent()
|
||||
{
|
||||
param(
|
||||
$PerfData,
|
||||
[bool]$AsObject = $FALSE
|
||||
);
|
||||
|
||||
[string]$PerfDataOutput = '';
|
||||
|
||||
foreach ($package in $PerfData.Keys) {
|
||||
$data = $PerfData[$package];
|
||||
if ($data.package) {
|
||||
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -AsObject $AsObject);
|
||||
} else {
|
||||
$PerfDataOutput += $data.perfdata;
|
||||
}
|
||||
}
|
||||
|
||||
return $PerfDataOutput;
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function @( 'Write-IcingaPluginPerfData' );
|
||||
Loading…
Reference in a new issue