Windows 2003 Cluster monitor script for Exchange 2003 server


 

Hello, Here is my another script I made it to monitor my company’s Exchange 2003 cluster. If you run Exchange 2003 server on Windows 2003 cluster, this might help you.

Here are the needs for this script,

– Exchange cluster group might be failover to another node for some reason. I want to know why it did failover and when. Most importantly, How much time it takes to failover.

– For Better practice, I set "affect the group" settings only to very important core resources. If all other resources fails, it will not affect the group and stays failed. If that happens for any reason. I want to know when it happens.

– Run this script from a standalone server. Do not run this on the cluster node(s) itself. It beats the reason for this script. It uses WMI, so it can run from any Windows 2000, Windows 2003 or XP machine.

It’s basic VBScript and I found the help from MSDN website. Anybody can reuse this script by providing the Exchange cluster server name, an SMTP server name and Administrators who needs to receive email alerts.

NOTE: You need to have an SMTP server other than the Exchange server itself. If the Exchange is down on the cluster, you need to send alert mails via different SMTP server.

Questions, leave me reply. OK Let’s get to the script.

 

‘===============================================================
‘ Name: ClusterProbe.vbs
‘ Purpose: Check each Cluster member found for Exchange server,
‘ and Check all properties on the ExchangeClusterResource
‘ objects. If the state is other than 2, send emails
‘ to administrators
‘Written by: Anand Venkatachalapathy
‘Written Date: Sep 9 2006
‘===============================================================

Dim strAdministrators ‘Who supposed to receive alerts

StrAdministrators = "Adminname@company.com;pageremail@pager.com"

Dim sSMTpServerName ‘* sSMTPServerName – SMTP Server Name

‘* SMTP server – This server should not be your Exchange server.
‘* If your Exchange cluster is down, you need to send alerts. So, assign it to
‘* a different Server
sSMTPServerName = "YourSMTPServerName"

Check_Cluster_Resources "YourExchangeClusterName"

‘===============================================================
‘ Name: Check_Cluster_Resources
‘ Purpose: Check each Cluster member found for Exchange server,
‘ and Check all properties on the ExchangeClusterResource
‘ objects. If the state is other than 2, send emails
‘ to administrators
‘ Input: strComputerName [string] the computer to access
‘ Output: If the state is other than 2, calls Alert_Admins sub
‘ to send emails
‘===============================================================
Public Sub Check_Cluster_Resources ( strComputerName )

Const cWMINameSpace = "root/cimv2/applications/exchange"
Const cWMIInstance = "ExchangeClusterResource"
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim strWinMgmts ‘ Connection string for WMI
Dim objWMIExchange ‘ Exchange Namespace WMI object
Dim listClusterResources ‘ ExchangeClusterResource collection
Dim objExchangeConnector ‘ A single ExchangeClusterResource WMI object
Dim strResourceName
Dim strVirtualMachine
Dim strNodeName
Dim numResourceState, strStateDescription
Dim strResourceType
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("ClusterProbe.log", ForAppending, True)
f.WriteLine vbCRLF & "————————————————————–"
f.WriteLine Now & "- Checking cluster resources for " & strComputerName

‘ Create the object string, indicating WMI (winmgmts), using the
‘ current user credentials (impersonationLevel=impersonate),
‘ on the computer passed to the function in strComputerName, and
‘ using the CIM namespace for the Exchange provider.
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & strComputerName & "/" & cWMINameSpace


‘ Get an object using the string you just created.
Set objWMIExchange = GetObject(strWinMgmts)


‘ The Resources that currently exist appear as a list of
‘ ExchangeClusterResource instances in the Exchange namespace.
Set listClusterResources = objWMIExchange.InstancesOf(cWMIInstance)


