Thursday 10 March 2016

Daily Cluster Health Report

This post will show you how to setup a RAC component report: an email that sends the state of the cluster components. This helps a DBA keep an eye on the cluster and act preemptively if any component appears offline.

REQUIREMENTS:

1. Access to Task Scheduler (or cron for Linux)
2. A from address from a recognized mail server within your domain.
3. A home folder to deploy the scripts

INSTALL

1. Open up command prompt (cmd) and execute the following – adjust root location if need be

e:
mkdir E:\dba\script\clusterhealthreport
cd E:\dba\script\clusterhealthreport

2. Create a file called mail.vbs inside E:\oracle\scripts\LogReport. Copy the following and paste into the file
'Grab the parameters
from_address = WScript.Arguments(0)
to_address = WScript.Arguments(1)
subject = WScript.Arguments(2)
file = WScript.Arguments(3)

'Set the file reading variables
Const ForReading = 1
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'Set the mail properties
SMTPServer = "smtprelay.inter.domain.net"
Recipient = to_address
From = from_address
Subject = subject


'Create the mail object
GenericSendmail SMTPserver, From, Recipient, Subject, Message
Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)
Message = fso.OpenTextFile(file,ForReading).ReadAll

'Assisgn the values to our mail object and send the mail off
set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message
msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg.Configuration.Fields.Update
msg.Send
End Sub

3. Create a file called clusterhealthreport.bat and paste the following into it. Set the variables in yellow to what you want:
SET CLUSTERNAME=CLUSTERNAME
SET WORKING_DIR=E:\dba\script\clusterhealthreport
SET PATH=%PATH%;%WORKING_DIR%
SET ORACLE_BASE=E:\Oracle
SET ORACLE_HOME=E:\OracleGrid\11.2.0.4

cd %WORKING_DIR%
E:

SETLOCAL EnableDelayedExpansion

echo CLUSTER HEALTH REPORT  > clusterhealthreport.log
echo ---------------------  >> clusterhealthreport.log
echo .                      >> clusterhealthreport.log
echo crsctl stat res -t     >> clusterhealthreport.log

crsctl stat res -t >> clusterhealthreport.log

mail.vbs serveraddress@servername.net emailaddress@domain.net "%CLUSTERNAME% Cluster Health Report" %WORKING_DIR%\clusterhealthreport.log

4. Create a task scheduler to run once a day – I usually set it for 5:30am:























Click start, open task scheduler















Right click task scheduler library



Under the general tab, ensure the task executes with the highest privileges and runs while the user in not logged into the system. Enter a description for the server administrator.

Create a schedule – for details on their configuration see the screenshot below.


In the action tab, browse to the bat file location created in step 3

Your email should look like the following:
CLUSTER HEALTH REPORT 
--------------------- 
.                     
crsctl stat res -t    
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS      
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                               
ora.H_DRIVE.dg
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.LISTENER.lsnr
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.asm
               ONLINE  ONLINE       yournodedb01           Started            
               ONLINE  ONLINE       yournodedb02           Started            
ora.gsd
               OFFLINE OFFLINE      yournodedb01                              
               OFFLINE OFFLINE      yournodedb02                              
ora.net1.network
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.ons
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
ora.registry.acfs
               ONLINE  ONLINE       yournodedb01                              
               ONLINE  ONLINE       yournodedb02                              
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       yournodedb02                              
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       yournodedb01                              
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       yournodedb01                              
ora.cvu
      1        ONLINE  ONLINE       yournodedb01                              
ora.oc4j
      1        ONLINE  ONLINE       yournodedb01                              
ora.scan1.vip
      1        ONLINE  ONLINE       yournodedb02                              
ora.scan2.vip
      1        ONLINE  ONLINE       yournodedb01                              
ora.scan3.vip
      1        ONLINE  ONLINE       yournodedb01                              
ora.database.db
      1        ONLINE  ONLINE       yournodedb01           Open               
      2        ONLINE  ONLINE       yournodedb02           Open               
ora.yournodedb01.vip
      1        ONLINE  ONLINE       yournodedb01                               
ora.yournodedb02.vip
      1        ONLINE  ONLINE       yournodedb02         

No comments:

Post a Comment