function Get-SupportedPlatformAPMVersion { <# .SYNOPSIS Returns the Supported NewRelic APM Version Based on Alkami Platform Version .DESCRIPTION Returns the Supported NewRelic APM Version Based on Alkami Platform Version. The Alkami Platform includes NewRelic API libraries which may require specific corresponding versions of APM, without which, the application may not start or report metrics correctly. .PARAMETER PlatformVersion The Platform Version to evaluate. If not supplied, will use the local or remote ORB version for lookup purposes. If less than a 4 digit version is supplied, the end will be padded with .0 to make it 4 segments .PARAMETER ComputerName The remote server name to interrogate for deployed ORB version. The default is the local computer. .Example Get-SupportedPlatformAPMVersion [Get-SupportedPlatformAPMVersion] : Attempting to Retrieve Alkami Platform Version from LocalHost [Get-SupportedPlatformAPMVersion] : Based on Alkami Platform version 2022.2.0.13, NewRelic APM version 8.39.0.0 should be installed 8.39.0.0 .Example Get-SupportedPlatformAPMVersion -PlatformVersion "2022.2.5.7" [Get-SupportedPlatformAPMVersion] : Based on Alkami Platform version 2022.2.5.7, NewRelic APM version 8.39.0.0 should be installed 8.39.0.0 .Example Get-SupportedPlatformAPMVersion -ComputerName "APP123456.domain.local" [Get-SupportedPlatformAPMVersion] : Attempting to Retrieve Alkami Platform Version from APP123456.fh.local [Get-SupportedPlatformAPMVersion] : Based on Alkami Platform version 2022.2.0.13, NewRelic APM version 8.39.0.0 should be installed 8.39.0.0 .Example Get-SupportedPlatformAPMVersion -PlatformVersion "2022.2" [Get-SupportedPlatformAPMVersion] : Less than a 4 digit version detected, only found 2 digits. Padding with '.0' 2 times. [Get-SupportedPlatformAPMVersion] : Based on Alkami Platform version 2022.2.0.0, NewRelic APM version 8.39.0.0 should be installed 8.39.0.0 #> [CmdletBinding()] [OutputType([System.String])] [CmdletBinding(DefaultParameterSetName = 'LocalHostParameterSet')] param( [Parameter(ParameterSetName = 'UserInputParameterSet', Mandatory = $true)] [System.Version]$PlatformVersion, [Parameter(ParameterSetName = 'LocalHostParameterSet', Mandatory = $false)] [string]$ComputerName = $env:COMPUTERNAME ) $logLead = Get-LogLeadName if (-NOT [String]::IsNullOrEmpty($PlatformVersion)) { Write-Verbose "$logLead : Using user supplied version $PlatformVersion" $targetPlatformVersion = $PlatformVersion } else { $isLocalRun = Compare-StringToLocalMachineIdentifiers -stringToCheck $ComputerName if ($isLocalRun) { Write-Host "$logLead : Attempting to Retrieve Alkami Platform Version from LocalHost" $targetPlatformVersion = Get-ORBVersion } else { Write-Host "$logLead : Attempting to Retrieve Alkami Platform Version from $ComputerName" try { $targetPlatformVersion = Invoke-CommandWithRetry -MaxRetries 3 -Exponential -ScriptBlock { Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-ORBVersion } } } catch { Write-Warning "$logLead : Unable to retrieve remote platform version within the retry limit. Review the logs and address." } } } if ($null -eq $targetPlatformVersion) { Write-Warning "$logLead : Could not retrieve Alkami Platform version. Returning null" return $null } $versionDigits = $targetPlatformVersion.ToString().Split('.').Count if ($versionDigits -lt 4) { $missingDigits = 4 - $versionDigits Write-Host "$logLead : Less than a 4 digit version detected, only found $versionDigits digits. Padding with '.0' $missingDigits times." $i = 0 do { $targetPlatformVersion = $targetPlatformVersion.ToString() + ".0" $i++ } while ($i -lt $missingDigits) Write-Verbose "$logLead : Final target version is $targetPlatformVersion" } $map = Get-SupportedPlatformAPMVersionMap # Lord help us if the Platform version ever gets this high $supermaxVersion = ("{0}.{0}.{0}.{0}" -f [Int]::MaxValue) [PSObject[]]$targetAPMVersion = $map | Where-Object { # Compare the minimum version (if $null, then 0.0.0.0) from the map to the ORB version to find an equivilent or higher match (Compare-SemVer -Version1 $targetPlatformVersion -Version2 (Test-IsNull -ValueA $_.PlatformMinimumVersion -ValueB "0.0.0.0" -Strict)) -ge 0 -and # Compare the maximum version (if $null, then [int32.maxvalue].0.0) from the map to the ORB version to find a lower match (Compare-SemVer -Version1 $targetPlatformVersion -Version2 (Test-IsNull -ValueA $_.PlatformMaximumVersion -ValueB $supermaxVersion -Strict)) -le 0 } # If we somehow matched more than one APM version from the matrix, someone made a booboo # Hopefully the tests prevent that from being merged, but just in case if ($targetAPMVersion.Count -gt 1) { Write-Warning "$logLead : More than one NewRelic APM version matched to the current ORB version. This should not be possible, and so something is horribly wrong. Check the array in Get-SupportedPlatformAPMVersionMap for mistakes" Write-Warning "$logLead : Matched the Below:" foreach ($targetVersion in $targetAPMVersion) { Write-Warning "$logLead : $($targetVersion.APMVersion)" } return $null } Write-Host "$logLead : Based on Alkami Platform version $targetPlatformVersion, NewRelic APM version $($targetAPMVersion.APMVersion) should be installed" return ([PSObject]$targetAPMVersion).APMVersion }