‘ Were any ExchangeClusterResource Instances returned?
if (listClusterResources.count > 0) then
‘ If yes, do the following:
‘ Iterate through the list of ExchangeClusterResource objects.
For each objExchangeConnector in listClusterResources
‘===============================================================
‘Following Values are taken from MSDN EXchange/Cluster website
‘Cluster Resource State descriptions:
‘ClusterResourceStateUnknown = -1,
‘ClusterResourceInherited = 0,
‘ClusterResourceInitializing = 1,
‘ClusterResourceOnline = 2,
‘ClusterResourceOffline = 3,
‘ClusterResourceFailed = 4,
‘ClusterResourcePending = 128,
‘ClusterResourceOnlinePending = 129,
‘ClusterResourceOfflinePending = 130
‘===============================================================
numResourceState = objExchangeConnector.State
strResourceName = objExchangeConnector.Name
strVirtualMachine = objExchangeConnector.VirtualMachine
strNodeName = objExchangeConnector.Owner
strResourceType = objExchangeConnector.Type
If numResourceState <> 2 Then
Select Case numResourceState
Case -1
strStateDescription = "Unknown"
Case 0
strStateDescription = "Inherited"
Case 1
strStateDescription = "Initializing"
Case 2
strStateDescription = "Online"
Case 3
strStateDescription = "Offline"
Case 4
strStateDescription = "Failed"
Case 128
strStateDescription = "Pending"
Case 129
strStateDescription = "OnlinePending"
Case 130
strStateDescription = "OfflinePending"
End Select
f.WriteLine strResourceName & " is NOT online at " & strNodeName
f.WriteLine "Alerting Administrators…."
strTo = strAdministrators
strSub = "<Exchange Cluster> " & strStateDescription & ": " & strResourceName
strBody = strResourceName & "(" & strVirtualMachine & ") is hosted at " & strNodeName & vbCRLF
strBody = strBody & strResourceName & "’state is changed to " & strStateDescription & vbCRLF
strBody = strBody & strResourceName & "’s type is " & strResourceType & vbCRLF & vbCRLF
Alert_Admins strTo,strSub,strBody
f.WriteLine "Alert sent to " & strAdministrators
Else
f.WriteLine strResourceName & " is ONLINE at " & strNodeName
End If

‘ Move to the next ExchangeClusterResource.
Next
else
‘ If no ExchangeClusterResource instances were returned,
‘ display that.
f.WriteLine "No ExchangeClusterResource instances were returned."
strTo = strAdministrators
strSub = "<Exchange Cluster> " & strComputerName & " is not responding"
strBody = strComputerName & " is not available on the network"
Alert_Admins strTo,strSub,strBody
f.WriteLine "Alert sent to " & strAdministrators
end if
f.close
end Sub

‘===============================================================
‘ Name: Alert_Admins
‘ Purpose: Send email using smtp server.
‘ Input: strTo – Who to send to, strSub – Subject of the message
‘ strBody – Body of the message
‘ Output: Sends the emails to the strTO recipients
‘===============================================================
Sub Alert_Admins( strTo,strSub,strBody)
‘* iMsg – holds CDO.Message object
‘* Flds – Enumeration for CDO SMTP object properties
‘* iConf – holds CDO.Configuration
Dim iMsg, Flds, iConf

‘* Assign cdoSendUsingPort is set to 2, i.e., send using SMTP (25) port
Const cdoSendUsingPort = 2

‘* Create CDO Objects and assign to variables
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

‘* Assign values to Flds class properties

With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServerName
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 25
.Update
End With

‘* Assign message properties and Send the mail
With iMsg
Set .Configuration = iConf
.Fields("urn:schemas:httpmail:importance").Value = 2 ‘Setting Mail importance to High (2)
.Fields.Update
.To = strTo
.From = "AdminAlerts@company.com" ‘Fake, but make-sense email FROM address
.Sender = "Administrator@company.com" ‘Return Email address
.Subject = strSub
.TextBody = strBody
.Send
End With

End Sub

Advertisements

Changing WINS Server address to a bunch of Servers using VBScript


When my company started Active Directory project, we setup a new WINS server running on Windows 2003 server. We replaced our old Windows NT WINS server with new Windows 2003 server.

 

