Improved constructing of Performance Data

This commit is contained in:
Lord Hepipud 2019-10-05 21:50:13 +02:00
parent 5190851b96
commit a1f7adc89a
4 changed files with 73 additions and 25 deletions

View file

@ -647,36 +647,22 @@ function New-IcingaCheck()
$this.AutodiscoverMinMax();
if ([string]::IsNullOrEmpty($this.minimum) -eq $FALSE) {
$this.minimum = [string]::Format(';{0}', $this.minimum);
}
if ([string]::IsNullOrEmpty($this.maximum) -eq $FALSE) {
$this.maximum = [string]::Format(';{0}', $this.maximum);
}
$this.completed = $TRUE;
[string]$LabelName = (Format-IcingaPerfDataLabel $this.name);
return @{
$perfdata = @{
'label' = $LabelName;
'perfdata' = [string]::Format(
"'{0}'={1}{2};{3};{4}{5}{6} ",
$LabelName,
(Format-IcingaPerfDataValue $this.value),
$this.unit,
(Format-IcingaPerfDataValue $this.warning),
(Format-IcingaPerfDataValue $this.critical),
(Format-IcingaPerfDataValue $this.minimum),
(Format-IcingaPerfDataValue $this.maximum)
);
'perfdata' = '';
'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(';', ''));
'minimum' = (Format-IcingaPerfDataValue $this.minimum);
'maximum' = (Format-IcingaPerfDataValue $this.maximum);
'package' = $FALSE;
};
return $perfdata;
}
$Check | Add-Member -membertype ScriptMethod -name 'AutodiscoverMinMax' -value {

View file

@ -24,7 +24,7 @@ function New-IcingaCheckresult()
$this.check.Compile($TRUE) | Out-Null;
if ([int]$this.check.exitcode -ne [int]$IcingaEnums.IcingaExitCode.Unknown -And -Not $this.noperfdata) {
Write-IcingaPluginPerfData ($this.check.GetPerfData().perfdata);
Write-IcingaPluginPerfData -PerformanceData ($this.check.GetPerfData().perfdata) -CheckCommand $CheckCommand;
}
return $this.check.exitcode;

View file

@ -0,0 +1,43 @@
function New-IcingaPerformanceDataEntry()
{
param (
$PerfDataObject,
$Label = $null,
$Value = $null
);
if ($null -eq $PerfDataObject) {
return '';
}
[string]$LabelName = $PerfDataObject.label;
[string]$PerfValue = $PerfDataObject.value;
if ([string]::IsNullOrEmpty($Label) -eq $FALSE) {
$LabelName = $Label;
}
if ([string]::IsNullOrEmpty($Value) -eq $FALSE) {
$PerfValue = $Value;
}
$minimum = '';
$maximum = '';
if ([string]::IsNullOrEmpty($PerfDataObject.minimum) -eq $FALSE) {
$minimum = [string]::Format(';{0}', $PerfDataObject.minimum);
}
if ([string]::IsNullOrEmpty($PerfDataObject.maximum) -eq $FALSE) {
$maximum = [string]::Format(';{0}', $PerfDataObject.maximum);
}
return ([string]::Format(
"'{0}'={1}{2};{3};{4}{5}{6} ",
$LabelName,
(Format-IcingaPerfDataValue $PerfValue),
$PerfDataObject.unit,
(Format-IcingaPerfDataValue $PerfDataObject.warning),
(Format-IcingaPerfDataValue $PerfDataObject.critical),
(Format-IcingaPerfDataValue $minimum),
(Format-IcingaPerfDataValue $maximum)
));
}

View file

@ -1,10 +1,12 @@
function Write-IcingaPluginPerfData()
{
param(
$PerformanceData
$PerformanceData,
$CheckCommand
);
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData);
$CheckResultCache = Get-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $CheckCommand;
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache);
Write-Host ([string]::Format('| {0}', $PerfDataOutput));
}
@ -12,6 +14,7 @@ function Get-IcingaPluginPerfDataContent()
{
param(
$PerfData,
$CheckResultCache,
[bool]$AsObject = $FALSE
);
@ -21,8 +24,24 @@ function Get-IcingaPluginPerfDataContent()
$data = $PerfData[$package];
if ($data.package) {
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -AsObject $AsObject);
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -CheckResultCache $CheckResultCache -AsObject $AsObject);
} else {
$PerfDataOutput += $data.perfdata;
foreach ($checkresult in $CheckResultCache.PSobject.Properties) {
$SearchPattern = [string]::Format('{0}_', $data.label);
$SearchEntry = $checkresult.Name;
if ($SearchEntry -like "$SearchPattern*") {
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value);
if ($AsObject) {
$global:IcingaThreadContent['Scheduler']['PluginPerfData'] += $cachedresult;
}
$PerfDataOutput += $cachedresult;
}
}
$compiledPerfData = (New-IcingaPerformanceDataEntry $data);
$PerfDataOutput += $compiledPerfData;
}
}