If you ever need to check for some information or debug your script, one idea is to use the Cluster Log, since the Resource Monitor allows the script to write messages to the Cluster Log file using the function Resource.LogInformation. The log file is located in C:\Windows\Cluster\Reports, and it is named Cluster.log. In our script, we have used the function to log some failure information for instance.
To access the cluster log, execute the following command a command prompt as an administrator:
powershell.exe -command Get-ClusterLog
Alternatively, you can open Powershell and run the command:
Get-ClusterLog
You may also add the following option to retrieve an updated log for the last 10 minutes only:
Get-ClusterLog -timespan 10
One additional suggestion: If you ever need to debug your Cluster script, create a separated VBS script with Cluster script code, replacing the calls to Resource.LogInformation with a Print function and create the Print() function as follows:
Function Print (txt)
WScript.StdOut.WriteLine (txt)
End Function
Use it as follows:
Function Online
Print "Entering Online"
Online = True
End Function
At the end of script add the function wanted to test and execute that script as following:
cscript test_script.vbx
Notice the Cluster VBS script is not a program, but just a set of functions that will be automatically called by the Windows Cluster Resource Monitor. With that said, the behavior of your external test script may differ from the similar script run by the Cluster.
Send Warning Messages from Cluster Service
We suggest a way to send messages for somebody who really needs to be notified if something goes wrong on the cluster. This suggestion is a VBS script to send messages using the Windows msg.exe utility.
It works when the cluster vbscript (script that runs inside generic script cluster resource) finds out the active node stopped to work and the cluster transfers the client's connections to the secondary node, at this moment we can execute a script to send that warning message about that occurrence.
This suggestion is based on one script and one text file (a csv type) containing lines specifying the recipient and the message to send, such as the example below:
win-fcbr10,Administrator,y
win-fcbr11,Administrator,y
win-fcbr12,Administrator,y
win81,Administrator,y
The file above is called sendmsg.inf. This script works with the following script:
Dim arraylist, filename, linestring, Arg, ExecMessage
Arg = WScript.Arguments (0)
filename = "C:\FairCom\Scripts\sendmsg.inf"
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
linestring = f.ReadLine
Do Until f.AtEndOfStream
arraylist = Split(linestring,",")
If arraylist(2) = "y" then
ExecMessage = "msg.exe /" & "server:" & arraylist(0) & " " & arraylist(1) & " " & """" & Arg & """"
WshShell.Exec (ExecMessage)
End If
linestring = f.ReadLine
Loop
f.Close
We call this script sendmsg.vbs.
This script must be executed at the cluster script, more precisely in the IsAlive function, when the exit code from ctsmon.exe utility returns a value different from zero. See the piece of code below to illustrate:
If oIsAlive.ExitCode <> 0 Then
Resource.LogInformation "Error ctreeSQL Server: """ & oIsAlive.ExitCode
Resource.LogInformation oIsAlive.StdErr.ReadAll
WShShell.Exec ("C:\FairComs\Scripts\sendmsg.vbs " & "Error ctreeSQL Server: """ & oIsAlive.ExitCode)
End If