Fixes NULL exception on REST message

This commit is contained in:
Lord Hepipud 2021-06-28 11:25:51 +02:00
parent d95cea5b18
commit 4d161676ec
2 changed files with 9 additions and 4 deletions

View file

@ -21,6 +21,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#282](https://github.com/Icinga/icinga-powershell-framework/issues/282) Fixes issue on `System.Text.StringBuilder` which fails to initialize properly on some older Windows systems * [#282](https://github.com/Icinga/icinga-powershell-framework/issues/282) Fixes issue on `System.Text.StringBuilder` which fails to initialize properly on some older Windows systems
* [#284](https://github.com/Icinga/icinga-powershell-framework/issues/284) Fixes exception while creating default threshold objects * [#284](https://github.com/Icinga/icinga-powershell-framework/issues/284) Fixes exception while creating default threshold objects
* [#285](https://github.com/Icinga/icinga-powershell-framework/issues/285) Fixes plain Icinga 2 conf generation for commands, which was caused by a new exception output for additional output * [#285](https://github.com/Icinga/icinga-powershell-framework/issues/285) Fixes plain Icinga 2 conf generation for commands, which was caused by a new exception output for additional output
* [#293](https://github.com/Icinga/icinga-powershell-framework/pull/293) Fixes crash on REST-Api for NULL values while parsing the REST message
## 1.5.0 (2021-06-02) ## 1.5.0 (2021-06-02)

View file

@ -55,9 +55,10 @@ function Read-IcingaRESTMessage()
# Header # Header
$Request.Add( 'Header', @{ } ); $Request.Add( 'Header', @{ } );
$SplitString = $RestMessage.split("`r`n"); $SplitString = $RestMessage.Split("`r`n");
foreach ( $SingleString in $SplitString ) { foreach ( $SingleString in $SplitString ) {
if ( ([string]::IsNullOrEmpty($SingleString) -eq $FALSE) -And ($SingleString -match '^{.+' -eq $FALSE) ) { if ( ([string]::IsNullOrEmpty($SingleString) -eq $FALSE) -And ($SingleString -match '^{.+' -eq $FALSE) -And $SingleString.Contains(':') -eq $TRUE ) {
$SingleSplitString = $SingleString.Split(':', 2); $SingleSplitString = $SingleString.Split(':', 2);
$Request.Header.Add( $SingleSplitString[0], $SingleSplitString[1].Trim()); $Request.Header.Add( $SingleSplitString[0], $SingleSplitString[1].Trim());
} }
@ -69,7 +70,10 @@ function Read-IcingaRESTMessage()
# Body # Body
$RestMessage -match '(\{(.*\n)*}|\{.*\})' | Out-Null; $RestMessage -match '(\{(.*\n)*}|\{.*\})' | Out-Null;
if ($null -ne $Matches) {
$Request.Add('Body', $Matches[1]); $Request.Add('Body', $Matches[1]);
}
# We received a content length, but couldnt load the body. Some clients will send the body as separate message # We received a content length, but couldnt load the body. Some clients will send the body as separate message
# Lets try to read the body content # Lets try to read the body content