It’s easy to change the new WINS server information to the Desktops. DHCP server was the easy place to distribute the WINS server to all Desktop in one shot. BUT, What about the Servers in Data center with manual IP address mapping? Here I come with a script as below.

 

I used WMI objects to get the network properties and change the WINS address.

 

If you want to reuse this script, you need the following information ready.

  1. ServersList.txt – a text file with server names one in each line
  2. Primary and Secondary WINS server IP address
  3. First two or three octects of your production network IP address

The third requirement is little tricky. If your production network IP address of a server is 192.168.0.44, then you need to provide "192.168" to the script (check the script). If the IP Address goes like this 10.20.30.10, then you need to provide "10.20.30". I hope you get the idea.

 

I always create a log file with these kinds of scripts. This script will create a log file in running directory as WinsChange.log. It’s very handy to check back which servers were applied with new WINS and which ones failed (got to do manually).

 

CAUTION: This script works only Windows 2000 and above OSes.

 

You need to change the values in this script where you find “<<<<<” in comments

 

‘ Script Purpose: To change the WINS server information in Network properties to a bunch of computers/servers

‘ Written by: Anand Venkatachalapathy

On Error Resume Next

 

Dim fso, fin, fout

Set fso = CreateObject("Scripting.FileSystemObject")

Set fin = fso.OpenTextFile("ServerList.txt", 1, True)

Set fout = fso.OpenTextfile("WinsChange.log",2, True)

 

Do While NOT fin.AtEndOfStream

            ChangeWINS(fin.ReadLine)

Loop

 

fin.Close

fout.Close

 

Sub ChangeWINS(strComputer)

WScript.Echo "———" & strComputer & "——————"

fout.WriteLine "———" & strComputer & "——————"

 

strWINSPrimaryServer = "xx.xx.xx.xx"          ‘<<<Provide your primary WINS server IP address

strWINSSecondaryServer = "yy.yy.yy.yy"      ‘<<<Provide your secondary WINS server IP address

 

Set objWMIService = GetObject("winmgmts:" _

 & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

Set colNicConfigs = objWMIService.ExecQuery _

 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

 

WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _

 "  Attempting to set WINS primary and secondary servers …"

 

For Each objNicConfig In colNicConfigs

 

            strIPAddress = Join(objNicConfig.IPAddress,",")

            WScript.Echo "Working on network interface: " & strIPAddress

            fout.WriteLine "Working on network interface: " & strIPAddress

            If InStr(strIPAddress,"x.x") > 0 then                         ‘<<<<< Provide your starting two octects of IP address

                                                                                                ‘This is important, because we want to change the IP address only

                                                                                                ‘ to production network card.  This logic will skip the backup area network

                                                                                                ‘cards, loopback cards and disabled network cards

                        WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index & VbCrLf & "    " & objNicConfig.Description

                        fout.WriteLine "  Network Adapter " & objNicConfig.Index & "    " & objNicConfig.Description

                        intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, strWINSSecondaryServer)

 

                        If intSetWINSServer = 0 Then

                                    WScript.Echo "    Successfully set WINS servers."

                                    fout.WriteLine "    Successfully set WINS servers."

                        ElseIf intSetWINSServer = 1 Then

                                    WScript.Echo "    Successfully set WINS servers." & VbCrLf & "    Must reboot."

                                    fout.WriteLine "    Successfully set WINS servers." & VbCrLf & "    Must reboot."

                        Else

                                    WScript.Echo "    Unable to set WINS servers."

                                    fout.WriteLine "    Unable to set WINS servers."

                        End If

            End If

Next

 

WScript.Echo VbCrLf & String(80, "-")

 

Set colNicConfigs = objWMIService.ExecQuery _

 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

 

For Each objNicConfig In colNicConfigs

            WScript.Echo VbCrLf & _

            "  Network Adapter " & objNicConfig.Index & VbCrLf & _

            "    " & objNicConfig.Description

            WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer

            WScript.Echo "    Secondary WINS Server: " & _

            objNicConfig.WINSSecondaryServer

Next

 

End Sub