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!

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


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!!!
 
Hello strogonof,

Just wonder what it is, but, it won't do in vbs.
[tt]
If itmGroup.Name = "Cluster Group"
[red]continue[/red]
End If[/tt]

regards - tsuji
 
ups...sorry..that's the Quorum Group, the one tha has que quorum disk. I was having problems with it...the script didn't run if i had the code to do for all the groups including the quorum...so i decided to do only for the other groups...
about the "continue" statement...i also thougt it wasn't used in vbs..only vb...
the idea is to "ignore/pass" que quorum group and just failover the other groups....
what i'm really having problems, is that, afert bringing one group offline it doesn't continues the script..and doesn't move the group and brings online...and writesthe failover times in the file.
 
strogonof,

Yes, I can vaguely see what it means to do. Would this serve for something?
Code:
'above lines...
For Each itmGroup in objClus.ResourceGroups
    'the other lines
    If itmGroup.Name [blue]<>[/blue] "Cluster Group" [red]Then[/red]
        c1 = Now
        itmGroup.Offline(40)
        'etc etc the other lines
    [blue]End If[/blue]
next
'below lines...
- tsuji
 
I'll try it tomorrow morning and then I reply if it works...please..keep in touch...
thanks...
But..I don't think that has something to do with that "bug" of my code....
 
Here's the configuration of my 2 node cluster, it has 3 groups, usually 2 of them (the quorum and sql) are on one node and the other (exchange + file share)on the other node.
What is happening when I run the script is that it "jumps" directly to the 3rd group withou doing the failover on the other 2 groups and when it's bringing offline that 3rd group it gives an error that says:
"The group or resource is not in the correct state to perform the requested operation" (code: 8007139F)
Oh well...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top