From 037ccf86aa6f109948aac0d599382d50a225ea2a Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Fri, 20 Aug 2021 13:53:29 +0200 Subject: [PATCH] Improves debug output on TCP handling --- doc/31-Changelog.md | 1 + lib/icinga/enums/Icinga_IcingaEnums.psm1 | 2 +- lib/webserver/New-IcingaTCPClientRESTMessage.psm1 | 6 ++++-- lib/webserver/Read-IcingaTCPStream.psm1 | 15 +++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index bc8c4ab..1a0141f 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -40,6 +40,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#338](https://github.com/Icinga/icinga-powershell-framework/pull/338) Improves various styles, outputs and view for the Icinga for Windows Management Console and fixes some spelling mistakes * [#342](https://github.com/Icinga/icinga-powershell-framework/pull/342) Adds feature to print commands being executed by the Icinga Management Console with `l` and improves summary visualisation for better readability * [#346](https://github.com/Icinga/icinga-powershell-framework/pull/346) Adds support for version names for snapshots +* [#348](https://github.com/Icinga/icinga-powershell-framework/pull/348) Improves debug output on TCP handling by separating several network messages into multiple messages and by logging the send message to the client ## 1.5.2 (2021-07-09) diff --git a/lib/icinga/enums/Icinga_IcingaEnums.psm1 b/lib/icinga/enums/Icinga_IcingaEnums.psm1 index 0e70992..44a1a1b 100644 --- a/lib/icinga/enums/Icinga_IcingaEnums.psm1 +++ b/lib/icinga/enums/Icinga_IcingaEnums.psm1 @@ -75,7 +75,7 @@ # Example usage: # $IcingaEnums.IcingaExitCode.Ok #> - if ($null -eq $IcingaEnums) { +if ($null -eq $IcingaEnums) { [hashtable]$IcingaEnums = @{ IcingaExitCode = $IcingaExitCode; IcingaExitCodeText = $IcingaExitCodeText; diff --git a/lib/webserver/New-IcingaTCPClientRESTMessage.psm1 b/lib/webserver/New-IcingaTCPClientRESTMessage.psm1 index bce7fe8..8708374 100644 --- a/lib/webserver/New-IcingaTCPClientRESTMessage.psm1 +++ b/lib/webserver/New-IcingaTCPClientRESTMessage.psm1 @@ -31,7 +31,7 @@ function New-IcingaTCPClientRESTMessage() ); } - $ResponseMeessage = -Join( + $ResponseMessage = -Join( [string]::Format( 'HTTP/1.1 {0} {1}{2}', $HTTPResponse, @@ -53,8 +53,10 @@ function New-IcingaTCPClientRESTMessage() $HTMLContent ); + Write-IcingaDebugMessage -Message 'Sending message to client' -Objects $ResponseMessage; + # Encode our message before sending it - $UTF8Message = [System.Text.Encoding]::UTF8.GetBytes($ResponseMeessage); + $UTF8Message = [System.Text.Encoding]::UTF8.GetBytes($ResponseMessage); return @{ 'message' = $UTF8Message; diff --git a/lib/webserver/Read-IcingaTCPStream.psm1 b/lib/webserver/Read-IcingaTCPStream.psm1 index dddf245..cc71c24 100644 --- a/lib/webserver/Read-IcingaTCPStream.psm1 +++ b/lib/webserver/Read-IcingaTCPStream.psm1 @@ -15,16 +15,15 @@ function Read-IcingaTCPStream() } # Get the maxium size of our buffer - [byte[]]$bytes = New-Object byte[] $ReadLength; - + [byte[]]$bytes = New-Object byte[] $ReadLength; # Read the content of our SSL stream - $MessgeSize = $Stream.Read($bytes, 0, $ReadLength); - - Write-IcingaDebugMessage -Message 'Network Stream message size and content in bytes' -Objects $MessgeSize, $bytes; - + $MessageSize = $Stream.Read($bytes, 0, $ReadLength); # Resize our array to the correct size - [byte[]]$resized = New-Object byte[] $MessgeSize; - [array]::Copy($bytes, 0, $resized, 0, $MessgeSize); + [byte[]]$resized = New-Object byte[] $MessageSize; + [array]::Copy($bytes, 0, $resized, 0, $MessageSize); + + Write-IcingaDebugMessage -Message 'Network Stream message size' -Objects $MessageSize; + Write-IcingaDebugMessage -Message 'Network Stream message in bytes' -Objects $resized; # Return our message content return [System.Text.Encoding]::UTF8.GetString($resized);