Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript for W2K3 Cluster failover

Status
Not open for further replies.

strogonof

Technical User
Jan 21, 2003
8
CA
Hi,

I'm doing a script to failover my company's W2K3 cluster with 2 nodes.
The idea is to simulate a cluster failover by the script, count the time of failover for each group and put them in a .html file to send by email.
I found some useful scripts on the web, where I took part of the code.
Here's what I have until now:

Option Explicit
Dim objClus, WSHShell, objNet, objFS, strSysName, strDir, strClusDir, strOutputFile, fsoOutputFile
Dim itmNode, itmGroup
Dim c1, c2, c3, p1, p2, p3, v1, v2, v3
Dim cOff, pOff, vOff, cOn, pOn, vOn, cSt, pSt, vSt

Set objNet = WScript.CreateObject("WScript.Network")
Set WSHShell = Wscript.CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objClus = CreateObject("MSCluster.Cluster")


objClus.Open ""

strSysName = objNet.ComputerName

strDir = WSHShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
strClusDir = strDir & "\Cluster\"

strOutputFile = strClusDir & objClus.Name & ".htm"

'if (objFS.FileExists(strOutputFile)) then
' strOutputFile = strClusDir & objClus.Name & ".htm"
'end if

Set fsoOutputFile = objFS.CreateTextFile(strOutputFile, True)



fsoOutputFile.WriteLine()
fsoOutputFile.WriteLine("<HTML>")
fsoOutputFile.WriteLine("<BODY>")
fsoOutputFile.WriteLine("<HEAD>")
fsoOutputFile.WriteLine("<style>")
fsoOutputFile.WriteLine("BODY {margin-left: .5in; margin-right: .5in;margin-top: .25in; font-family: 'arial'; font-size: 10pt}")
fsoOutputFile.WriteLine("H2 {margin-bottom: 1mm}")
fsoOutputFile.WriteLine("TD {font-size: 10pt}")
fsoOutputFile.WriteLine("HR {margin-bottom: 0mm}")
fsoOutputFile.WriteLine("</style>")
fsoOutputFile.WriteLine("</HEAD>")
fsoOutputFile.WriteLine()
fsoOutputFile.WriteLine("<H2> Cluster Failover " & objClus.Name & "</H2>")
fsoOutputFile.WriteLine("<HR WIDTH='75%' ALIGN='LEFT' COLOR=#000000><p>")
fsoOutputFile.WriteLine()


fsoOutputFile.WriteLine("<TABLE CELLPADDING='5'>")


'Print the cluster nodes
For Each itmNode in objClus.Nodes
fsoOutputFile.WriteLine("<TD ALIGN='RIGHT' VALIGN='TOP'><b>Nó:</b></TD>")
fsoOutputFile.WriteLine("<TD>")

fsoOutputFile.WriteLine(itmNode.Name & "</TD><TD> " & itmNode.state & "</TD><BR>")

Next
fsoOutputFile.WriteLine("</TR>")
fsoOutputFile.WriteLine("</TABLE><P>")

fsoOutputFile.WriteLine("<HR WIDTH='75%' ALIGN='LEFT' COLOR=#cccccc>")

'Begin the resources summary table
fsoOutputFile.WriteLine("<P>")
fsoOutputFile.WriteLine("<b><i>Failover</i></b>")
fsoOutputFile.WriteLine("<blockquote>")
fsoOutputFile.WriteLine("<TABLE BORDER='0' BORDERCOLOR='#cccccc' CELLPADDING='5'>")
fsoOutputFile.WriteLine("<TR><TD><b>Group</b></TD>")
fsoOutputFile.WriteLine("<TD><b>Time/Date</b></TD>")
fsoOutputFile.WriteLine("<TD><b>Offline Time</b></TD>")
fsoOutputFile.WriteLine("<TD><b>Online Time</b></TD>")
fsoOutputFile.WriteLine("<TD><b>Startup Time</b></TD></TR>")



'Run this For-Each loop for each resource group in the cluster


For Each itmGroup in objClus.ResourceGroups

'Move Groups to appropriate node


'Print the name of the group
fsoOutputFile.WriteLine("<TR><TD VALIGN='TOP' ROWSPAN='" & itmGroup.Resources.Count & "'>" & itmGroup.Name & " </TD>")



'Print the time and date
fsoOutputFile.WriteLine("<TD VALIGN='TOP' ROWSPAN='" & itmGroup.Resources.Count & "'>" & Now & " </TD>")


If itmGroup.Name = "Cluster Group"
continue
End If
c1 = Now
itmGroup.Offline(40)
If itmGroup.State = 1 Then
c2=Now
cOff = (c2-c1)*86400.0
End If
itmGroup.Move(20)
itmGroup.Online(60)
If itmGroup.State = 0 Then
c3 = Now
cOn = (c3-c2)*86400.0
End If
cSt = cOff + cOn
fsoOutputFile.WriteLine("<TD VALIGN='TOP' ROWSPAN='" & itmGroup.Resources.Count & "'>" & cstr(cOff) & " </TD>")
fsoOutputFile.WriteLine("<TD VALIGN='TOP' ROWSPAN='" & itmGroup.Resources.Count & "'>" & cOn & " </TD>")
fsoOutputFile.WriteLine("<TD VALIGN='TOP' ROWSPAN='" & itmGroup.Resources.Count & "'>" & cSt & " </TD></TR>")


Next


'End of the resource details table
fsoOutputFile.WriteLine("</TABLE>")
fsoOutputFile.WriteLine("</blockquote>")

'Print the footer
fsoOutputFile.WriteLine("<P>")
fsoOutputFile.WriteLine("<HR WIDTH='75%' ALIGN='LEFT' COLOR=#cccccc>")
fsoOutputFile.WriteLine("<i>End of Report</i>")
fsoOutputFile.WriteLine("<HR WIDTH='75%' ALIGN='LEFT' COLOR=#cccccc>")

fsoOutputFile.WriteLine("</BODY>")
fsoOutputFile.WriteLine("</HTML>")

fsoOutputFile.Close


The cluster is configured with 3 groups (quorum, sql, exchange) and when I run the script it goes directly to the 3rd group, without doing the failover for the other 2 groups. And it gives an error saying: "The resource or group is not in the correct state to perform the requested operation" (something like this).

Well...this isn't working as I expected to. It's bringing a group offline and it doesn't move the group. Consequently, the next group isn't brought offline, and the times for the 3 groups doesn't appear in the html file.

Any suggestions ???

Thanks!!!
 
I have no experience with Clustering, but as a standard practice you should implement some error checking/catching, even just to check the error level and description via wscript.echo err.number & err.description, at important parts of your script and some wscript.echo 's to check your time variables.


nedbert9
A+, CCNA, CNE 3-5, MCSE NT4, MCP 2003
A leisurely lifestyle is a sign of wisdom and maturity - Aristotle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top