mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
82 lines
3 KiB
PowerShell
82 lines
3 KiB
PowerShell
function Write-IcingaPluginPerfData()
|
|
{
|
|
param (
|
|
$IcingaCheck = $null
|
|
);
|
|
|
|
if ($null -eq $IcingaCheck) {
|
|
return;
|
|
}
|
|
|
|
$PerformanceData = $IcingaCheck.__GetPerformanceData();
|
|
$CheckCommand = $IcingaCheck.__GetCheckCommand();
|
|
|
|
if ($PerformanceData.package -eq $FALSE) {
|
|
$PerformanceData = @{
|
|
$PerformanceData.label = $PerformanceData;
|
|
}
|
|
} else {
|
|
$PerformanceData = $PerformanceData.perfdata;
|
|
}
|
|
|
|
if ([string]::IsNullOrEmpty($CheckCommand) -eq $FALSE -And $Global:Icinga.ThresholdCache.ContainsKey($CheckCommand)) {
|
|
$CheckResultCache = $Global:Icinga.ThresholdCache[$CheckCommand];
|
|
} else {
|
|
$CheckResultCache = New-Object PSCustomObject;
|
|
}
|
|
|
|
if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE -And $global:IcingaDaemonData.JEAContext -eq $FALSE) {
|
|
[string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -IcingaCheck $IcingaCheck);
|
|
Write-IcingaConsolePlain ([string]::Format('| {0}', $PerfDataOutput));
|
|
} else {
|
|
[void](Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -AsObject $TRUE -IcingaCheck $IcingaCheck);
|
|
}
|
|
}
|
|
|
|
function Get-IcingaPluginPerfDataContent()
|
|
{
|
|
param(
|
|
$PerfData,
|
|
$CheckResultCache,
|
|
[bool]$AsObject = $FALSE,
|
|
$IcingaCheck = $null
|
|
);
|
|
|
|
[string]$PerfDataOutput = '';
|
|
|
|
foreach ($package in $PerfData.Keys) {
|
|
$data = $PerfData[$package];
|
|
if ($data.package) {
|
|
$PerfDataOutput += (Get-IcingaPluginPerfDataContent -PerfData $data.perfdata -CheckResultCache $CheckResultCache -AsObject $AsObject -IcingaCheck $IcingaCheck);
|
|
} else {
|
|
foreach ($checkresult in $CheckResultCache.PSobject.Properties) {
|
|
|
|
$SearchPattern = [string]::Format('{0}_', $data.label);
|
|
$SearchEntry = $checkresult.Name;
|
|
if ($SearchEntry -like "$SearchPattern*") {
|
|
$TimeSpan = $IcingaCheck.__GetTimeSpanThreshold($SearchEntry, $data.label);
|
|
|
|
$cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value -Warning $TimeSpan.Warning -Critical $TimeSpan.Critical);
|
|
|
|
if ($AsObject) {
|
|
# New behavior with local thread separated results
|
|
$global:Icinga.PerfData += $cachedresult;
|
|
}
|
|
$PerfDataOutput += $cachedresult;
|
|
}
|
|
}
|
|
|
|
$compiledPerfData = (New-IcingaPerformanceDataEntry $data);
|
|
|
|
if ($AsObject) {
|
|
# New behavior with local thread separated results
|
|
$global:Icinga.PerfData += $compiledPerfData;
|
|
}
|
|
$PerfDataOutput += $compiledPerfData;
|
|
}
|
|
}
|
|
|
|
return $PerfDataOutput;
|
|
}
|
|
|
|
Export-ModuleMember -Function @( 'Write-IcingaPluginPerfData' );
|