mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Improved stability for service check execution daemon
This commit is contained in:
parent
7e23ea76df
commit
04af3a8503
1 changed files with 42 additions and 36 deletions
|
|
@ -44,6 +44,8 @@ function Start-IcingaServiceCheckTask()
|
|||
|
||||
Use-Icinga -LibOnly -Daemon;
|
||||
$PassedTime = 0;
|
||||
$SortedResult = $null;
|
||||
$OldData = @{};
|
||||
|
||||
if (-Not ($IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($CheckCommand))) {
|
||||
$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.Add($CheckCommand, [hashtable]::Synchronized(@{}));
|
||||
|
|
@ -53,14 +55,13 @@ function Start-IcingaServiceCheckTask()
|
|||
|
||||
while ($TRUE) {
|
||||
if ($PassedTime -ge $Interval) {
|
||||
& $CheckCommand @Arguments;
|
||||
try {
|
||||
& $CheckCommand @Arguments | Out-Null;
|
||||
|
||||
$Results = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'];
|
||||
$UnixTime = Get-IcingaUnixTime;
|
||||
$OldData = @{};
|
||||
|
||||
foreach ($result in $Results.Keys) {
|
||||
$SortedResult = $Results[$result].GetEnumerator() | Sort-Object name -Descending;
|
||||
foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) {
|
||||
$SortedResult = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'][$result].GetEnumerator() | Sort-Object name -Descending;
|
||||
Add-IcingaHashtableItem -Hashtable $OldData -Key $result -Value @{};
|
||||
|
||||
foreach ($index in $TimeIndexes) {
|
||||
|
|
@ -74,7 +75,7 @@ function Start-IcingaServiceCheckTask()
|
|||
$ObjectValue += $timeEntry.Value;
|
||||
Remove-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry;
|
||||
} else {
|
||||
Add-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry -Value $TRUE;
|
||||
Add-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry -Value $null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,13 +91,18 @@ function Start-IcingaServiceCheckTask()
|
|||
# Flush data we no longer require in our cache to free memory
|
||||
foreach ($entry in $OldData.Keys) {
|
||||
foreach ($key in $OldData[$entry].Keys) {
|
||||
Remove-IcingaHashtableItem -Hashtable $Results[$entry] -Key $key.Name
|
||||
Remove-IcingaHashtableItem -Hashtable $$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'][$entry] -Key $key.Name
|
||||
}
|
||||
}
|
||||
|
||||
Set-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $CheckCommand -Value $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'];
|
||||
} catch {
|
||||
# Todo: Add error reporting / handling
|
||||
}
|
||||
|
||||
$PassedTime = 0;
|
||||
$SortedResult = $null;
|
||||
$OldData = @{};
|
||||
}
|
||||
$PassedTime += 1;
|
||||
Start-Sleep -Seconds 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue