Using the XmlServiceReader with Health Monitoring and Recovery (HMR)

After publishing the XmlServiceReader and writing about the shortcomings of the health check for the XML service provided by Citrix, I like to expand on the process of creating a custom health check using the XmlServiceReader.

According to an article in the Citrix community, health checks are easily created in any language and even scripts. Such a script needs to return a zero exit code to indicate success and needs to return one if the test failed. The following code demonstrates how a custom request can be supplied and the response can be tested to contain a predefined string. See this article for a detailed description of the XmlServiceReader.

@Echo Off
SetLocal
Set MyDir=%~dp0
Set MyDir=%MyDir:~0,-1%
(
    Echo <RequestCapabilities>
    Echo <Nil />
    Echo </RequestCapabilities>
)>"%Temp%\XmlServiceReader-request.txt"
Type "%Temp%\XmlServiceReader-request.txt" | "%MyDir%\XmlServiceReader.exe" -server %ComputerName% -port 8080 –stream >"%Temp%\XmlServiceReader-response.txt"
Type "%Temp%\XmlServiceReader-response.txt" | Find /i "separate-credentials-validation"
If ErrorLevel 1 Exit 1
EndLocal
Exit 0

Please note that the following script tests the XML service located on port 8080 which may not apply in your environment. The port of the XML service can be read from the TcpPort value located under HKLM\SYSTEM\CurrentControlSet\Services\CtxHttp. Unfortunately, the contents of this value needs to be converted from hexadecimal to decimal.

Before deploying your own script on any of your servers, be sure to use the HMRSDKTester supplied by the HMR SDK. It creates a temporary service running with LocalSystem privileges and displays the output and return code of the script. Citrix also documents the security requirements for HMR tests. I have used this tool to validate the above script.

References

How to Write Your First Health Monitoring & Recovery Test

Health Monitoring & Recovery SDK 4.5

Security Requirements for Health Monitoring & Recovery Tests

Monitoring & Recovery Tests in any Language

Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.