lib/icinga/plugin/Write-IcingaPluginPerfData.psm1
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; } $CheckResultCache = $Global:Icinga.ThresholdCache[$CheckCommand]; if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -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' ); |