mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -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;
|
Use-Icinga -LibOnly -Daemon;
|
||||||
$PassedTime = 0;
|
$PassedTime = 0;
|
||||||
|
$SortedResult = $null;
|
||||||
|
$OldData = @{};
|
||||||
|
|
||||||
if (-Not ($IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($CheckCommand))) {
|
if (-Not ($IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($CheckCommand))) {
|
||||||
$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.Add($CheckCommand, [hashtable]::Synchronized(@{}));
|
$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.Add($CheckCommand, [hashtable]::Synchronized(@{}));
|
||||||
|
|
@ -53,14 +55,13 @@ function Start-IcingaServiceCheckTask()
|
||||||
|
|
||||||
while ($TRUE) {
|
while ($TRUE) {
|
||||||
if ($PassedTime -ge $Interval) {
|
if ($PassedTime -ge $Interval) {
|
||||||
& $CheckCommand @Arguments;
|
try {
|
||||||
|
& $CheckCommand @Arguments | Out-Null;
|
||||||
|
|
||||||
$Results = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'];
|
|
||||||
$UnixTime = Get-IcingaUnixTime;
|
$UnixTime = Get-IcingaUnixTime;
|
||||||
$OldData = @{};
|
|
||||||
|
|
||||||
foreach ($result in $Results.Keys) {
|
foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) {
|
||||||
$SortedResult = $Results[$result].GetEnumerator() | Sort-Object name -Descending;
|
$SortedResult = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'][$result].GetEnumerator() | Sort-Object name -Descending;
|
||||||
Add-IcingaHashtableItem -Hashtable $OldData -Key $result -Value @{};
|
Add-IcingaHashtableItem -Hashtable $OldData -Key $result -Value @{};
|
||||||
|
|
||||||
foreach ($index in $TimeIndexes) {
|
foreach ($index in $TimeIndexes) {
|
||||||
|
|
@ -74,7 +75,7 @@ function Start-IcingaServiceCheckTask()
|
||||||
$ObjectValue += $timeEntry.Value;
|
$ObjectValue += $timeEntry.Value;
|
||||||
Remove-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry;
|
Remove-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry;
|
||||||
} else {
|
} 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
|
# Flush data we no longer require in our cache to free memory
|
||||||
foreach ($entry in $OldData.Keys) {
|
foreach ($entry in $OldData.Keys) {
|
||||||
foreach ($key in $OldData[$entry].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'];
|
Set-IcingaCacheData -Space 'sc_daemon' -CacheStore 'checkresult' -KeyName $CheckCommand -Value $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'];
|
||||||
|
} catch {
|
||||||
|
# Todo: Add error reporting / handling
|
||||||
|
}
|
||||||
|
|
||||||
$PassedTime = 0;
|
$PassedTime = 0;
|
||||||
|
$SortedResult = $null;
|
||||||
|
$OldData = @{};
|
||||||
}
|
}
|
||||||
$PassedTime += 1;
|
$PassedTime += 1;
|
||||||
Start-Sleep -Seconds 1;
|
Start-Sleep -Seconds 1;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue