Improves REST-Api memory management

This commit is contained in:
Lord Hepipud 2023-07-24 17:51:33 +02:00
parent 87a9d126d2
commit e96711efba
4 changed files with 28 additions and 0 deletions

View file

@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems
* [#645](https://github.com/Icinga/icinga-powershell-framework/pull/645) Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin for example
* [#646](https://github.com/Icinga/icinga-powershell-framework/pull/646) Fixes REST-Api to allow arguments for check execution with and without leading `-`
* [#648](https://github.com/Icinga/icinga-powershell-framework/pull/648) Fixes some memory management while using the REST-Api to clear connection objects once they are no longer required
### Enhancements

View file

@ -87,16 +87,19 @@ function New-IcingaForWindowsRESTApi()
if (Test-IcingaRESTClientBlacklisted -Client $Connection.Client -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist) {
Write-IcingaDebugMessage -Message 'A remote client which is trying to connect was blacklisted' -Objects $Connection.Client.Client;
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
continue;
}
if ((Test-IcingaRESTClientConnection -Connection $Connection) -eq $FALSE) {
$Connection = $null;
continue;
}
# API not yet ready
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.Count -eq 0) {
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
continue;
}
@ -105,6 +108,7 @@ function New-IcingaForWindowsRESTApi()
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.ContainsKey($NextRESTApiThreadId) -eq $FALSE) {
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
continue;
}

View file

@ -39,6 +39,7 @@ function New-IcingaForWindowsRESTThread()
Send-IcingaWebAuthMessage -Connection $Connection;
# Close the connection
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
continue;
}
@ -56,6 +57,7 @@ function New-IcingaForWindowsRESTThread()
Send-IcingaWebAuthMessage -Connection $Connection;
# Close the connection
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
continue;
}
}
@ -99,6 +101,7 @@ function New-IcingaForWindowsRESTThread()
# Finally close the clients connection as we are done here and
# ensure this thread will close by simply leaving the function
Close-IcingaTCPConnection -Client $Connection.Client;
$Connection = $null;
# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;

View file

@ -57,6 +57,26 @@ function Invoke-IcingaApiChecksRESTCall()
[string]$ExecuteCommand = $Request.RequestArguments.command;
}
if ((Test-IcingaFunction -Name $ExecuteCommand) -eq $FALSE) {
Add-IcingaHashtableItem `
-Hashtable $ContentResponse `
-Key $ExecuteCommand `
-Value @{
'exitcode' = 3;
'checkresult' = [string]::Format('[UNKNOWN] Icinga plugin not found exception: Command "{0}" is not present on the system{1}{1}The command "{0}" you are trying to execute over the REST-Api endpoint "apichecks" is not available on the system.', $ExecuteCommand, (New-IcingaNewLine));
'perfdata' = @();
} | Out-Null;
Send-IcingaTCPClientMessage -Message (
New-IcingaTCPClientRESTMessage `
-HTTPResponse ($IcingaHTTPEnums.HTTPResponseType.'Not Found') `
-ContentBody $ContentResponse
) -Stream $Connection.Stream;
return;
}
if ((Test-IcingaRESTApiCommand -Command $ExecuteCommand -Endpoint 'apichecks') -eq $FALSE) {
Add-IcingaHashtableItem `