icinga-powershell-framework/lib/daemons/ServiceCheckDaemon/tools/New-IcingaServiceCheckDaemonEnvironment.psm1

62 lines
2.2 KiB
PowerShell
Raw Normal View History

2021-12-09 11:42:06 -05:00
function New-IcingaServiceCheckDaemonEnvironment()
{
param (
$CheckCommand,
$Arguments,
$TimeIndexes
);
if ($Global:Icinga.Public.Daemons.ServiceCheck.PerformanceDataCache.ContainsKey($CheckCommand) -eq $FALSE) {
$Global:Icinga.Public.Daemons.ServiceCheck.PerformanceDataCache.Add(
$CheckCommand, @{ }
);
}
$Global:Icinga.Private.Daemons.Add(
'ServiceCheck',
@{
'PassedTime' = 0;
'SortedResult' = $null;
'PerformanceCache' = @{ };
'AverageCalculation' = @{ };
'MaxTime' = 0;
'MaxTimeInSeconds' = 0;
}
);
foreach ($index in $TimeIndexes) {
# Only allow numeric index values
if ((Test-Numeric (ConvertTo-Seconds $index)) -eq $FALSE) {
2021-12-09 11:42:06 -05:00
Write-IcingaEventMessage -EventId 1450 -Namespace 'Framework' -Objects $CheckCommand, ($Arguments | Out-String), ($TimeIndexes | Out-String), $index;
continue;
}
if ($Global:Icinga.Private.Daemons.ServiceCheck.AverageCalculation.ContainsKey([string]$index) -eq $FALSE) {
$Global:Icinga.Private.Daemons.ServiceCheck.AverageCalculation.Add(
[string]$index,
@{
'Interval' = ([int]($index -Replace '[^0-9]', ''));
'RawInterval' = $index;
'Time' = (ConvertTo-Seconds $index);
'Sum' = 0;
'Count' = 0;
2021-12-09 11:42:06 -05:00
}
);
}
if ($Global:Icinga.Private.Daemons.ServiceCheck.MaxTime -le (ConvertTo-Seconds $index)) {
$Global:Icinga.Private.Daemons.ServiceCheck.MaxTime = (ConvertTo-Seconds $index);
2021-12-09 11:42:06 -05:00
}
}
$Global:Icinga.Private.Daemons.ServiceCheck.MaxTimeInSeconds = $Global:Icinga.Private.Daemons.ServiceCheck.MaxTime * 60;
if ($Global:Icinga.Private.Scheduler.CheckData.ContainsKey($CheckCommand) -eq $FALSE) {
$Global:Icinga.Private.Scheduler.CheckData.Add(
$CheckCommand,
@{
'results' = @{ };
'average' = (New-Object -TypeName PSObject);
}
);
}
}