How to configure Load Balancing for Session Recording with NetScaler

# Copyright (c) Citrix Systems, Inc. All rights reserved.

<#

.SYNOPSIS

This script is used to sync configurations between Session Recording Servers for load balancing deployment.

.DESCRIPTION

Will do below kinds of actions:

1. Export values from the registry key: HKEY_LOCAL_MACHINESOFTWARECitrixSmartAuditorServer to SrServerConfig.reg;

2. Import from SrServerConfig.reg and overwrite values in registry key: HKEY_LOCAL_MACHINESOFTWARECitrixSmartAuditorServer;

3. Add redirection mapping sr_lb_map.xml in %windir%System32msmqmapping;

3.1 sr_lb_map.xml will consist redirection rule for both http and https, and not port specific.

.PARAMETER Action

Export – to export the registry configurations of Session Recording Server to a registry file

Import – to import the registry configurations of Session Recording Server from a registry file

AddRedirection – to add HTTP/HTTPS redirection for MSMQ

.PARAMETER NetScalerHost

The host name or FQDN of NetScaler.

.OUTPUTS

Exported configuration file (SrServerConfig.reg) or backup configuration file (SrServerConfig.reg.bk)

.EXAMPLE

SrServerConfigurationSync.ps1 -Action Export

.EXAMPLE

SrServerConfigurationSync.ps1 -Action Import

.EXAMPLE

SrServerConfigurationSync.ps1 -Action AddRedirection -NetScalerHost netscaler.xd.local

.EXAMPLE

SrServerConfigurationSync.ps1 -Action Import,AddRedirection -NetScalerHost netscaler.xd.local

.EXAMPLE

SrServerConfigurationSync.ps1 -Action Import,Export,AddRedirection -NetScalerHost netscaler.xd.local

#>

######################

# Parameters section #

######################

Param(

[Parameter(Mandatory = $true)]

[ValidateSet(“Export”, “Import”, “AddRedirection”)]

[string[]] $Action,

[Parameter(Mandatory = $false)]

[string] $NetScalerHost

)

#############################

# Default variables section #

#############################

$SR_SERVER_REG_PATH = “HKEY_LOCAL_MACHINESOFTWARECitrixSmartAuditorServer”

$REG_FILE_PATH = “SrServerConfig.reg”

$REG_BACKUP_FILE_PATH = “SrServerConfig.reg.bk”

$TEMP_REDIRECT_XML = “sr_lb_map.xml”

$REDIRECT_XML_PATH = “$env:windirSystem32msmqmapping”

############# MAIN ###############

Try

{

If ($Action -Contains “export”) {

Write-Host “Exporting current Session Recording Server Configuration to registry file: $REG_FILE_PATH …” -ForegroundColor Green

& REG EXPORT $SR_SERVER_REG_PATH $REG_FILE_PATH /Y

Write-Host “Finish exporting.” -ForegroundColor Green

}

If ($Action -Contains “import”)

{

If (!(Test-Path $REG_FILE_PATH))

{

Write-Host “No $REG_FILE_PATH founded. Aborted.” -ForegroundColor Yellow

Exit 0

}

# Back up previous registry key

Write-Host “Backing up Session Recording Server Configuration to Registry file: $REG_BACKUP_FILE_PATH …” -ForegroundColor Green

& REG EXPORT $SR_SERVER_REG_PATH $REG_BACKUP_FILE_PATH /Y

Write-Host “Importing Session Recording Server Configuration from Registry file: $REG_FILE_PATH …” -ForegroundColor Green

& REG IMPORT $REG_FILE_PATH 2>$null

Write-Host “Finish importing.” -ForegroundColor Green

}

If ($Action -Contains “addredirection”)

{

# Check if netscaler host is given; If not, exit normally with warning.

If(([String]::IsNullOrEmpty($NetScalerHost)))

{

Write-Host “No NetScaler host name is specified. Finish adding redirection.” -ForegroundColor Yellow

Exit 0

}

If (!(Test-Path $TEMP_REDIRECT_XML))

{

New-Item $TEMP_REDIRECT_XML -Type file

}

$SysInfo = Get-WmiObject -Class Win32_ComputerSystem

$LocalFqdn = “$($SysInfo.Name).$($SysInfo.Domain)”

$RedirectXmlContent =

@”

<redirections xmlns=”msmq-queue-redirections.xml”>

<redirection>

<from>http://$NetScalerHost*/msmq/private$/CitrixSmAudData</from>

<to>http://$LocalFqdn/msmq/private$/CitrixSmAudData</to>

</redirection>

<redirection>

<from>https://$NetScalerHost*/msmq/private$/CitrixSmAudData</from>

<to>https://$LocalFqdn/msmq/private$/CitrixSmAudData</to>

</redirection>

</redirections>

“@

# Don’t take care of encoding

$RedirectXmlContent | Out-File -FilePath $TEMP_REDIRECT_XML

Write-Host “Copying $TEMP_REDIRECT_XML to $REDIRECT_XML_PATH …” -ForegroundColor Green

Copy-Item $TEMP_REDIRECT_XML -Destination $REDIRECT_XML_PATH

Write-Host “Restarting MSMQ service …” -ForegroundColor Green

Restart-Service msmq -Force

Write-Host “Finish adding HTTP/HTTPS Redirection for MSMQ.” -ForegroundColor Green

}

Exit 0

}

Catch

{

Write-Host “$_.Exception.Message” -ForegroundColor Red

Exit 1

}

Finally

{

# Nothing to do

}

Related:

Leave a Reply