From 4e5151bdd208462a7ac7e9277e2f09670674ce29 Mon Sep 17 00:00:00 2001 From: Habib Rangoonwala Date: Mon, 29 May 2017 18:46:16 -0700 Subject: [PATCH] Initial Version --- README.md | 3 + auth/howto.txt | 15 + bin/HSR.env | 21 + bin/HSR.lib | 1482 +++++++++++++++++++++++++ bin/crypt | 24 + bin/hAlertLogMonitor.ksh | 497 +++++++++ bin/hArchCleanup.ksh | 44 + bin/hCLONEPreparation.ksh | 134 +++ bin/hCMQueueMonitor.ksh | 236 ++++ bin/hColdBackup.ksh | 122 ++ bin/hDBObjectMonitor.ksh | 87 ++ bin/hDBSessionMonitor.ksh | 100 ++ bin/hGC.ksh | 48 + bin/hGetCPUCount.ksh | 14 + bin/hGetRequestIDInfo.ksh | 186 ++++ bin/hHotBackup.ksh | 312 ++++++ bin/hInitialize.ksh | 100 ++ bin/hInitializeSQLPlus.ksh | 28 + bin/hJVM.ksh | 91 ++ bin/hLockMonitor.ksh | 109 ++ bin/hMonitor.ksh | 49 + bin/hOSMonitor.ksh | 187 ++++ bin/hPreStop.sh | 88 ++ bin/hProcessMemory.ksh | 26 + bin/hProfileOptionMonitor.ksh | 129 +++ bin/hResponsibilityMonitor.ksh | 184 +++ bin/hRunawayMonitor.ksh | 231 ++++ bin/hSFMQueueMonitor.ksh | 131 +++ bin/hTSMonitor.ksh | 132 +++ bin/hTempTSMonitor.ksh | 182 +++ bin/hTranslateFile.ksh | 60 + bin/hUNDOTSMonitor.ksh | 204 ++++ bin/hURLCheck.java | 42 + bin/hURLMonitor.ksh | 107 ++ bin/hWFInBoundMailMonitor.ksh | 147 +++ bin/hWFQueueMonitor.ksh | 161 +++ bin/hZombieMonitor.ksh | 109 ++ conf/ORCL.URLList.ini | 8 + conf/ORCL.config.ini | 33 + conf/ResponsibilityMonitor.config.ini | 5 + conf/default.config.ini | 182 +++ sql/hAdminResponsibility.generic.sql | 25 + sql/hBeginBackup.10g.sql | 9 + sql/hBeginBackup.9i.sql | 17 + sql/hCMStatus.generic.sql | 43 + sql/hEndBackup.10g.sql | 12 + sql/hEndBackup.9i.sql | 23 + sql/hProfileOptions.generic.sql | 30 + sql/hShutdown.10g.sql | 7 + sql/hStartup.10g.sql | 7 + sql/hUNDOTSMonitor.SQL1.10g.sql | 36 + 51 files changed, 6259 insertions(+) create mode 100644 auth/howto.txt create mode 100644 bin/HSR.env create mode 100644 bin/HSR.lib create mode 100644 bin/crypt create mode 100644 bin/hAlertLogMonitor.ksh create mode 100644 bin/hArchCleanup.ksh create mode 100644 bin/hCLONEPreparation.ksh create mode 100644 bin/hCMQueueMonitor.ksh create mode 100644 bin/hColdBackup.ksh create mode 100644 bin/hDBObjectMonitor.ksh create mode 100644 bin/hDBSessionMonitor.ksh create mode 100755 bin/hGC.ksh create mode 100644 bin/hGetCPUCount.ksh create mode 100644 bin/hGetRequestIDInfo.ksh create mode 100644 bin/hHotBackup.ksh create mode 100644 bin/hInitialize.ksh create mode 100644 bin/hInitializeSQLPlus.ksh create mode 100755 bin/hJVM.ksh create mode 100644 bin/hLockMonitor.ksh create mode 100644 bin/hMonitor.ksh create mode 100644 bin/hOSMonitor.ksh create mode 100755 bin/hPreStop.sh create mode 100755 bin/hProcessMemory.ksh create mode 100644 bin/hProfileOptionMonitor.ksh create mode 100644 bin/hResponsibilityMonitor.ksh create mode 100644 bin/hRunawayMonitor.ksh create mode 100644 bin/hSFMQueueMonitor.ksh create mode 100644 bin/hTSMonitor.ksh create mode 100644 bin/hTempTSMonitor.ksh create mode 100644 bin/hTranslateFile.ksh create mode 100644 bin/hUNDOTSMonitor.ksh create mode 100644 bin/hURLCheck.java create mode 100644 bin/hURLMonitor.ksh create mode 100644 bin/hWFInBoundMailMonitor.ksh create mode 100644 bin/hWFQueueMonitor.ksh create mode 100644 bin/hZombieMonitor.ksh create mode 100644 conf/ORCL.URLList.ini create mode 100644 conf/ORCL.config.ini create mode 100644 conf/ResponsibilityMonitor.config.ini create mode 100644 conf/default.config.ini create mode 100644 sql/hAdminResponsibility.generic.sql create mode 100644 sql/hBeginBackup.10g.sql create mode 100644 sql/hBeginBackup.9i.sql create mode 100644 sql/hCMStatus.generic.sql create mode 100644 sql/hEndBackup.10g.sql create mode 100644 sql/hEndBackup.9i.sql create mode 100644 sql/hProfileOptions.generic.sql create mode 100644 sql/hShutdown.10g.sql create mode 100644 sql/hStartup.10g.sql create mode 100644 sql/hUNDOTSMonitor.SQL1.10g.sql diff --git a/README.md b/README.md index b741fca..07de02a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # Oracle EBS Monitoring The scripts in this repo helps do a basic EBS (Oracle EBusiness Suite) monitoring +The script supports: + Oracle EBusiness Suite: 11.5.10x, 12.1.3 + Database: 10g, 11g diff --git a/auth/howto.txt b/auth/howto.txt new file mode 100644 index 0000000..e788935 --- /dev/null +++ b/auth/howto.txt @@ -0,0 +1,15 @@ +# how to encrypt the password +# ensure cryptkey is updated in default.config.ini or instance specific config.ini + +# USAGE +./crypt [cryptkey] < [plaintextpassword.txt] > [output.filename] + +# Encrypt Example 1 +./crypt supersecret < plaintextpassword.txt > SYSTEM.credential + + +# Decrypt Example 1 +./crypt supersecret < SYSTEM.credential + + +# WARNING: this is very basic way of encrypting the file, you should use standard encryption method or use password vaults \ No newline at end of file diff --git a/bin/HSR.env b/bin/HSR.env new file mode 100644 index 0000000..acff295 --- /dev/null +++ b/bin/HSR.env @@ -0,0 +1,21 @@ +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-May-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 20-Feb-2009 +# Updation Date: 05-Feb-2010 [Alias for Linux] +# Updation Date: 09-Aug-2010 [Alias for crypt in Linux] +############################################################### + +# find out the current working director [CWD] +H_SCRIPT_TOP=`dirname $0` + +# Create Alias for echo if its a Linux environment +if [ `uname` = 'Linux' ]; then + alias echo='echo -e ' + alias crypt="$H_SCRIPT_TOP/crypt " +fi + +# load the library +. $H_SCRIPT_TOP/HSR.lib + diff --git a/bin/HSR.lib b/bin/HSR.lib new file mode 100644 index 0000000..76786ac --- /dev/null +++ b/bin/HSR.lib @@ -0,0 +1,1482 @@ +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 16-Mar-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 18-Feb-2009 +############################################################### + +# +### GetElapsedTime +### Value +# + +GetElapsedTime () +{ + hSeconds=`echo "$SECONDS"|cut -d. -f1` + echo "$hSeconds" + return 0 +} + + +# +### GetInstance <> +### Value +# + + +GetInstance () +{ + + hInstance=$1 + + if [ -z "$hInstance" ]; then + hInstance="$ORACLE_SID$TWO_TASK" + fi + + echo "$hInstance" + exit 0 + +} + + +# +### GetHost <> +### Value +# + + +GetHost () +{ + + hHost=$1 + + if [ -z "$hHost" ]; then + hHost=`uname -n` + fi + + echo "$hHost" + exit 0 + +} + + +# +### GetColumnValue <> <> <> +### Value record nn default "\t" +# + +GetColumnValue () +{ + + hRecord="$1" + hColumn="$2" + + if [ ! -z "$3" ]; then + hSeparator="$3" + else + hSeparator="\t" + #hCount=`echo "$hRecord" |awk 'BEGIN {FS="$hSeparator"} {print NF}'` + hCount=`printf "$hRecord" |awk 'BEGIN {FS="'"$hSeparator"'"} {print NF}'` + + if [ "$hCount" -eq 1 ]; then + hSeparator=" " + fi + fi + + #hReturn=`echo "$hRecord" |awk 'BEGIN {FS="$hSeparator"} {print $hColumn}'` + #hReturn=`echo $hRecord|cut -d " " -f1` + hReturn=`printf "$hRecord" |awk 'BEGIN {FS="'"$hSeparator"'"} {print $'$hColumn'}'` + + echo "$hReturn" + exit 0 +} + + + +# +### ReadINIValue <> <> <
> <> <> +### Value True/False +# + + +ReadINIValue () +{ + + hInstance=$1 + hHost=$2 + hSection=$3 + hKey=$4 + hEval=$5 + + hOutput=`grep "$hInstance.$hHost.$hSection.$hKey=" "$H_CONFIG_FILE"|grep -v ^#` + + if [ -z "$hOutput" ]; then + exit 1 + else + + hReturn=`echo "$hOutput"|cut -d= -f2-999` + + if [ -z "$hEval" ]; then + + echo "$hReturn" + return 0 + else + echo "`eval 'echo '$hReturn`" + return 0 + fi + + exit 0 + + fi + +} + + +# +### GetScriptParameter <
> <> <> +### Value True/False +# + +GetScriptParameter () +{ + + hInstance=$1 + hHost=$2 + hSection=$3 + hKey=$4 + hEval=$5 + hTotalArgs=$# + + hOutput=`grep -v ^# $H_CONFIG_FILE|grep ".$hKey="` + hJumpSection="" + + GetJumpSection() + { + hJumpSection=`SubString "$hReturn" "1" "3"` + + if [ "$hJumpSection" = "@@@" ]; then + hJumpSection=`SubString "$hReturn" "4"` + else + hJumpSection="" + fi + + echo "$hJumpSection" + + } + + hGSP1() + { + hReturn=`echo "$hOutput" | grep "$hInstance.$hHost.$hSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "$hInstance.$hHost.$hSection.$hKey="|cut -d= -f2-999|wc -l` + hJumpSection=`GetJumpSection "$hReturn"` + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP1 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP2() + { + hReturn=`echo "$hOutput" | grep "$hInstance.default.$hSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "$hInstance.default.$hSection.$hKey="|cut -d= -f2-999|wc -l` + hJumpSection=`GetJumpSection "$hReturn"` + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP2 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP3() + { + hReturn=`echo "$hOutput" | grep "default.$hHost.$hSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "default.$hHost.$hSection.$hKey="|cut -d= -f2-999|wc -l` + hJumpSection=`GetJumpSection "$hReturn"` + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP3 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP4() + { + hReturn=`echo "$hOutput" | grep "$hInstance.default.DefaultSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "$hInstance.default.DefaultSection.$hKey="|cut -d= -f2-999|wc -l` + #hJumpSection=`GetJumpSection "$hReturn"` + hJumpSection="" + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP4 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP5() + { + hReturn=`echo "$hOutput" | grep "default.default.$hSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "default.default.$hSection.$hKey="|cut -d= -f2-999|wc -l` + hJumpSection=`GetJumpSection "$hReturn"` + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP5 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP6() + { + hReturn=`echo "$hOutput" | grep "default.default.DefaultSection.$hKey="|cut -d= -f2-999` + hCount=`echo "$hOutput" | grep "default.default.DefaultSection.$hKey="|cut -d= -f2-999|wc -l` + #hJumpSection=`GetJumpSection "$hReturn"` + hJumpSection="" + + #if [ ! -z "$hReturn" ]; then + if [ "$hCount" -eq 1 ]; then + if [ ! -z "$hJumpSection" ]; then + hSection="$hJumpSection" + hGSP6 + fi + if [ -z "$hEval" ]; then + echo "$hReturn" + else + echo "`eval 'echo '$hReturn`" + fi + exit 0 + fi + } + + hGSP1 + hGSP2 + hGSP3 + hGSP4 + hGSP5 + hGSP6 + + exit 1 + +} + + +GetScriptParameterOLD () +{ + + + hInstance=$1 + hHost=$2 + hSection=$3 + hKey=$4 + hEval=$5 + hTotalArgs=$# + + lValue=`ReadINIValue "$hInstance" "$hHost" "$hSection" "$hKey" "$hEval"` + + if [ $? -ne 0 ]; then + + lValue=`ReadINIValue "$hInstance" "$hHost" "DefaultSection" "$hKey" "$hEval"` + + fi + + if [ $? -ne 0 ]; then + + exit 1 + + fi + + echo "$lValue" + + exit 0 + + +} + + +# +### IsScriptEnabled +### Value +# + + +IsScriptEnabled () +{ + + hInstance=$ORACLE_SID$TWO_TASK + hHostname=$H_HOSTNAME + hScriptName=$H_SCRIPTSECTION + + if [ -f "$hLogDirectory/$hInstance.$hHostname.DISABLED" -o -f "$hLogDirectory/$hInstance.default.DISABLED" -o -f "$hLogDirectory/$hScriptName.$hInstance.default.DISABLED" -o -f "$hLogDirectory/$hScriptName.$hInstance.$hHostname.DISABLED" ]; then + hReturn="False" + else + hReturn=`GetScriptParameter "$hInstance" "$hHostname" "$hScriptName" "IsEnabled"` + fi + + if [ -z "$hReturn" -o "$hReturn" = "True" ]; then + exit 0 + else + exit 1 + fi + +} + + +# +### CreateLockFile <> <> <> <> +### Value +# +CreateLockFile () +{ + + hLockFile=$1 + hLogFile=$2 + hNewLine=$3 + hDateFormat=$4 + hPID=$5 + + echo "$hPID" > "$hLockFile" + `WriteLogFile $hLogFile "Updated Lockfile with PID=$hNewPID $hNewLine" "$hDateFormat"` + +} + + +# +### CheckLockFile <> <> <> <> +### Value +# + + +CheckLockFile () +{ + + hLockFile="$1" + hLogFile="$2" + hNewLine="$3" + hDateFormat="$4" + hScriptName="$H_SCRIPTNAME" + hPID=0 + hNewPID=$$ + + `WriteLogFile $hLogFile "Checking if the script $hScriptName is already running. $hNewLine" "$hDateFormat"` + + if [ -z "$hLockFile" ]; then + `WriteLogFile "$hLogFile" "LockFile name is invalid $hNewLine" "$hDateFormat"` + echo "LockFile name is invalid" + exit 1 + fi + + if [ -f "$hLockFile" ]; then + + hPID=`cat "$hLockFile"` + + if [ ! -z "$hPID" ]; then + + hOutput=`ps -p "$hPID"|grep "$hPID"` + + if [ ! -z "$hOutput" ]; then + + hOutput=`ps -ef|grep $hPID|grep -v grep|grep $hScriptName` + + if [ -z "$hOutput" ]; then + `WriteLogFile "$hLogFile" "OLD PID=$hPID is not running but assigned to other process $hNewLine" "$hDateFormat"` + `CreateLockFile "$hLockFile" "$hLogFile" "$hNewLine" "$hDateFormat" "$hNewPID"` + exit 0 + else + `WriteLogFile "$hLogFile" "OLD PID=$hPID is still running $hNewLine" "$hDateFormat"` + `WriteLogFile "$hLogFile" "$hOutput is still running $hNewLine" "$hDateFormat"` + echo "OLD PID=$hPID is still running, please verify $hNewLine $hOutput" + exit 1 + fi + + else + + `WriteLogFile "$hLogFile" "OLD PID=$hPID is not running $hNewLine" "$hDateFormat"` + `CreateLockFile "$hLockFile" "$hLogFile" "$hNewLine" "$hDateFormat" "$hNewPID"` + exit 0 + fi + + else + `WriteLogFile "$hLogFile" "LockFile is ZERO Byte $hNewLine" "$hDateFormat"` + `CreateLockFile "$hLockFile" "$hLogFile" "$hNewLine" "$hDateFormat" "$hNewPID"` + exit 0 + fi + + else + `WriteLogFile "$hLogFile" "Creating LockFile $hNewLine" "$hDateFormat"` + `CreateLockFile "$hLockFile" "$hLogFile" "$hNewLine" "$hDateFormat" "$hNewPID"` + exit 0 + fi + +} + + +# +### WriteLogFile <> <> <> +### Value +# + + +WriteLogFile() +{ + + hLogFileName=$1 + hMessage=$2 + hDateFormat=$3 + hLogFileName2=$hRunLogFile + + if [ -z "$hDateFormat" ]; then + echo "$hMessage"|while read LINE; + do + echo "$LINE" >> $hLogFileName + + if [ ! -z "$hLogFileName2" ]; then + echo "$LINE" >> $hLogFileName2 + fi + done + else + hDate=`GetDate $hDateFormat` + echo "$hMessage"|while read LINE; + do + echo "$hDate \t $LINE" >> $hLogFileName + if [ ! -z "$hLogFileName2" ]; then + echo "$hDate \t $LINE" >> $hLogFileName2 + fi + done + fi + + exit 0 + +} + + +# +### GetDate <> +### Value +# + +GetDate() +{ + echo `date +"$*"` + exit 0 +} + + +# +### Repeat <> <> +### Value +# + +Repeat() +{ + hString=$1 + hTimes=$2 + hCount=0 + hReturn="$hString" + + while [ $hCount -le $hTimes ] + do + hReturn="$hReturn$hString" + hCount=`expr $hCount + 1` + done + echo "$hReturn" +} + +# +### WriteEMailHeader <> <> <> <> +### Value +# + +WriteEMailHeader() +{ + + hTemporaryFile=$1 + hFrom=$2 + hTo=$3 + hSubject=$4 + + hTo=`ReplaceString "$hTo" " " ";"` + + # truncate Temporary File + > $hTemporaryFile + + echo "From: $hFrom" >> $hTemporaryFile + echo "To: $hTo" >> $hTemporaryFile + echo "Subject: $hSubject" >> $hTemporaryFile + echo "MIME-Version: 1.0" >> $hTemporaryFile + echo "Content-Type: text/html" >> $hTemporaryFile + echo "Content-Disposition: inline" >> $hTemporaryFile + + exit 0 + +} + +# +### BeginHTML <> <> +### Value +# + +BeginHTML() +{ + + hTemporaryFile=$1 + hTitle=$2 + + echo '<HTML>' >> $hTemporaryFile + echo '<HEAD><TITLE>'"$hTitle"' ' >> $hTemporaryFile + echo '' >> $hTemporaryFile + +} + +# +### EndHTML <> +### Value +# + +EndHTML() +{ + + hTemporaryFile=$1 + + echo '' >> $hTemporaryFile + echo '' >> $hTemporaryFile + +} + + + + +# +### BeginHTMLHeader <> <> +### Value +# + +BeginHTMLHeader() +{ + + hTemporaryFile=$1 + hTitle=$2 + if [ -z "$3" ]; then + hColumns=1 + else + hColumns=$3 + fi + + echo '<TABLE border=1 width=100% cellspacing=0 cellpadding=0>' >> $hTemporaryFile + echo '<TR>' >> $hTemporaryFile + echo '<B><TH colspan='$hColumns ' align=center bgcolor=blue color=white> ' >> $hTemporaryFile + echo '<FONT face=Arial size=3 color=white> ' >> $hTemporaryFile + echo "$hTitle" >> $hTemporaryFile + echo '</FONT> </TH> </B> <TR>' >> $hTemporaryFile + +} + + +# +### EndHTMLHeader <<TemporaryFileName>> +### Value +# + +EndHTMLHeader() +{ + + hTemporaryFile=$1 + + echo '</TABLE>' >> $hTemporaryFile + +} + + + +# +### WriteHTMLLine <<TemporaryFileName>> <<Text>> +### Value +# + +WriteHTMLLine() +{ + + hTemporaryFile=$1 + hLine=$2 + + echo '<TR><TD align=center> ' >> $hTemporaryFile + echo '<FONT face="Arial" size="2" color="red"> ' >> $hTemporaryFile + echo "$hLine" >> $hTemporaryFile + echo '</FONT></TD></TR>' >> $hTemporaryFile +} + + +# +### SendHTMLEmail <<TemporaryFileName>> <<To>> +### Value +# + +SendHTMLEmail() +{ + + hTemporaryFile=$1 + hTo=$2 + + (cat $hTemporaryFile) | sendmail "$hTo" + if [ $? -eq 0 ]; then + rm $hTemporaryFile + exit 0 + else + exit 1 + fi + +} + +# +### SendTextEmail <<TemporaryFileName>> <<From>> <<To>> <<subject>> +### Value +# + +SendTextEmail() +{ + + hTemporaryFile=$1.2 + hTemporaryFile2=$1 + hFrom=$2 + hTo=$3 + hSubject=$4 + + hTo=`ReplaceString "$hTo" " " ";"` + + # truncate Temporary File + > $hTemporaryFile + + echo "From: $hFrom" >> $hTemporaryFile + echo "To: $hTo" >> $hTemporaryFile + echo "Subject: $hSubject" >> $hTemporaryFile + echo "MIME-Version: 1.0" >> $hTemporaryFile + echo "Content-Type: text/text" >> $hTemporaryFile + echo "Content-Disposition: inline" >> $hTemporaryFile + + hTo=$3 + + cat $hTemporaryFile2 >> $hTemporaryFile + + (cat $hTemporaryFile) | sendmail "$hTo" + if [ $? -eq 0 ]; then + rm $hTemporaryFile + rm $hTemporaryFile2 + exit 0 + else + exit 1 + fi + +} + + +# +### SendSingleLineEmail <<TemporaryFileName>> <<From>> <<TO>> <<MailSubject>> <<Title>> <<ErrorMessage>> +### Value +# + +SendSingleLineEmail() +{ + + hTemporaryFile=$1 + hFrom=$2 + hTo=$3 + hMailSubject=$4 + hTitle=$5 + hErrorMessage=$6 + hErrorMessage2=$7 + + hTo=`ReplaceString "$hTo" " " ";"` + + `WriteEMailHeader $hTemporaryFile "$hFromAlias" "$hTo" "$hMailSubject"` + + `BeginHTML $hTemporaryFile $hMailSubject` + `BeginHTMLHeader $hTemporaryFile "$hTitle"` + + `WriteHTMLLine $hTemporaryFile "$hErrorMessage"` + + if [ ! -z "$hErrorMessage2" ]; then + `WriteHTMLLine $hTemporaryFile "$hErrorMessage2"` + fi + + `EndHTMLHeader $hTemporaryFile` + `EndHTML $hTemporaryFile` + hTo=$3 + `SendHTMLEmail $hTemporaryFile "$hTo"` + +} + + +# +### SendMultiLineEmail <<TemporaryFileName>> <<From>> <<TO>> <<MailSubject>> <<Title>> <<FieldCount>> <<Align>> +### Value +# + +SendMultiLineEmail() +{ + + hTemporaryFile=$1 + hTemporaryFile2=$1.2 + hFrom=$2 + hTo=$3 + hMailSubject=$4 + hTitle=$5 + + if [ -z "$6" ]; then + hFieldCount=1 + hAlign="left" + else + hFieldCount=$6 + hAlign="center" + fi + hSrNo=1 + + cp "$hTemporaryFile" "$hTemporaryFile2" + + `WriteEMailHeader $hTemporaryFile "$hFromAlias" "$hTo" "$hMailSubject"` + + `BeginHTML $hTemporaryFile $hMailSubject` + + hTableCount=`grep "___TABLE___" $hTemporaryFile2 | wc -l` + hTableCount=`expr $hTableCount + 1` + + `BeginHTMLHeader $hTemporaryFile "$hTitle" $hFieldCount` + + + # format the details + + cat $hTemporaryFile2|while read LINE; + do + + ### if its ZERO length string, continue + if [ -z "$LINE" ]; then + continue + fi + + hString=`echo "$LINE" |grep "___TABLE___"` + if [ ! -z "$hString" ]; then + + hSrNo=1 + + echo '</TR>' >> $hTemporaryFile + `EndHTMLHeader $hTemporaryFile` + + hFieldCount=`GetColumnValue "$hString" "2"` + hTitle=`GetColumnValue "$hString" "3"` + + `BeginHTMLHeader $hTemporaryFile "$hTitle" $hFieldCount` + continue + fi + + hRem=`expr $hSrNo % 2` + + i=1 + + echo '<TR> ' >> $hTemporaryFile + + while [ $i -le $hFieldCount ]; + do + + # if its only single column, print the entire line + if [ $hFieldCount -eq 1 ]; then + hField=$LINE + else + hField=`echo "$LINE"|cut -f$i` + fi + + if [ "$hField" = "___SKIPLINE___" ]; then + break; + fi + + if [ "$hSrNo" -eq 1 ]; then + echo '<TD align='$hAlign' bgcolor="gray"> ' >> $hTemporaryFile + else + if [ $hRem -eq 0 ]; then + echo '<TD align='$hAlign' bgcolor="f7f7e7"> ' >> $hTemporaryFile + else + echo '<TD align='$hAlign' bgcolor="f7f7d2"> ' >> $hTemporaryFile + fi + fi + + if [ "$hSrNo" -eq 1 ]; then + + echo '<FONT face="Arial" size="2" > ' >> $hTemporaryFile + echo "<TEXT>$hField</TEXT>"|sed 's/___NEWLINE___/<BR>/g' >> $hTemporaryFile + echo '</FONT></TD>' >> $hTemporaryFile + + else + + echo '<FONT face="Arial" size="1" > ' >> $hTemporaryFile + echo "<TEXT>$hField</TEXT>"|sed 's/___NEWLINE___/<BR>/g' >> $hTemporaryFile + echo '</FONT></TD>' >> $hTemporaryFile + + fi + + i=`expr $i + 1` + + done + + echo '</TR>' >> $hTemporaryFile + + + + hSrNo=`expr $hSrNo + 1` + + done + + rm $hTemporaryFile2 + + `EndHTMLHeader $hTemporaryFile` + `EndHTML $hTemporaryFile` + hTo=$3 + `SendHTMLEmail $hTemporaryFile "$hTo"` + + +} + + + + +# OLD READINIVALUE - this is not in use, because of performance issues +### ReadINIValue <<Section>> <<Key>> <<EvaluateBeforeReturningValue>> +### Value True/False +# + + +ReadINIValueOld () +{ + + hSection=$1 + hKey=$2 + hEval=$3 + hTotalArgs=$# + hFound="False" + hLineCount=`cat $H_CONFIG_FILE|wc -l` + hLines=0 + + cat $H_CONFIG_FILE|while read LINE; + do + + ### if its ZERO length string, continue + if [ -z "$LINE" ]; then + continue + fi + + ## write logic for commented line --- starting with # + ############################## + + if [ "$LINE" = "[$hSection]" -a $hFound = "False" ]; then + + hFound="True" + hLines=`expr $hLines + 1`; export hLines + continue + + fi + + if [ $hFound = "True" ]; then + + lKey=`echo $LINE|cut -d= -f1` + + if [ "$lKey" = "$hKey" ]; then + + # capture everything after first "= sign", + # this is to ensure that if the value of key having + # "= Sign is passed as it is, example SQL1 in config.ini + + lReturn=`echo $LINE|cut -d= -f2-999` + hFound="Completed" + + if [ $hTotalArgs -lt 3 ]; then + + echo "$lReturn" + return 0 + break + fi + + echo "`eval 'echo '$lReturn`" + return 0 + break + + fi + + fi + + hLines=`expr $hLines + 1` + + if [ $hLines -eq $hLineCount ]; then + return 1 + fi + + done + + #if [ "$hCompleted" = "Completed" ]; then + # exit 0 + #else + # exit 1 + #fi + +} + +# +### GetSQLCredentials <<CryptKey>> <<SYSDBA>> <<Credentials>> +### Value +# + +GetSQLCredentials() +{ + + hCryptKey=$1 + hSYSDBA=$2 + hCredentials=$3 + + + # decode userid/password + + if [ ! -z "$hCryptKey" ]; then + + # if crypt key is not ZERO Length, Credentials has to be a crypt file + + if [ ! -f "$hCredentials" ]; then + + echo "Credentials File [$hCredentials] NOT FOUND" + exit 1 + + else + + hCredentials=`crypt "$hCryptKey" < "$hCredentials"` + + fi + + else + + if [ -z "$hCryptKey" -a -f "$hCredentials" ]; then + hCredentials=`cat "$hCredentials"` + fi + + if [ ! -z "$hSYSDBA" -o "$hSYSDBA" = "True" ]; then + hCredentials="/as sysdba" + fi + + + fi + + echo "$hCredentials" + exit 0 + +} + + +# +### GetUserID <<Credentials>> +### Value +# + +GetUserID() +{ + + hCredentials=$1 + + + # decode userid/password + + if [ ! -z "$hCredentials" ]; then + + + hUserID=`echo "$hCredentials"|cut -d "/" -f1` + echo "$hUserID" + exit 0 + + else + + echo "" + exit 1 + + fi + +} + + +# +### GetPassword <<Credentials>> +### Value +# + +GetPassword() +{ + + hCredentials=$1 + + + # decode userid/password + + if [ ! -z "$hCredentials" ]; then + + hPassword=`echo "$hCredentials"|cut -d "/" -f2` + echo "$hPassword" + exit 0 + + else + + echo "" + exit 1 + + fi + +} + +# +### GetLength <<String>> +### Value +# + +GetLength() +{ + + hString=$1 + + hLength=`expr "$hString" : '.*'` + echo "$hLength" + + exit 0 + +} + +# +### SubString <<String>> <<Position>> <<Length>> +### Value +# + +SubString() +{ + + hString=$1 + hPos=$2 + hLength=$3 + + if [ -z "$hLength" ]; then + hLength=`GetLength "$hString"` + fi + + #hReturn=`echo|nawk '{ print substr("'"${hString}"'",${hPos},${hLength}) }'` + hReturn=`echo|nawk '{ print substr("'"${hString}"'","'"${hPos}"'","'"${hLength}"'") }'` + echo "$hReturn" + + exit 0 + +} + + +# +### ReplaceString <<SourceString>> <<String1>> <<String2>> +### Value +# + +ReplaceString() +{ + + hSourceString=$1 + hString1=$2 + hString2=$3 + + #hReturn=`echo "$hSourceString"|sed -e "s/$hString1/$hString2/g"` + hReturn=`echo "$hSourceString"|tr "$hString1" "$hString2"` + + echo "$hReturn" + + exit 0 + +} + + + +# +### RunSQLCommand <<Credentials>> <<SQLCommand>> <<SQLPlusExecutable>> <<TemporaryFile>> <<Arg1>> +### Value +# + +RunSQLCommand() +{ + + hCredentials=$1 + hSQL=$2 + hSQLPlusExecutable=$3 + hTemporaryFile=$4 + + hUserID=`GetUserID "$hCredentials"` + hPassword=`GetPassword "$hCredentials"` + hSQLPlusOutput="" + + `WriteLogFile $hScriptLogFile "Running SQL*Plus $hNewLine" "$hDateFormat"` + + echo "set head off" > $hTemporaryFile + echo "set feed off" >> $hTemporaryFile + echo "set pages 0" >> $hTemporaryFile + echo "set lines 30000" >> $hTemporaryFile + echo "set trimspool on" >> $hTemporaryFile + if [ ! -z "$hSQLPlusOutFile" ]; then + echo "spool $hSQLPlusOutFile" >> $hTemporaryFile + fi + + #if [ "$hSQLFieldSeparator" = "TAB" ]; then + + # echo "col TAB# new_value TAB NOPRINT" >> $hTemporaryFile + # echo "select chr(9) TAB# from dual;" >> $hTemporaryFile + # echo "set colsep "&TAB"" >> $hTemporaryFile + + #fi + + if [ -f "$hSQL" ]; then + + `WriteLogFile $hScriptLogFile "SQL is a file [$hSQL] $hNewLine" "$hDateFormat"` + # Arguments are only valid for SQL File + hArg1=$5 + cat "$hSQL" >> $hTemporaryFile + + else + `WriteLogFile $hScriptLogFile "SQL: $hNewLine ==== $hNewLine $hSQL $hNewLine" "$hDateFormat"` + echo "$hSQL ;" >> $hTemporaryFile + + fi + + echo "exit" >> $hTemporaryFile + + #run SQLPlus + + hUserID=`echo "$hCredentials"|cut -d "/" -f1` + hPassword=`echo "$hCredentials"|cut -d "/" -f2` + + if [ -z "$hUserID" ]; then + hSQLPlusOutput=`echo "$hPassword"|$hSQLPlusExecutable "/as sysdba" @$hTemporaryFile "$hArg1"` + else + hSQLPlusOutput=`echo "$hPassword"|$hSQLPlusExecutable "$hUserID" @$hTemporaryFile "$hArg1"` + fi + + hSQLPlusOutput=`echo "$hSQLPlusOutput"|grep -v "Enter password:"` + rm "$hTemporaryFile" + + hErrorMessage=`echo "$hSQLPlusOutput"|grep ORA-|grep -v ORA-00271` + + if [ ! -z "$hErrorMessage" ]; then + + `WriteLogFile $hScriptLogFile "SQL*Plus Failed with ERROR $hNewLine [$hErrorMessage] $hNewLine" "$hDateFormat"` + echo "$hErrorMessage" + exit 1 + + else + + `WriteLogFile $hScriptLogFile "SQL*Plus Output: $hNewLine ================ $hNewLine $hSQLPlusOutput $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "SQL*Plus completed SUCCESSFULLY $hNewLine" "$hDateFormat"` + echo "$hSQLPlusOutput" + exit 0 + + + fi + +} + +# +### RunFilerCommand <<CommandTYPE>> <<COMMAND>> +### Value +# + +RunFilerCommand() +{ + + hCommandType=$1 + hCommand=`eval 'print '$2` + hCount=0 + hReturn="" + + if [ "$hCommandType" = "LIST" ]; then + hCommand="$hCommand | grep $SNAPSHOT" + fi + + while [ $hCount -lt $hRetryAttempt ]; + do + + hCount=`expr $hCount + 1` + + `WriteLogFile $hScriptLogFile "[Attempt $hCount of $hRetryAttempt] = Running Filer Command [$hCommand] $hNewLine" "$hDateFormat"` + + print "$hCommand" > "$hTemporaryFile.sh" + chmod 755 "$hTemporaryFile.sh" + + #$hCommand > $hTemporaryFile.flr 2>&1 + $hTemporaryFile.sh > $hTemporaryFile.flr 2>&1 + + hReturn=`cat $hTemporaryFile.flr` + rm "$hTemporaryFile.flr" + rm "$hTemporaryFile.sh" + + if [ "$hCommandType" = "DELETE" ]; then + + if [ "$hReturn" = 'deleting snapshot...' ]; then + echo "$hReturn DELETED" + exit 0 + elif [ "$hReturn" = 'No such snapshot.' ]; then + echo "$hReturn - NOT FOUND" + exit 0 + fi + + elif [ "$hCommandType" = "CREATE" ]; then + + if [ "$hReturn" = 'creating snapshot...' ]; then + echo "$hReturn - CREATED" + exit 0 + elif [ "$hReturn" = 'Snapshot already exists.' ]; then + echo "$hReturn - ALREADY EXISTS" + exit 0 + fi + + elif [ "$hCommandType" = "RENAME" ]; then + + if [ "$hReturn" = '' ]; then + echo "$hReturn - RENAMED" + exit 0 + elif [ "$hReturn" = 'No such snapshot.' ]; then + echo "$hReturn - NOT FOUND" + exit 0 + fi + elif [ "$hCommandType" = "LIST" ]; then + + if [ ! -z "$hReturn" ]; then + echo "$hReturn" + else + echo "$hReturn - NOT FOUND" + fi + exit 0 + + fi + + `WriteLogFile $hScriptLogFile "Command failed with error: $hNewLine $hReturn ... $hNewLine Retrying in $hRetryDelayInSeconds seconds $hNewLine" "$hDateFormat"` + + sleep $hRetryDelayInSeconds + + done + + echo "$hCommand$hNewLine$hReturn" + exit 1 + +} + + + +# +### TakeSnap <<FILER>> <<VOLUME>> <<COMMAND>> <<SNAPSHOT1>> <<SNAPSHOT2>> +### Value CREATE/DELETE/RENAME snapname1 snapname2 +# + +TakeSnap() +{ + + FILER=$1 + VOLUME=$2 + hCommand="$3" + hSnapshot1="$4" + hSnapshot2="$5" + + # DELETE SNAPSHOT + if [ ! -z "$hSnapshot1" ]; then + SNAPSHOT=$hSnapshot1 + else + SNAPSHOT=$hNamePattern.$hSnapshotKeepDays + fi + + if [ -z "$hCommand" -o "$hCommand" = "DELETE" ]; then + + hReturn=`RunFilerCommand "DELETE" "$hDeleteSnapshotCommand"` + + if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "DELETE Filer Command COMPLETED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + else + `WriteLogFile $hScriptLogFile "DELETE Filer Command FAILED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + exit 1 + fi + + fi + + # RENAME SNAPSHOT + hCount=$hSnapshotKeepDays + if [ -z "$hCommand" -o "$hCommand" = "RENAME" ]; then + + while [ $hCount -gt 0 ]; + do + + if [ "$hSnapshot1" = "" -a "$hSnapshot2" = "" ]; then + hCount=`expr $hCount - 1` + FROM_SNAPSHOT=$hNamePattern.$hCount + TO_SNAPSHOT=$hNamePattern.`expr $hCount + 1` + else + FROM_SNAPSHOT=$hSnapshot1 + TO_SNAPSHOT=$hSnapshot2 + # if from/to name is passed exit the loop after running one iteration + hCount=0 + fi + + hReturn=`RunFilerCommand "RENAME" "$hRenameSnapshotCommand"` + if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "RENAME Filer Command COMPLETED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + else + `WriteLogFile $hScriptLogFile "RENAME Filer Command FAILED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + exit 1 + fi + + done + + fi + + # CREATE SNAPSHOT + if [ ! -z "$hSnapshot1" ]; then + SNAPSHOT=$hSnapshot1 + else + SNAPSHOT=$hNamePattern.0 + fi + + if [ -z "$hCommand" -o "$hCommand" = "CREATE" ]; then + + hReturn=`RunFilerCommand "CREATE" "$hCreateSnapshotCommand"` + if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "CREATE Filer Command COMPLETED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + else + `WriteLogFile $hScriptLogFile "CREATE Filer Command FAILED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + exit 1 + fi + + fi + + # LIST SNAPSHOT + if [ ! -z "$hSnapshot1" ]; then + SNAPSHOT=$hSnapshot1 + else + SNAPSHOT=$hNamePattern.0 + fi + + if [ "$hCommand" = "LIST" ]; then + + hReturn=`RunFilerCommand "LIST" "$hListSnapshotCommand"` + if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "LIST Filer Command COMPLETED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + else + `WriteLogFile $hScriptLogFile "LIST Filer Command FAILED [$hReturn] $hNewLine" "$hDateFormat"` + echo "$hReturn" + exit 1 + fi + + fi + + exit 0 + +} + + +# +### WriteHistoryRecord <<record to be written separated by TAB>> +### Value +# + +WriteHistoryRecord () +{ + + hDate=`GetDate $hDateFormat` + + if [ ! -z "$hHistoryFile" ]; then + + echo "$hDate\t$*" >> $hHistoryFile + + if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "History Record Written $hNewLine" "$hDateFormat"` + exit 0 + else + `WriteLogFile $hScriptLogFile "History Record NOT Written $hNewLine" "$hDateFormat"` + exit 1 + fi + + fi + + exit 0 + +} + +# +### ToUpper +### Value +# + +ToUpper () +{ + echo $1 | tr '[a-z]' '[A-Z]' + return 0 +} + +# +### ToUpper +### Value +# + +ToLower () +{ + echo $1 | tr '[A-Z]' '[a-z]' + return 0 +} + + +# +### MyEval +### Value +# + +MyEval() +{ + echo "`eval 'echo '$1`" + return 0 +} + diff --git a/bin/crypt b/bin/crypt new file mode 100644 index 0000000..f8b7019 --- /dev/null +++ b/bin/crypt @@ -0,0 +1,24 @@ +#!/usr/bin/perl -w +############################################################### +# Created by: Unknown +# Updated by: Habib Rangoonwala +# Updated: 16-Mar-2007 +############################################################### + +$pass = shift or die "Usage: ", $0 =~ /([^\/]*$)/, " passwd < file\n"; + +undef $/; # Set "slurp mode" +@file = split //, <>; # Make a 'character' array from file + +# Tweak the password itself to avoid "known text XOR" attack +@pass = map{ +$x = ord; +$y = ( $x + 10 ) ** 2 % 256; +$z = ( $x - 10 ) ** 2 % 256; +chr ( $y ^ $z ) +} split //, $pass; + +# Write to file +print chr( ord $file[$_] ^ ord $pass[$_ % scalar @pass] ) for 0 .. $#file + + diff --git a/bin/hAlertLogMonitor.ksh b/bin/hAlertLogMonitor.ksh new file mode 100644 index 0000000..436005c --- /dev/null +++ b/bin/hAlertLogMonitor.ksh @@ -0,0 +1,497 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-May-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Alert Log Monitor [Mail Alert]" +hPageAlertTitle="Alert Log Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# Read Script Specific Configuration Parameter +hAlertLogFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "AlertLogFile" "True"` +hScriptReferenceFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ScriptReferenceFile" "True"` + +hMailKeywords=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailKeywords"` +hPageKeywords=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageKeywords"` + +hMailKeywordsIgnoreList=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailKeywordsIgnoreList"` +hPageKeywordsIgnoreList=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageKeywordsIgnoreList"` + +hDisplayFullRecord=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DisplayFullRecord"` + +hConfigReadTime=`GetElapsedTime` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "AlertLogFile: $hAlertLogFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ReferenceFile: $hScriptReferenceFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "MailKeywords: $hMailKeywords $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "MailKeywordsIgnore:$hMailKeywordsIgnoreList $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageKeywords: $hPageKeywords $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageKeywordsIgnore:$hPageKeywordsIgnoreList $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "DisplayFullRecord: $hDisplayFullRecord $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +#==================================== +# Check if the File exists! +#==================================== +if [ -f "$hAlertLogFile" ]; then + `WriteLogFile $hScriptLogFile "File [$hAlertLogFile] Exists $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "File [$hAlertLogFile] is missing $hNewLine" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "File [$hAlertLogFile] is missing."` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 +fi + + +#===================================== +# Get the number of lines in the file +#===================================== +hTotalLines=`wc -l "$hAlertLogFile"` + +# just extract NumberOfLines from output <NoOfLines> <FileName> +hTotalLines=`echo $hTotalLines | cut -f 1 -d " "` + +if [ $hTotalLines -gt 0 ]; then + `WriteLogFile $hScriptLogFile "File [$hAlertLogFile] has $hTotalLines Lines $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "File [$hAlertLogFile] has ZERO Lines $hNewLine" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "File [$hAlertLogFile] has ZERO Lines."` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 +fi + +#=========================================================== +# Check for Reference File with line count from previous run +#=========================================================== + +hPreviousLineCount=0 + +if [ -f $hScriptReferenceFile ]; then + `WriteLogFile $hScriptLogFile "ScriptReferenceFile [$hScriptReferenceFile] Exists and its Writable $hNewLine" "$hDateFormat"` + hPreviousLineCount=`cat $hScriptReferenceFile` + `WriteLogFile $hScriptLogFile "ScriptReferenceFile Previous Line Count is $hPreviousLineCount $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "Creating ScriptReferenceFile [$hScriptReferenceFile] $hNewLine" "$hDateFormat"` + # creating Script Reference File and redirecting the error message to TempFile + (echo $hPreviousLineCount > $hScriptReferenceFile) 2> $hTemporaryFile + + if [ $? -gt 0 ]; then + + hMailErrorMessage=`cat $hTemporaryFile` + `WriteLogFile $hScriptLogFile "Unable to Create ScriptReferenceFile [$hScriptReferenceFile] $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "OS Error Message [$hMailErrorMessage] $hNewLine" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "Unable to Create ScriptReferenceFile [$hScriptReferenceFile]" "OS Error Message [$hMailErrorMessage]"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + else + `WriteLogFile $hScriptLogFile "Created ScriptReferenceFile [$hScriptReferenceFile] $hNewLine" "$hDateFormat"` + fi +fi + +#========================================== +# Update Reference File with new line count +#========================================== + +(echo $hTotalLines > $hScriptReferenceFile) 2> $hTemporaryFile +if [ $? -ne 0 ]; then + + hMailErrorMessage=`cat $hTemporaryFile` + `WriteLogFile $hScriptLogFile "Unable Reset ScriptReferenceFile [$hScriptReferenceFile] $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "OS Error Message [$hMailErrorMessage] $hNewLine" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "Unable Reset ScriptReferenceFile [$hScriptReferenceFile]" "OS Error Message [$hMailErrorMessage]"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 +fi + +#================================================================= +# Find out how many lines needs to be processed in alert.log file +#================================================================= +hNewLines=0 +if [ $hTotalLines -ge $hPreviousLineCount ]; then + hNewLines=`expr $hTotalLines - $hPreviousLineCount` +else + hNewLines=$hTotalLines +fi + + +#==================== +# Process new lines +#==================== + +# declare an array to store all the lines from last run + +hAlertLogLines="" +hMailErrorMessage="" +hPageErrorMessage="" +hTimeStampLine="" + +hMailErrorCount=0 +hPageErrorCount=0 + +if [ $hNewLines -eq 0 ]; then + `WriteLogFile $hScriptLogFile "No New Lines to be processed $hNewLine" "$hDateFormat"` +else + + `WriteLogFile $hScriptLogFile "Number of Lines to be processed = $hNewLines $hNewLine" "$hDateFormat"` + hTmpCount=0 + + # read all the lines to be processed + # also write it to history file + hAlertLogText=`tail -$hNewLines $hAlertLogFile` + echo "$hAlertLogText" | while read LINE; + do + hAlertLogLines[$hTmpCount]="$LINE" + hTmpCount=`expr $hTmpCount + 1` + + hTmpString=`echo $LINE | cut -f 1 -d " "` + + if [ ! -z `echo "Sun Mon Tue Wed Thu Fri Sat"|grep "$hTmpString"` ]; then + hTimeStampLine="$LINE" + fi + + for hKeyword in $hMailKeywords; + do + + hLine=`echo $LINE | grep -i $hKeyword` + + # write history record + if [ ! -z "$hLine" ]; then + hReturn=`WriteHistoryRecord "$hTimeStampLine\t$hLine"` + break + fi + + done + + done + + + # loop thru each MailKeywords + # +-+-+-+-+-+-+-+-+-+-+-+-+-+ + + `WriteLogFile $hScriptLogFile "Scanning file for MailKeywords $hNewLine" "$hDateFormat"` + + hTmpCount=0 + while [ $hTmpCount -lt $hNewLines ] + do + + for hKeyword in $hMailKeywords; + do + + hLine=`echo ${hAlertLogLines[$hTmpCount]} | grep -i $hKeyword` + + # check if the its listed in ignore keyword + if [ ! -z "$hMailKeywordsIgnoreList" -a ! -z "$hLine" ]; then + + for hIgnoreKeyword in $hMailKeywordsIgnoreList; + do + hLine=`echo $hLine | grep -iv $hIgnoreKeyword` + done + + if [ -z "$hLine" ]; then + `WriteLogFile $hScriptLogFile "IGNORED:${hAlertLogLines[$hTmpCount]} " "$hDateFormat"` + fi + + fi + + # check if the keyword exist in the alert line + if [ ! -z "$hLine" ]; then + + # check if full record needs to be printed, i.e. from timestamp to timestamp + if [ "$hDisplayFullRecord" = "True" -o "$hDisplayFullRecord" = "true" ]; then + + hTmpNumber=$hTmpCount + + # loop to navigate to the timestamp + while true + do + + if [ $hTmpNumber -le 0 ]; then + break + fi + + hTmpNumber=`expr $hTmpNumber - 1` + + hTmpString=`echo ${hAlertLogLines[$hTmpNumber]} | cut -f 1 -d " "` + + if [ -z `echo "Sun Mon Tue Wed Thu Fri Sat"|grep "$hTmpString"` ]; then + + if [ $hTmpNumber -le 0 ]; then + break + fi + + else + break + fi + + done + + # loop to extract all the record lines i.e. from timestamp to next timestamp + + hMailErrorMessage[$hMailErrorCount]='___BEGIN___' + hMailErrorCount=`expr $hMailErrorCount + 1` + + while true + do + + hMailErrorMessage[$hMailErrorCount]="${hAlertLogLines[$hTmpNumber]}" + hAlertLineNo=`expr $hPreviousLineCount + $hTmpNumber + 1` + `WriteLogFile $hScriptLogFile "* Line#$hAlertLineNo [${hAlertLogLines[$hTmpNumber]}] * $hNewLine" "$hDateFormat"` + hTmpNumber=`expr $hTmpNumber + 1` + hMailErrorCount=`expr $hMailErrorCount + 1` + + hTmpString=`echo ${hAlertLogLines[$hTmpNumber]} | cut -f 1 -d " "` + + if [ ! -z `echo "Sun Mon Tue Wed Thu Fri Sat"|grep "$hTmpString"` ]; then + break + else + if [ $hTmpNumber -ge $hNewLines ]; then + break + fi + fi + + done + + hMailErrorMessage[$hMailErrorCount]='___END___' + hMailErrorCount=`expr $hMailErrorCount + 1` + + hTmpCount=$hTmpNumber + + else + + # when only single error line is required in email + + hMailErrorMessage[$hMailErrorCount]='___BEGIN___' + hMailErrorCount=`expr $hMailErrorCount + 1` + + hMailErrorMessage[$hMailErrorCount]="$hLine" + hMailErrorCount=`expr $hMailErrorCount + 1` + + hMailErrorMessage[$hMailErrorCount]='___END___' + hMailErrorCount=`expr $hMailErrorCount + 1` + + hAlertLineNo=`expr $hPreviousLineCount + $hTmpCount + 1` + `WriteLogFile $hScriptLogFile "* Line#$hAlertLineNo [$hLine] * $hNewLine" "$hDateFormat"` + fi + fi + + + done + + hTmpCount=`expr $hTmpCount + 1` + + done + + if [ $hMailErrorCount -eq 0 ]; then + `WriteLogFile $hScriptLogFile "No Mail Errors Found $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "Total Mail Errors Count is $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending MailAlert to $hMailAlias" "$hDateFormat"` + + hTmpCount=0 + + # truncate Temporary File + echo "Error Messages" > $hTemporaryFile + + while [ $hTmpCount -lt $hMailErrorCount ]; + do + + if [ "${hMailErrorMessage[$hTmpCount]}" != "___BEGIN___" -a "${hMailErrorMessage[$hTmpCount]}" != "___END___" ]; then + printf "${hMailErrorMessage[$hTmpCount]}___NEWLINE___" >> $hTemporaryFile + fi + if [ "${hMailErrorMessage[$hTmpCount]}" = "___END___" ]; then + echo "$hNewLine" >> $hTemporaryFile + fi + + hTmpCount=`expr $hTmpCount + 1` + + done + + # send alert + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle"` + `WriteLogFile $hScriptLogFile "MailAlert sent to $hMailAlias" "$hDateFormat"` + + fi + + + # loop thru each PageKeywords + # +-+-+-+-+-+-+-+-+-+-+-+-+-+ + + `WriteLogFile $hScriptLogFile "Scanning file for PageKeywords $hNewLine" "$hDateFormat"` + + hTmpCount=0 + while [ $hTmpCount -lt $hNewLines ] + do + + for hKeyword in $hPageKeywords; + do + + hLine=`echo ${hAlertLogLines[$hTmpCount]} | grep -i $hKeyword|grep -iv ora-00060` + + # check if the its listed in ignore keyword + if [ ! -z "$hPageKeywordsIgnoreList" -a ! -z "$hLine" ]; then + + for hIgnoreKeyword in $hPageKeywordsIgnoreList; + do + hLine=`echo $hLine | grep -iv $hIgnoreKeyword` + done + + if [ -z "$hLine" ]; then + `WriteLogFile $hScriptLogFile "IGNORED:${hAlertLogLines[$hTmpCount]} " "$hDateFormat"` + fi + + fi + + # check if the keyword exist in the alert line + if [ ! -z "$hLine" ]; then + + # check if full record needs to be printed, i.e. from timestamp to timestamp + if [ "$hDisplayFullRecord" = "True" -o "$hDisplayFullRecord" = "true" ]; then + + hTmpNumber=$hTmpCount + + # loop to navigate to the timestamp + while true + do + + if [ $hTmpNumber -le 0 ]; then + break + fi + + hTmpNumber=`expr $hTmpNumber - 1` + + hTmpString=`echo ${hAlertLogLines[$hTmpNumber]} | cut -f 1 -d " "` + + if [ -z `echo "Sun Mon Tue Wed Thu Fri Sat"|grep "$hTmpString"` ]; then + + if [ $hTmpNumber -le 0 ]; then + break + fi + + else + break + fi + + done + + # loop to extract all the record lines i.e. from timestamp to next timestamp + + hPageErrorMessage[$hPageErrorCount]='___BEGIN___' + hPageErrorCount=`expr $hPageErrorCount + 1` + + while true + do + + hPageErrorMessage[$hPageErrorCount]="${hAlertLogLines[$hTmpNumber]}" + hAlertLineNo=`expr $hPreviousLineCount + $hTmpNumber + 1` + `WriteLogFile $hScriptLogFile "* Line#$hAlertLineNo [${hAlertLogLines[$hTmpNumber]}] * $hNewLine" "$hDateFormat"` + hTmpNumber=`expr $hTmpNumber + 1` + hPageErrorCount=`expr $hPageErrorCount + 1` + + hTmpString=`echo ${hAlertLogLines[$hTmpNumber]} | cut -f 1 -d " "` + + if [ ! -z `echo "Sun Mon Tue Wed Thu Fri Sat"|grep "$hTmpString"` ]; then + break + else + if [ $hTmpNumber -ge $hNewLines ]; then + break + fi + fi + + done + + hPageErrorMessage[$hPageErrorCount]='___END___' + hPageErrorCount=`expr $hPageErrorCount + 1` + + hTmpCount=$hTmpNumber + + else + + # when only single error line is required in email + + hPageErrorMessage[$hPageErrorCount]='___BEGIN___' + hPageErrorCount=`expr $hPageErrorCount + 1` + + hPageErrorMessage[$hPageErrorCount]="$hLine" + hPageErrorCount=`expr $hPageErrorCount + 1` + + hPageErrorMessage[$hPageErrorCount]='___END___' + hPageErrorCount=`expr $hPageErrorCount + 1` + + + hAlertLineNo=`expr $hPreviousLineCount + $hTmpCount + 1` + `WriteLogFile $hScriptLogFile "* Line#$hAlertLineNo [$hLine] * $hNewLine" "$hDateFormat"` + fi + fi + + + done + + hTmpCount=`expr $hTmpCount + 1` + + done + + + if [ $hPageErrorCount -eq 0 ]; then + `WriteLogFile $hScriptLogFile "No Page Errors Found $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "Total Page Errors Count is $hPageErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending PageAlert to $hPageAlias" "$hDateFormat"` + + hTmpCount=0 + + # truncate Temporary File + echo "Error Messages" > $hTemporaryFile + + while [ $hTmpCount -lt $hPageErrorCount ]; + do + + if [ "${hPageErrorMessage[$hTmpCount]}" != "___BEGIN___" -a "${hPageErrorMessage[$hTmpCount]}" != "___END___" ]; then + printf "${hPageErrorMessage[$hTmpCount]}___NEWLINE___" >> $hTemporaryFile + fi + + if [ "${hPageErrorMessage[$hTmpCount]}" = "___END___" ]; then + echo "$hNewLine" >> $hTemporaryFile + fi + + hTmpCount=`expr $hTmpCount + 1` + + done + + # send alert + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle"` + `WriteLogFile $hScriptLogFile "PageAlert sent to $hPageAlias" "$hDateFormat"` + + fi + +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hArchCleanup.ksh b/bin/hArchCleanup.ksh new file mode 100644 index 0000000..1a4d207 --- /dev/null +++ b/bin/hArchCleanup.ksh @@ -0,0 +1,44 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 30-Jan-2009 +# Updation Date: 30-Jan-2009 +# Updation Date: 07-Feb-2010 [Fixed hArchSQL1, where LOCATION is written in mix characters like upper/lower +# This script cannot be run individually, it should be +# invoked by hHotBackup.ksh script +############################################################### + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +#hArchSQL1="SELECT REPLACE(value,'location=') FROM v\$parameter WHERE name LIKE 'log_archive_dest%' AND name NOT LIKE 'log_archive_dest%state%'" +# above SQL doesnt work with upper case LOCATION, fixed it as below +hArchSQL1="SELECT SUBSTR(value,INSTR(value,'=')+1) FROM v\$parameter WHERE name LIKE 'log_archive_dest%' AND name NOT LIKE 'log_archive_dest%state%'" +hArchSQL2="SELECT SUBSTR(value,1,INSTR(value,'%')-1)||'*'||SUBSTR(value,INSTR(value,'.')) FROM v\$parameter WHERE name='log_archive_format'" + +hOutput=`RunSQLCommand "$hCredentials" "$hArchSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` +hLogArchiveFormat=`RunSQLCommand "$hCredentials" "$hArchSQL2" "$hSQLPlusExecutable" "$hTemporaryFile"` + +echo "$hOutput"|while read hARCHDEST; +do + + if [ ! -z $hARCHDEST ]; then + hArchRMCommand="find $hARCHDEST/* -name $hLogArchiveFormat -mtime +$hArchKeepDays -exec ls -ltr {}" + `WriteLogFile $hScriptLogFile "Command being run [$hArchRMCommand] $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Following ARCH files are being DELETED[$hARCHDEST/$hLogArchiveFormat]: $hNewLine" "$hDateFormat"` + hArchFileList=`find $hARCHDEST/* -name $hLogArchiveFormat -mtime +$hArchKeepDays -exec ls -ltr {} \;` + if [ ! -z "$hArchFileList" ]; then + hArchFileCount=`echo "$hArchFileList"|wc -l` + else + hArchFileCount=0 + fi + `WriteLogFile $hScriptLogFile "$hArchFileList $hNewLine" "$hDateFormat"` + hArchFileList=`find $hARCHDEST/* -name $hLogArchiveFormat -mtime +$hArchKeepDays -exec rm {} \;` + `WriteLogFile $hScriptLogFile "RM Output:$hArchFileList $hNewLine" "$hDateFormat"` + fi + +done + +exit $hArchFileCount diff --git a/bin/hCLONEPreparation.ksh b/bin/hCLONEPreparation.ksh new file mode 100644 index 0000000..6d95294 --- /dev/null +++ b/bin/hCLONEPreparation.ksh @@ -0,0 +1,134 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 31-Jul-2009 +# Updation Date: 31-Jul-2009 +# Updation Date: 07-Feb-2010 [fixed CLONEDirectory, multiple ARCHDEST causes duplicate files, hardcoded dest_id=1 in SQL1 and SQL3 +# +# This script cannot be run individually, it should be +# invoked by hHotBackup.ksh script +############################################################### + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +`WriteLogFile $hScriptLogFile "*** Running CLONE Preparation Script *** $hNewLine" "$hDateFormat"` + +hCLONEControlFile="$hCLONEDirectory/hCLONEControlFile.sql" + +if [ ! -d "$hCLONEDirectory" ]; then + mkdir -p "$hCLONEDirectory" + + `WriteLogFile $hScriptLogFile "Created $hCLONEDirectory $hNewLine" "$hDateFormat"` +fi + +# script to generate recovery control file script +hControlFileSQL="ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '$hCLONEControlFile' REUSE RESETLOGS" +hOutput=`RunSQLCommand "$hCredentials" "$hControlFileSQL" "$hSQLPlusExecutable" "$hTemporaryFile"` +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to generate BACKUP CONTROLFILE" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi + +# include SET database in control file sql script +sed -e "s/CREATE CONTROLFILE REUSE/CREATE CONTROLFILE REUSE SET/" "$hCLONEControlFile" > "$hCLONEControlFile.2" +mv "$hCLONEControlFile.2" "$hCLONEControlFile" + +# add UNTIL CANCEL in control file sql script +sed -e "s/RECOVER DATABASE USING BACKUP CONTROLFILE/RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL/" "$hCLONEControlFile" > "$hCLONEControlFile.2" +mv "$hCLONEControlFile.2" "$hCLONEControlFile" + + +# script to copy ARCH files to RECOVERY destination + +hArchSQL1="SELECT name FROM v\$archived_log WHERE sequence# BETWEEN $hStartSequence AND $hEndSequence AND dest_id=1 AND resetlogs_change# = (SELECT resetlogs_change# FROM v\$database) ORDER BY name" +hArchSQL2="SELECT SUBSTR(value,1,INSTR(value,'%')-1)||'*'||SUBSTR(value,INSTR(value,'.')) FROM v\$parameter WHERE name='log_archive_format'" +hArchSQL3="SELECT REPLACE(name,(SELECT value FROM v\$parameter WHERE name='log_archive_dest'),'$hCLONEDirectory') FROM v\$archived_log WHERE sequence# BETWEEN $hStartSequence AND $hEndSequence AND dest_id=1 ORDER BY name" + +hArchFileList=`RunSQLCommand "$hCredentials" "$hArchSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` +hArchFileList2=`RunSQLCommand "$hCredentials" "$hArchSQL3" "$hSQLPlusExecutable" "$hTemporaryFile"` +hLogArchiveFormat=`RunSQLCommand "$hCredentials" "$hArchSQL2" "$hSQLPlusExecutable" "$hTemporaryFile"` + +hRMList=`ls -ltr $hCLONEDirectory/$hLogArchiveFormat` +`WriteLogFile $hScriptLogFile "Following CLONED-ARCH files from previous run are being DELETED[$hCLONEDirectory]: $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hRMList $hNewLine" "$hDateFormat"` +hRMOuput=`rm $hCLONEDirectory/$hLogArchiveFormat` +`WriteLogFile $hScriptLogFile "RM Output: $hRMOutput $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "STARTING ARCH File COPY to CLONEDirectory=$hCLONEDirectory $hNewLine" "$hDateFormat"` + +echo "$hArchFileList"|while read hArchFile; +do + + if [ ! -z $hArchFile ]; then + `WriteLogFile $hScriptLogFile "Copying $hArchFile to $hCLONEDirectory $hNewLine" "$hDateFormat"` + hCPOutput=`cp $hArchFile $hCLONEDirectory` + hCPStatus=$? + if [ $hCPStatus -eq 0 ]; then + `WriteLogFile $hScriptLogFile "ARCH File Copy SUCCESS $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "ARCH File Copy FAILED [$hCPOutput] $hNewLine" "$hDateFormat"` + exit 1 + fi + fi + +done + +`WriteLogFile $hScriptLogFile "Successfully COPIED from Seq#$hStartSequence To Seq#$hEndSequence $hNewLine" "$hDateFormat"` + +# add the list of ARCH files to control file sql script +#sed -e "s/$/\\\/" hsr.txt ## to add "\" at the end of the line + +> "$hCLONEControlFile.2" + +cat "$hCLONEControlFile"|while read LINE; +do + + # alternatively we can use """sed -e '/^$/d' hCLONEControlFile.sql > h.sql"""" + if [ ! -z "$LINE" ]; then + echo "$LINE" >> "$hCLONEControlFile.2" + fi + + if [ "$LINE" = "RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL" ]; then + echo "$hArchFileList2" >> "$hCLONEControlFile.2" + echo "CANCEL" >> "$hCLONEControlFile.2" + fi + +done + +mv "$hCLONEControlFile.2" "$hCLONEControlFile" + +if [ $? -eq 0 ]; then + `WriteLogFile $hScriptLogFile "Successfully UPDATED BACKUP CONTROLFILE with ARCH file Information $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "Unable to update BACKUP CONTROLFILE with ARCH file Information $hNewLine" "$hDateFormat"` +fi + +# take CLONEPreparationVolume Snapshot +hCLONEPreparationVolume=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CLONEPreparationVolume"` + +if [ ! -z "$hCLONEPreparationVolume" ]; then + + hFiler=`echo "$hCLONEPreparationVolume"|cut -d ":" -f1` + hVolume=`echo "$hCLONEPreparationVolume"|cut -d ":" -f2` + + hReturn=`TakeSnap "$hFiler" "$hVolume"` + if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to run filer command" "$hReturn"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + fi + +else + + `WriteLogFile $hScriptLogFile "CLONEPreparationVolume NOT Defined $hNewLine" "$hDateFormat"` + +fi + +exit 0 \ No newline at end of file diff --git a/bin/hCMQueueMonitor.ksh b/bin/hCMQueueMonitor.ksh new file mode 100644 index 0000000..45bf316 --- /dev/null +++ b/bin/hCMQueueMonitor.ksh @@ -0,0 +1,236 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 09-Sep-2008 +# Updation Date: 09-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + + +# define Alert Title +hMailAlertTitle="CM Queue Monitor [Mail Alert]" +hPageAlertTitle="CM Queue Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1") +hSQL2=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2" "True") +hQueueMailLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "QueueMailLimit") +hQueuePageLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "QueuePageLimit") + +hConfigReadTime=$(GetElapsedTime) + +# write Script Specific Details to logfile +$(WriteLogFile $hScriptLogFile "QueueMailLimit: $hQueueMailLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "QueuePageLimit: $hQueuePageLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat") + +#run SQLPlus [find out CM Status] + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL2" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + $(WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +hCMStatus=`echo "$hSQLPlusOutput" | grep DOWN` + +if [ ! -z "$hCMStatus" ]; then + + $(WriteLogFile $hScriptLogFile "Page Alert: CM is DOWN $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Output: $hSQLPlusOutput $hNewLine" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject: CM-DOWN" "$hPageAlertTitle" "CM is DOWN [$hSQLPlusOutput]") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +#run SQLPlus + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + $(WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +hQueueMailLimit=$(ReplaceString "$hQueueMailLimit" ";" "\n") +hQueuePageLimit=$(ReplaceString "$hQueuePageLimit" ";" "\n") + +# find out the DEFAULT mail limit +hDefaultString=$(echo "$hQueueMailLimit" | grep "DEFAULT") +hDefaultMailLimit=$(echo "$hDefaultString"|cut -d: -f2) + +# find out the DEFAULT page limit +hDefaultString=$(echo "$hQueuePageLimit" | grep "DEFAULT") +hDefaultPageLimit=$(echo "$hDefaultString"|cut -d: -f2) + +# create two files [one for page alert and other for mail alert] +hMailFile=$hTemporaryFile.mail +hPageFile=$hTemporaryFile.page + +hMailErrorCount=0 +hPageErrorCount=0 + +printf "Queue Name\tQueue Description\tMax Processes\tRunning Processes\tRunning Requests\tPending Requests\tMail Condition\tStatus\n" > $hMailFile +printf "Queue Name\tQueue Description\tMax Processes\tRunning Processes\tRunning Requests\tPending Requests\tPage Condition\tStatus\n" > $hPageFile + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hQueueName=$(GetColumnValue "$LINE" "1") + hQueueDescription=$(GetColumnValue "$LINE" "2") + hMaxProcesses=$(GetColumnValue "$LINE" "3") + hRunningProcesses=$(GetColumnValue "$LINE" "4") + hPending=$(GetColumnValue "$LINE" "5") + hRunningRequests=$(GetColumnValue "$LINE" "6") + + hMailString=$(echo "$hQueueMailLimit" | grep "$hQueueName") + hMailQueueNameToCheck=$(echo "$hMailString"|cut -d: -f1) + hMailLimit=$(echo "$hMailString"|cut -d: -f2) + + hPageString=$(echo "$hQueuePageLimit" | grep "$hQueueName") + hPageQueueNameToCheck=$(echo "$hPageString"|cut -d: -f1) + hPageLimit=$(echo "$hPageString"|cut -d: -f2) + + hStatus="OK" + + # check if PENDING request satiesfies MAIL CONDITION or DEFAULT MAILCONDITION + if [ "$hQueueName" = "$hMailQueueNameToCheck" ]; then + + if [ "$hPending" -ge "$hMailLimit" ]; then + + hMailErrorCount=$(expr $hMailErrorCount + 1) + if [ "$hPending" -ge "$hPageLimit" ]; then + hStatus="CRITICAL" + else + hStatus="WARNING" + fi + fi + + else + + hMailLimit="$hDefaultMailLimit*" + + if [ "$hPending" -ge "$hDefaultMailLimit" ]; then + + hMailErrorCount=$(expr $hMailErrorCount + 1) + if [ "$hPending" -ge "$hPageLimit" ]; then + hStatus="CRITICAL" + else + hStatus="WARNING" + fi + + fi + + fi + + # no matter if mail alert is satiesfied, write to mailfile + printf "$hQueueName\t$hQueueDescription\t$hMaxProcesses\t$hRunningProcesses\t$hRunningRequests\t$hPending\t$hMailLimit\t$hStatus\n" >> $hMailFile + + # check if PENDING request satisfies PAGE CONDITION or DEFAULT PAGECONDITION + if [ "$hQueueName" = "$hPageQueueNameToCheck" ]; then + + if [ "$hPending" -ge "$hPageLimit" ]; then + + hPageErrorCount=$(expr $hPageErrorCount + 1) + hStatus="CRITICAL" + + fi + + else + + hPageLimit="$hDefaultPageLimit*" + + if [ "$hPending" -ge "$hDefaultPageLimit" ]; then + + hPageErrorCount=$(expr $hPageErrorCount + 1) + hStatus="CRITICAL*" + + fi + + fi + + # if PAGE ALERT is satisfied then write to PageFile + if [ "$hStatus" = "CRITICAL" ] || [ "$hStatus" = "CRITICAL*" ]; then + printf "$hQueueName\t$hQueueDescription\t$hMaxProcesses\t$hRunningProcesses\t$hRunningRequests\t$hPending\t$hPageLimit\t$hStatus\n" >> $hPageFile + fi + + # write history record + hReturn=$(WriteHistoryRecord "$hConfigReadTime\t$hQueueName\t$hMaxProcesses\t$hRunningProcesses\t$hRunningRequests\t$hPending\t$hMailLimit\t$hPageLimit\t$hStatus") + + fi + +done + +if [ "$hMailErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hMailFile" "$hFromAlias" "$hMailAlias" "$hMailSubject [$hMailErrorCount Queue(s) reported]" "$hMailAlertTitle" "9") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat") +else + $(WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat") + rm "$hMailFile" +fi + +if [ "$hPageErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hPageFile" "$hFromAlias" "$hPageAlias" "$hMailSubject [$hPageErrorCount Queue(s) reported]" "$hPageAlertTitle" "9") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") +else + $(WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat") + rm "$hPageFile" +fi + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +$(WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat") + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 + diff --git a/bin/hColdBackup.ksh b/bin/hColdBackup.ksh new file mode 100644 index 0000000..3d7d007 --- /dev/null +++ b/bin/hColdBackup.ksh @@ -0,0 +1,122 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 07-Feb-2010 +# Updation Date: 07-Feb-2010 +############################################################### + +# define Alert Title +hMailAlertTitle="ColdBackup [Mail Alert]" +hPageAlertTitle="ColdBackup [Page Alert]" + +hParam1="$1" +hParam2="$2" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" "" "" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1" "True"` + +hVolumes=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Volumes"` +hArchVolumes=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ArchVolumes"` +hRedoVolumes=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RedoVolumes"` +hCLONEPreparationVolume=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CLONEPreparationVolume"` + +hCreateSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CreateSnapshotCommand"` +hRenameSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RenameSnapshotCommand"` +hDeleteSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DeleteSnapshotCommand"` +hListSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ListSnapshotCommand"` + +hRetryAttempt=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RetryAttempt"` +hRetryDelayInSeconds=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RetryDelayInSeconds"` + +hOracleSID=`echo $ORACLE_SID` + +# write Script Specific Details to logfile + +`WriteLogFile $hScriptLogFile "SQL1: $hSQL1 $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "CreateSnapshotCmd: $hCreateSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "RenameSnapshotCmd: $hRenameSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "DeleteSnapshotCmd: $hDeleteSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ListSnapshotCmd: $hListSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Retry Attempt: $hRetryAttempt $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "RetryDelayInSec: $hRetryDelayInSeconds $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +hVolumes="$hVolumes;$hArchVolumes;$hRedoVolumes;$hCLONEPreparationVolume" +hVolumes=`ReplaceString "$hVolumes" ";" "\n"` + +if [ ! -z "$hParam1" ]; then + hSnapshotName="$hParam1" +else + echo "Please specify snapshot name" + exit 1 +fi + +if [ ! -z "$hParam2" ]; then + hOperation="$hParam2" +else + hOperation="CREATE" +fi + +#run SQLPlus + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") +if [ $? -eq 0 ]; then + + print "Database is RUNNING [$hSQLPlusOutput]" + +fi + +if [ -f "$hSQLPlusOutFile" ]; then + rm "$hSQLPlusOutFile" +fi + + +if [ "$hOperation" = "CREATE" ]; then + if [ -z "`echo "$hSQLPlusOutput"|grep "1034"`" ]; then + print "\nDatabase is RUNNING . . ." + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + #exit 1 + else + print "Database is NOT RUNNING . . ." + fi +fi + + +# take filer action [CREATE/DELETE/LIST] + +echo "$hVolumes"|while read LINE; +do + + hFiler=`echo "$LINE"|cut -d ":" -f1` + hVolume=`echo "$LINE"|cut -d ":" -f2` + + printf "$hOperation snapshot for $hFiler:$hVolume . . ." + hReturn=`TakeSnap "$hFiler" "$hVolume" "$hOperation" "$hSnapshotName` + if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to run filer command" "$hReturn"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + fi + print " COMPLETED [$hReturn] \n" + +done + +`WriteLogFile $hScriptLogFile " ColdBackup Script Completed Successfully $hNewLine" "$hDateFormat"` diff --git a/bin/hDBObjectMonitor.ksh b/bin/hDBObjectMonitor.ksh new file mode 100644 index 0000000..7ec4f60 --- /dev/null +++ b/bin/hDBObjectMonitor.ksh @@ -0,0 +1,87 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 04-Jun-2009 +# Updation Date: +############################################################### + +# define Alert Title +hMailAlertTitle="DB Object Monitor [Mail Alert]" +hPageAlertTitle="DB Object Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` + +#run SQLPlus +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +hMailErrorCount=0 +printf "Owner\tObject Type\tObject Name\tCreated\tLast DDL Time\n" > $hTemporaryFile + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hOwner=`GetColumnValue "$LINE" "1"` + hObjectType=`GetColumnValue "$LINE" "2"` + hObjectName=`GetColumnValue "$LINE" "3"` + hCreated=`GetColumnValue "$LINE" "4"` + hLastDDLTime=`GetColumnValue "$LINE" "5"` + + printf "$hOwner\t$hObjectType\t$hObjectName\t$hCreated\t$hLastDDLTime\n" >> $hTemporaryFile + + hMailErrorCount=`expr $hMailErrorCount + 1` + + fi + +done + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [Object Count=$hMailErrorCount]" "5"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile" +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hDBSessionMonitor.ksh b/bin/hDBSessionMonitor.ksh new file mode 100644 index 0000000..2d7a356 --- /dev/null +++ b/bin/hDBSessionMonitor.ksh @@ -0,0 +1,100 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 09-Sep-2008 +# Updation Date: 09-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="DB Session Monitor [Mail Alert]" +hPageAlertTitle="DB Session Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` +hIdleTimeInSeconds=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "IdleTimeInSeconds"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "IdleTimeInSeconds: $hIdleTimeInSeconds $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +#run SQLPlus +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1 $hIdleTimeInSeconds" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +hMailErrorCount=0 +printf "SID\tSerial#\tProgram\tModule\tAction\tDBUsername\tHostname\tOSUser\tStatus\tLastCallET\n" > $hTemporaryFile + +cat $hSQLPlusOutFile|while read LINE; +do + + `WriteLogFile $hScriptLogFile "Processing $hMailErrorCount=$LINE $hNewLine" "$hDateFormat"` + + if [ ! -z "$LINE" ]; then + + hSID=`GetColumnValue "$LINE" "1"` + hSerialNo=`GetColumnValue "$LINE" "2"` + hProgram=`GetColumnValue "$LINE" "3"` + hModule=`GetColumnValue "$LINE" "4"` + hAction=`GetColumnValue "$LINE" "5"` + hUsername=`GetColumnValue "$LINE" "6"` + hHostname=`GetColumnValue "$LINE" "7"` + hOSUser=`GetColumnValue "$LINE" "8"` + hStatus=`GetColumnValue "$LINE" "9"` + hLastCallET=`GetColumnValue "$LINE" "10"` + + printf "$hSID\t$hSerialNo\t$hProgram\t$hModule\t$hAction\t$hUsername\t$hHostname\t$hOSUser\t$hStatus\t$hLastCallET\n" >> $hTemporaryFile + + hMailErrorCount=`expr $hMailErrorCount + 1` + + fi + +done + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [SessionCount=$hMailErrorCount]" "10"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile" +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hGC.ksh b/bin/hGC.ksh new file mode 100755 index 0000000..e3d9718 --- /dev/null +++ b/bin/hGC.ksh @@ -0,0 +1,48 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 03-May-2012 +# Updation Date: 03-May-2012 +############################################################### + +hFile='gcstat.txt' + +hJavaVendor=`java -version 2>&1 |grep -i jrockit` + +if [ "$hJavaVendor" = "" ]; then + hJavaVendor="ORACLE" +else + hJavaVendor="JROCKIT" +fi + +if [ "$hJavaVendor" = "ORACLE" ]; then + hPID=`adopmnctl.sh status|grep oacore|cut -d "|" -f 3` +else + hPID=`jps|grep Server|cut -d " " -f 1` +fi + + +while true +do + + for i in $hPID + do + + hTimeStamp=`date` + if [ "$hJavaVendor" = "ORACLE" ]; then + hOutput=`jstat -gcutil $i 1s 1|tail -1` + else + hOutput=`jstat -gc $i 1s 1|tail -1` + fi + echo $hOutput + + echo "$hTimeStamp $hOutput" >> "$hFile.$i" + + done + + sleep 60 + +done + +exit 0 diff --git a/bin/hGetCPUCount.ksh b/bin/hGetCPUCount.ksh new file mode 100644 index 0000000..e68605b --- /dev/null +++ b/bin/hGetCPUCount.ksh @@ -0,0 +1,14 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 08-Feb-2010 +# Updation Date: 08-Feb-2010 +############################################################### + +if [ `uname` = 'Linux' ]; then + echo $(cat /proc/cpuinfo|grep "processor"|wc -l) +fi +if [ `uname` = 'SunOS' ]; then + echo $(psrinfo|wc -l) +fi diff --git a/bin/hGetRequestIDInfo.ksh b/bin/hGetRequestIDInfo.ksh new file mode 100644 index 0000000..870675a --- /dev/null +++ b/bin/hGetRequestIDInfo.ksh @@ -0,0 +1,186 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 24-Feb-2009 +# Updation Date: 24-Feb-2009 +############################################################### + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +# Load the default environment before running the script. +hEnvironmentFile=`GetScriptParameter "default" "default" "DefaultSection" "EnvironmentFile" "True"` +. $hEnvironmentFile + +hInstance=`GetInstance` +hHost=`GetHost` + +hHostname=`uname -n` +HOSTNAME=$hHostname +SCRIPT_NAME=`basename $0 .ksh` + +hRequestID=$1 + +# set the environment specified in config.ini, this will ensure ORACLE_HOME, ORACLE_SID, PATH is set properly +hEnvironmentFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "EnvironmentFile" "True"` +. $hEnvironmentFile + +# check if the script is enabled on this instance.host, if not exit +hReturn=`IsScriptEnabled` +if [ $? -eq 1 ]; then + exit 1 +fi + +# Read Configuration Parameter +hNewLine=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "NewLine"` +hMailSubject=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "MailSubject" "True"` + +hFromAlias=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "FromAlias" "True"` +hMailAlias=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "MailAlias"` +hPageAlias=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "PageAlias"` + +hLockFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "LockFile" "True"` +hScriptLogFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "ScriptLogFile" "True"` +hScriptLogFileSize=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "ScriptLogFileSize" "True"` +hHistoryFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "HistoryFile" "True"` + +hTemporaryFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "TemporaryFile" "True"` + +hDateFormat=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "DateFormat"` + +hTimestamp=`GetDate $hDateFormat` + +#hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "SQL1"` +hCryptKey=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "CryptKey"` +hSYSDBA=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "SYSDBA"` +hCredentials=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "Credentials" "True"` +hUserID="" +hSQLPlusExecutable=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "SQLPlusExecutable" "True"` +hSQLPlusOutFile=`GetScriptParameter "$hInstance" "$hHost" "$SCRIPT_NAME" "SQLPlusOutFile" "True"` + + +hSQL1=" +SELECT * +FROM +( +SELECT fcr.request_id||CHR(9)|| + fcp.concurrent_program_name||CHR(9)|| + fcpt.user_concurrent_program_name||CHR(9)|| + TO_CHAR(fcr.actual_start_date,'DD-MON-RRRR HH24:MI')||CHR(9)|| + TO_CHAR(fcr.actual_completion_date,'DD-MON-RRRR HH24:MI')||CHR(9)|| + ROUND(((fcr.actual_completion_date - fcr.actual_start_date)* 24 * 60),2)||CHR(9)|| + ROUND(((fcr.actual_start_date - fcr.requested_start_date)* 24 * 60),2)||CHR(9)|| + fcr.argument_text +FROM apps.fnd_concurrent_requests fcr, + apps.fnd_concurrent_programs fcp, + apps.fnd_concurrent_programs_tl fcpt, + apps.fnd_concurrent_processes fcpro +WHERE fcr.program_application_id = fcp.application_id +AND fcr.concurrent_program_id = fcp.concurrent_program_id +AND fcp.application_id = fcpt.application_id +AND fcp.concurrent_program_id = fcpt.concurrent_program_id +AND fcr.Controlling_Manager = fcpro.Concurrent_Process_ID +AND fcp.concurrent_program_name= + ( + SELECT concurrent_program_name + FROM apps.fnd_concurrent_requests fcr,apps.fnd_concurrent_programs fcp + WHERE fcr.program_application_id = fcp.application_id + AND fcr.concurrent_program_id = fcp.concurrent_program_id + AND fcr.request_id = $hRequestID + ) +ORDER BY + fcr.actual_start_date DESC +) +WHERE ROWNUM < 11 +" + + +# write to logfile about start of the script +#hTmpStr=`Repeat "+-" 40` +#`WriteLogFile $hScriptLogFile "\t\t\t ***=================*** $hNewLine" "$hDateFormat"` +#`WriteLogFile $hScriptLogFile "\t\t\t *** GetRequestIDInfo*** $hNewLine" "$hDateFormat"` +#`WriteLogFile $hScriptLogFile "\t\t\t ***=================*** $hNewLine" "$hDateFormat"` +#`WriteLogFile $hScriptLogFile "$hNewLine" "$hDateFormat"` + +hMailSubject=`eval echo "$hMailSubject"` + +# check if the Script is already running + +hMessage=`CheckLockFile "$hLockFile" "$hScriptLogFile" "$hNewLine" "$hDateFormat"` + +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "FAILED:$hMailSubject" "GetRequestIDInfo [$hTimestamp] [Mail Alert]" "$hMessage"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + exit 1 +fi + +# decrypt the credentials + +hCredentials=`GetSQLCredentials "$hCryptKey" "$hSYSDBA" "$hCredentials"` + +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hCredentials $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "GetRequestIDInfo [$hTimestamp] [Page Alert]" "Unable to decrypt credentials [$hCredentials]"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi + + +#run SQLPlus + +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "GetRequestIDInfo [$hTimestamp] [Page Alert]" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +cat "$hSQLPlusOutFile"|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + #hRequestID=`printf "%s" "$LINE" |awk 'BEGIN {FS="\t"} {print $1}'` + #hConcurrentProgramName=`printf "%s" "$LINE" |awk 'BEGIN {FS="\t"} {print $2}'` + #hUserConcurrentProgramName=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $3}'` + #hActualStartTime=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $4}'` + #hActualCompletionTime=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $5}'` + #hExecutionTime=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $6}'` + #hWaitTime=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $7}'` + #hParameter=`printf "%s" "$LINE"|awk 'BEGIN {FS="\t"} {print $8}'` + + hRequestID=`GetColumnValue "$LINE" "1"` + hConcurrentProgramName=`GetColumnValue "$LINE" "2"` + hUserConcurrentProgramName=`GetColumnValue "$LINE" "3"` + hActualStartTime=`GetColumnValue "$LINE" "4"` + hActualCompletionTime=`GetColumnValue "$LINE" "5"` + hExecutionTime=`GetColumnValue "$LINE" "6"` + hWaitTime=`GetColumnValue "$LINE" "7"` + hParameter=`GetColumnValue "$LINE" "8"` + + fi + + printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "$hRequestID $hConcurrentProgramName $hUserConcurrentProgramName $hActualStartTime $hActualCompletionTime $hExecutionTime $hWaitTime" + +done + + +#`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +#tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +#mv $hTemporaryFile $hScriptLogFile +exit 0 + diff --git a/bin/hHotBackup.ksh b/bin/hHotBackup.ksh new file mode 100644 index 0000000..0301b67 --- /dev/null +++ b/bin/hHotBackup.ksh @@ -0,0 +1,312 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 14-Jan-2009 +# Updation Date: 14-Jan-2009 19-Feb-2009 +# Updation Date: 31-Jul-2009 [added refresh automation steps] +# Updation Date: 05-Aug-2010 [added to remove temporary file in EndBackup section +############################################################### + +# define Alert Title +hMailAlertTitle="HotBackup [Mail Alert]" +hPageAlertTitle="HotBackup [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" "$1" "$2" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hGetCurrentSequenceSQL=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "GetCurrentSequenceSQL"` +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1" "True"` +hSQL2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2" "True"` + +hVolumes=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Volumes"` +hCreateSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CreateSnapshotCommand"` +hRenameSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RenameSnapshotCommand"` +hDeleteSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DeleteSnapshotCommand"` +hListSnapshotCommand=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ListSnapshotCommand"` +hSnapshotKeepDays=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SnapshotKeepDays"` +hNamePattern=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "NamePattern" "True"` +hRetryAttempt=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RetryAttempt"` +hRetryDelayInSeconds=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RetryDelayInSeconds"` +hSuccessFlagFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SuccessFlagFile" "True"` + +hArchVolumes=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ArchVolumes"` +hArchCleanUpScript=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ArchCleanUpScript" "True"` +hArchKeepDays=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ArchKeepDays"` +hCLONEDirectory=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CLONEDirectory" "True"` +hCLONEPreparationScript=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CLONEPreparationScript" "True"` + +hOracleSID=`echo $ORACLE_SID` + +# Remove Success FLAG file +if [ ! -z "$hSuccessFlagFile" ]; then + + if [ -f "$hSuccessFlagFile" ]; then + + rm "$hSuccessFlagFile" + + if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to REMOVE[rm] SuccessFlagFile [$hSuccessFlagFile] $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to remove SuccessFlagFile [$hSuccessFlagFile]" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + else + `WriteLogFile $hScriptLogFile "SuccessFlagFile [$hSuccessFlagFile] REMOVED $hNewLine" "$hDateFormat"` + fi + + fi + +fi + +# write Script Specific Details to logfile + +`WriteLogFile $hScriptLogFile "GetCurrentSeq#SQL: $hGetCurrentSequenceSQL $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "SQL1: $hSQL1 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "SQL2: $hSQL2 $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "CreateSnapshotCmd: $hCreateSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "RenameSnapshotCmd: $hRenameSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "DeleteSnapshotCmd: $hDeleteSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ListSnapshotCmd: $hListSnapshotCommand $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Snapshot Keep Days:$hSnapshotKeepDays $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Name Pattern: $hNamePattern $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Retry Attempt: $hRetryAttempt $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "RetryDelayInSec: $hRetryDelayInSeconds $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "ArchVolumes: $hArchVolumes $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ArchCleanUpScript: $hArchCleanUpScript $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ArchKeepDays: $hArchKeepDays $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "CLONEDirectory: $hCLONEDirectory $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +hTime2=`GetElapsedTime` + +hConfigReadTime=`expr $hTime2` + +# function to end the backup, in case of failure, before exiting, end the backup mode. +EndBackup() +{ + # put the database in normal mode + hOutput=`RunSQLCommand "$hCredentials" "$hSQL2" "$hSQLPlusExecutable" "$hTemporaryFile"` + + if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to end-backup" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" + fi + exit 1 + fi + + if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" + fi + + return 0 +} + +hTime1=`GetElapsedTime` + +# get the current sequence +hOutput=`RunSQLCommand "$hCredentials" "$hGetCurrentSequenceSQL" "$hSQLPlusExecutable" "$hTemporaryFile"` +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to Get Current Sequence" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi +hStartSequence=$hOutput + +# put the database in begin backup mode +hOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to begin-backup" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi + +hTime2=`GetElapsedTime` +hBeginBackupTime=`expr $hTime2 - $hTime1` + +# backup for non-ARCH volumes + +hTime1=`GetElapsedTime` + +#hVolumes=`echo "$hVolumes"|tr ";" "\n"` +hVolumes=`ReplaceString "$hVolumes" ";" "\n"` +echo "$hVolumes"|while read LINE; +do + + hFiler=`echo "$LINE"|cut -d ":" -f1` + hVolume=`echo "$LINE"|cut -d ":" -f2` + + hReturn=`TakeSnap "$hFiler" "$hVolume"` + if [ $? -eq 1 ]; then + + EndBackup + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to run filer command" "$hReturn"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + fi + +done + +hTime2=`GetElapsedTime` +hDataVolumeBackupTime=`expr $hTime2 - $hTime1` + + +# put the database in normal mode + +hTime1=`GetElapsedTime` + +EndBackup + +hTime2=`GetElapsedTime` +hEndBackupTime=`expr $hTime2 - $hTime1` + +# get the current sequence +hOutput=`RunSQLCommand "$hCredentials" "$hGetCurrentSequenceSQL" "$hSQLPlusExecutable" "$hTemporaryFile"` +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to Get Current Sequence" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi +hEndSequence=$hOutput + + +hTime1=`GetElapsedTime` + +#hArchVolumes=`echo "$hArchVolumes"|tr ";" "\n"` +hArchVolumes=`ReplaceString "$hArchVolumes" ";" "\n"` +echo "$hArchVolumes"|while read LINE; +do + + hFiler=`echo "$LINE"|cut -d ":" -f1` + hVolume=`echo "$LINE"|cut -d ":" -f2` + + hReturn=`TakeSnap "$hFiler" "$hVolume"` + if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to run filer command" "$hReturn"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + fi + +done + +hTime2=`GetElapsedTime` +hArchVolumeBackupTime=`expr $hTime2 - $hTime1` + +# ARCH Clean-up +export hNewLine hMailSubject hFromAlias hMailAlias hPageAlias hLockFile hScriptLogFile hRunLogFile hScriptLogFileSize hTemporaryFile hLogDirectory +export hDateFormat hTimestamp hSQL1 hSQL2 hCryptKey hSYSDBA hCredentials hUserID hSQLPlusExecutable +export hVolumes hCreateSnapshotCommand hRenameSnapshotCommand hDeleteSnapshotCommand hListSnapshotCommand +export hSnapshotKeepDays hNamePattern hRetryAttempt hRetryDelayInSeconds hArchVolumes hArchCleanUpScript hArchKeepDays hOracleSID hTmpStr + +hTime1=`GetElapsedTime` + +$hArchCleanUpScript +hArchFileDeletedCount=$? + +hTime2=`GetElapsedTime` +hArchVolumeCleanupTime=`expr $hTime2 - $hTime1` + + +# CLONE Preparation Script Steps + +hTime1=`GetElapsedTime` + +export hStartSequence hEndSequence hCLONEDirectory hInstance hHost H_SCRIPTSECTION H_CONFIG_FILE + +$hCLONEPreparationScript +hCLONEPreparationScriptStatus=$? + +hTime2=`GetElapsedTime` +hCLONEPreparationTime=`expr $hTime2 - $hTime1` + +hEndDate=`GetDate $hDateFormat` +hTotalSeconds=`GetElapsedTime` + +hReturn=`WriteHistoryRecord "$hConfigReadTime\t$hBeginBackupTime\t$hDataVolumeBackupTime\t$hEndBackupTime\t$hArchVolumeBackupTime\t$hArchVolumeCleanupTime\t$hArchFileDeletedCount\t$hTotalSeconds\t$hCLONEPreparationTime"` + +if [ $hCLONEPreparationScriptStatus -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - CLONEPreparationScript Failed" "$hReturn"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile " HotBackup Script Completed with WARNING $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile " HotBackup Script Completed Successfully $hNewLine" "$hDateFormat"` +fi + +# Create Success FLAG file +if [ ! -z "$hSuccessFlagFile" ]; then + + touch "$hSuccessFlagFile" > $hTemporaryFile + + if [ $? -eq 1 ]; then + hOutput=`cat $hTemporayFile` + `WriteLogFile $hScriptLogFile "Unable to CREATE SuccessFlagFile [$hSuccessFlagFile] $hNewLine [$hError] $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle - Unable to CREATE SuccessFlagFile [$hSuccessFlagFile] $hNewLine You can manually create SuccessFlagFile as all backup task successfully completed" "$hOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "SuccessFlagFile [$hSuccessFlagFile] CREATED $hNewLine" "$hDateFormat"` + fi + +fi + +# PREPARE The EMail Body + +echo "" > $hTemporaryFile + +echo "\t\t\t***====================***" >> $hTemporaryFile +echo "\t\t\t*** HotBackup Summary ***" >> $hTemporaryFile +echo "\t\t\t***====================***" >> $hTemporaryFile +echo "=========================================================" >> $hTemporaryFile +echo "Hostname: $H_HOSTNAME" >> $hTemporaryFile +echo "Instance: $hOracleSID" >> $hTemporaryFile +echo "Backup Start Time: $hTimestamp" >> $hTemporaryFile +echo "Backup End Time: $hEndDate" >> $hTemporaryFile +echo "Configuration Read Time: $hConfigReadTime seconds" >> $hTemporaryFile +echo "Begin Backup Time: $hBeginBackupTime seconds" >> $hTemporaryFile +echo "End Backup Time: $hEndBackupTime seconds" >> $hTemporaryFile +echo "Data Volume Backup Time: $hDataVolumeBackupTime seconds" >> $hTemporaryFile +echo "ARCH Volume Backup Time: $hArchVolumeBackupTime seconds" >> $hTemporaryFile +echo "ARCH Volume Cleanup Time:$hArchVolumeCleanupTime seconds" >> $hTemporaryFile +echo "ARCH Files Deleted: $hArchFileDeletedCount file(s)" >> $hTemporaryFile +echo "CLONE Preparation Time: $hCLONEPreparationTime seconds" >> $hTemporaryFile +echo "Total Backup Time: $hTotalSeconds seconds" >> $hTemporaryFile +echo "=========================================================" >> $hTemporaryFile + +cat $hRunLogFile >> $hTemporaryFile + +#cp $hRunLogFile $hTemporaryFile + +`WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` +`SendTextEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "SUCCESS:$hMailSubject" "$hMailAlertTitle - Log"` +`WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hInitialize.ksh b/bin/hInitialize.ksh new file mode 100644 index 0000000..036687e --- /dev/null +++ b/bin/hInitialize.ksh @@ -0,0 +1,100 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 30-Aug-2009 +# Updation Date: 30-Aug-2009 +############################################################### +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +H_CONFIG_FILE="$H_SCRIPT_TOP/../conf/default.config.ini" + +# Load the default environment before running the script. +hEnvironmentFile=`GetScriptParameter "default" "default" "DefaultSection" "EnvironmentFile" "True"` +. $hEnvironmentFile + +hInstance=`GetInstance "$2"` +hHost=`GetHost "$3"` + +H_CONFIG_FILE="$H_SCRIPT_TOP/../conf/default.config.ini $H_SCRIPT_TOP/../conf/$hInstance.config.ini" + +H_HOSTNAME=`uname -n` +H_SCRIPTNAME=`basename $1` +H_SCRIPTSECTION=`basename $1 .ksh` + +# set the environment specified in config.ini, this will ensure ORACLE_HOME, ORACLE_SID, PATH is set properly +hEnvironmentFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "EnvironmentFile" "True"` +. $hEnvironmentFile +hLogDirectory=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "LogDirectory" "True"` +hScriptLogFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ScriptLogFile" "True"` +hForce=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Force"` + +# check if the script is enabled on this instance.host, if not exit +hReturn=`IsScriptEnabled` +if [ $? -eq 1 ]; then + if [ -f "$hScriptLogFile" ]; then + if [ "$hForce" = "True" ]; then + `WriteLogFile $hScriptLogFile "FORCE Running this script $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "Script is DISABLED $hNewLine" "$hDateFormat"` + fi + fi + if [ "$hForce" != "True" ]; then + exit 1 + fi +fi + +# Read Configuration Parameter +hNewLine=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "NewLine"` +hDateFormat=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DateFormat"` +hTimestamp=`GetDate $hDateFormat` + +hMailSubject=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailSubject" "True"` +hMailSubject=`eval echo "$hMailSubject"` +hFromAlias=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "FromAlias" "True"` +hMailAlias=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailAlias"` +hPageAlias=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageAlias"` + +hLockFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "LockFile" "True"` +hScriptLogFileSize=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ScriptLogFileSize" "True"` +hHistoryFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "HistoryFile" "True"` +hTemporaryFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile" "True"` +hRunLogFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "RunLogFile" "True"` + +hMailAlertTitle="$hMailAlertTitle [$hTimestamp]" +hPageAlertTitle="$hPageAlertTitle [$hTimestamp]" + +# write to logfile about start of the script +hTmpStr=`Repeat "+-" 40` +`WriteLogFile $hScriptLogFile "\t\t\t ***==============================*** $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "\t\t\t ***$H_SCRIPTSECTION*** $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "\t\t\t ***==============================*** $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Instance: $hInstance $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Hostname: $H_HOSTNAME $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Hostname2: $hHost $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "EnvironmentFile: $hEnvironmentFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "DateFormat: $hDateFormat $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "FromAlias: $hFromAlias $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "MailAlias: $hMailAlias $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageAlias: $hPageAlias $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "LogFile: $hScriptLogFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "LogFileSize: $hScriptLogFileSize lines $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "RunLogFile: $hRunLogFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "HistoryFile: $hHistoryFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "TemporaryFile: $hTemporaryFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "LockFile: $hLockFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +# check if the Script is already running +hMessage=`CheckLockFile "$hLockFile" "$hScriptLogFile" "$hNewLine" "$hDateFormat"` + +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "$hMessage"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + exit 1 +fi diff --git a/bin/hInitializeSQLPlus.ksh b/bin/hInitializeSQLPlus.ksh new file mode 100644 index 0000000..6ea7fd3 --- /dev/null +++ b/bin/hInitializeSQLPlus.ksh @@ -0,0 +1,28 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 02-Sep-2009 +# Updation Date: 02-Sep-2009 +############################################################### + +hCredentials=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Credentials" "True"` +hSQLPlusExecutable=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQLPlusExecutable" "True"` +hCryptKey=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CryptKey"` +hSYSDBA=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SYSDBA"` +hSQLPlusOutFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQLPlusOutFile" "True"` + +`WriteLogFile $hScriptLogFile "SQLPlusExecutable: $hSQLPlusExecutable $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "SQLPlusOutFile: $hSQLPlusOutFile $hNewLine" "$hDateFormat"` + +# decrypt the credentials + +hCredentials=`GetSQLCredentials "$hCryptKey" "$hSYSDBA" "$hCredentials"` + +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hCredentials $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "Unable to decrypt credentials [$hCredentials]"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi diff --git a/bin/hJVM.ksh b/bin/hJVM.ksh new file mode 100755 index 0000000..2169e89 --- /dev/null +++ b/bin/hJVM.ksh @@ -0,0 +1,91 @@ +#!/bin/bash +# Author: Habib Rangoonwala +# Updated: 12-JUN-2014 +# + +Server=$1 +SleepTime=$2 +# to support AccessGate +MODULE=$3 +hFile='gcstat' +hJavaVendor=`java -version 2>&1 |grep -i jrockit` +hDIR=`dirname $0` + +if [ "$hJavaVendor" = "" ]; then + hJavaVendor="ORACLE" +else + hJavaVendor="JROCKIT" +fi +getProcessID() +{ + #if [ "$hJavaVendor" = "ORACLE" ]; then + # to support AccessGate + if [ "$hJavaVendor" = "ORACLE" -a "$MODULE" = "" ]; then + hPID=`adopmnctl.sh status|grep 'oacore\|c4ws\|oafm' |cut -d "|" -f 3` + else + hPID=`jps|grep Server|cut -d " " -f 1` + fi + #echo $hPID +} + +getProcessID + +checkProcessID() +{ + getProcessID + for i in $hPID + do + if [ ! -f /proc/$i/exe ]; then + getProcessID + fi + done +} + +while true +do + for i in $hPID + do + + TimeStamp=$(date +'%a %d-%b-%Y %T [%Z]') + HOSTNAME=$(hostname) + hDatePostFix=`date "+%m_%d_%Y"` + CpuUsage=`ps -p $i -o pcpu |tail -1` + + if [ "$hJavaVendor" = "ORACLE" -a "$MODULE" = "" ]; then + + ServerName=$(ps hw -f -p $i | sed 's/^.*Doracle\.ons\.indexid=//; s/ .*$//') + hOutput=`jstat -gc $i 1s 1|tail -1` + hClasses=`jstat -class $i 1s 1|tail -1` + hJVMUsage=`jstat -gc $i | tail -1 |gawk '{print ($3+$4+$6+$8)/1024};'|head -1` + hPSMem=`ps -p $i -O rss | tail -1| gawk '{ print $2/1024 };' ` + hVmSize=`cat /proc/$i/status | grep 'VmSize' | gawk '{print ($2)};'` + # added to support accessgate + hThreads=`cat /proc/$i/status | grep 'Threads:' | gawk '{print ($2)};'` + hFreeHostMem=`grep 'MemFree:' /proc/meminfo|gawk '{print ($2)};'` + hFreeHostSwapMem=`grep 'SwapFree:' /proc/meminfo|gawk '{print ($2)};'` + hPMAP=`pmap $i | tail -1 | gawk '{print $2};'` + + echo "$TimeStamp $CpuUsage $hJVMUsage $hPSMem $hVmSize $hThreads $hFreeHostMem $hFreeHostSwapMem $hPMAP $hOutput $hClasses $ServerName.$HOSTNAME" >> "$hDIR/../logs/$Server/his/$hFile.$Server.$hDatePostFix" + else + ServerName=$(ps hw -f -p $i | sed 's/^.*-Dweblogic\.Name=//; s/ .*$//') + hOutput=`jstat -gc $i 1s 1|tail -1` + hClasses=`jstat -class $i 1s 1|tail -1` + hPSMem=`ps -p $i -O rss | tail -1| gawk '{ print $2/1024 };' ` + hJVMUsage=`jstat -gc $i | tail -1 |gawk '{print ($3+$4+$6+$8)/1024};'|head -1` + hVmSize=`cat /proc/$i/status | grep 'VmSize' | gawk '{print ($2)};'` + # added to support accessgate + hThreads=`cat /proc/$i/status | grep 'Threads:' | gawk '{print ($2)};'` + hFreeHostMem=`grep 'MemFree:' /proc/meminfo|gawk '{print ($2)};'` + hFreeHostSwapMem=`grep 'SwapFree:' /proc/meminfo|gawk '{print ($2)};'` + hPMAP=`pmap $i | tail -1 | gawk '{print $2};'` + + echo "$TimeStamp $CpuUsage $hJVMUsage $hPSMem $hVmSize $hThreads $hFreeHostMem $hFreeHostSwapMem $hPMAP $hOutput $hClasses $ServerName" >> "$hDIR/../logs/$Server/his/$hFile.$Server.$hDatePostFix" + fi + done + + sleep $SleepTime + + checkProcessID + +done +exit 0 diff --git a/bin/hLockMonitor.ksh b/bin/hLockMonitor.ksh new file mode 100644 index 0000000..7c2da0b --- /dev/null +++ b/bin/hLockMonitor.ksh @@ -0,0 +1,109 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 29-Aug-2007 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Lock Monitor [Mail Alert]" +hPageAlertTitle="Lock Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +#hUserID="" +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` + +#run SQLPlus + +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +# truncate temporary file + +echo "Blocking SID\tSerial #\tUsername\tHostname\tProgram\tModule\tAction\tStatus\tLastCallET\tBlocked SID\tSerial #\tUsername\tHostname\tProgram\tModule\tAction\tStatus\tLastCallET" > $hTemporaryFile + +hPageErrorCount=0 +hMailErrorCount=0 + +#echo "$hSQLPlusOutput"|while read LINE; +cat "$hSQLPlusOutFile"|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hBlockingSID=`GetColumnValue "$LINE" "1"` + hBlockingSerialNo=`GetColumnValue "$LINE" "2"` + hBlockingUsername=`GetColumnValue "$LINE" "3"` + hBlockingHostname=`GetColumnValue "$LINE" "4"` + hBlockingProgram=`GetColumnValue "$LINE" "5"` + hBlockingModule=`GetColumnValue "$LINE" "6"` + hBlockingAction=`GetColumnValue "$LINE" "7"` + hBlockingStatus=`GetColumnValue "$LINE" "8"` + hBlockingLastCallET=`GetColumnValue "$LINE" "9"` + hBlockingSQL=`GetColumnValue "$LINE" "10"` + hBlockedSID=`GetColumnValue "$LINE" "11"` + hBlockedSerialNo=`GetColumnValue "$LINE" "12"` + hBlockedUsername=`GetColumnValue "$LINE" "13"` + hBlockedHostname=`GetColumnValue "$LINE" "14"` + hBlockedProgram=`GetColumnValue "$LINE" "15"` + hBlockedModule=`GetColumnValue "$LINE" "16"` + hBlockedAction=`GetColumnValue "$LINE" "17"` + hBlockedStatus=`GetColumnValue "$LINE" "18"` + hBlockedLastCallET=`GetColumnValue "$LINE" "19"` + hBlockedSQL=`GetColumnValue "$LINE" "20"` + + echo "$hBlockingSID\t$hBlockingSerialNo\t$hBlockingUsername\t$hBlockingHostname\t$hBlockingProgram\t$hBlockingModule\t$hBlockingAction\t$hBlockingStatus\t$hBlockingLastCallET\t$hBlockedSID\t$hBlockedSerialNo\t$hBlockedUsername\t$hBlockedHostname\t$hBlockedProgram\t$hBlockedModule\t$hBlockedAction\t$hBlockedStatus\t$hBlockedLastCallET" >> $hTemporaryFile + echo "SQL<TD colspan=8><TEXT>$hBlockingSQL</TD>\tSQL<TD colspan=8><TEXT>$hBlockedSQL</TD>\t___SKIPLINE___" >> $hTemporaryFile + hMailErrorCount=`expr $hMailErrorCount + 1` + + fi + +done + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "18"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile" +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +if [ -f "$hSQLPlusOutFile" ]; then + rm $hSQLPlusOutFile +fi + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hMonitor.ksh b/bin/hMonitor.ksh new file mode 100644 index 0000000..d835de6 --- /dev/null +++ b/bin/hMonitor.ksh @@ -0,0 +1,49 @@ +#!/bin/ksh +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-May-2007 +# Updation Date: 02-Aug-2007 +############################################################### + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +hHour=`date +"%H"` +if [ "$hHour" = "00" -o "$hHour" = "04" -o "$hHour" = "08" -o "$hHour" = "12" -o "$hHour" = "16" -o "$hHour" = "20" ]; then + $hDirName/hZombieMonitor.ksh + wait +fi + +$hDirName/hOSMonitor.ksh +wait +$hDirName/hRunawayMonitor.ksh & +wait + +# DB Specific Scripts +$hDirName/hAlertLogMonitor.ksh & +wait +$hDirName/hTSMonitor.ksh & +wait +$hDirName/hDBSessionMonitor.ksh & +wait +$hDirName/hLockMonitor.ksh & +wait +$hDirName/hTempTSMonitor.ksh & +wait +$hDirName/hUNDOTSMonitor.ksh & +wait + +# CM Tier Specific Scripts +$hDirName/hCMQueueMonitor.ksh & +wait +$hDirName/hSFMQueueMonitor.ksh & +wait +$hDirName/hWFQueueMonitor.ksh & +wait +$hDirName/hWFInBoundMailMonitor.ksh & +wait + +# URL Monitoring +$hDirName/hURLMonitor.ksh & +wait diff --git a/bin/hOSMonitor.ksh b/bin/hOSMonitor.ksh new file mode 100644 index 0000000..01e9854 --- /dev/null +++ b/bin/hOSMonitor.ksh @@ -0,0 +1,187 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-May-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="OS Monitor [Mail Alert]" +hPageAlertTitle="OS Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# Read Script Specific Configuration Parameter +hCPUMailLimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CPUMailLimit" "True"` +hCPUPageLimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CPUPageLimit" "True"` + +hLoadMailLimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "LoadMailLimit" "True"` +hLoadPageLimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "LoadPageLimit" "True"` + +hShowTopProcesses=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ShowTopProcesses"` + +hConfigReadTime=`GetElapsedTime` + +# write Script Specific Details to logfile + +`WriteLogFile $hScriptLogFile "CPUMailLimit: $hCPUMailLimit $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "CPUPageLimit: $hCPUPageLimit $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "LoadMailLimit: $hLoadMailLimit $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "LoadPageLimit: $hLoadPageLimit $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ShowTopProcesses: $hShowTopProcesses $hNewLine" "$hDateFormat"` + +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +if [ `uname` = 'SunOS' ]; then + hOutput=`iostat -c 1 20 |awk '{print $4}'|grep -v id` +elif [ `uname` = 'Linux' ]; then + hOutput=`iostat -c 1 20 |grep -v "avg-cpu:"|awk '{print $6}'|awk -F. '{print $1}'|grep -v id` +fi + +hCPUTotal=0 +hCount=0 + +for hLoad in $hOutput +do + if [ ! -z "$hLoad" ]; then + hCPUTotal=`expr $hCPUTotal + $hLoad` + hCount=`expr $hCount + 1` + fi +done + +hCPUBusy=`expr 100 - $hCPUTotal / $hCount ` + +if [ "$hShowTopProcesses" -gt 0 ]; then + + hShowTopProcesses1=`expr $hShowTopProcesses + 1` + if [ `uname` = 'SunOS' ]; then + hOutput=`top -n $hShowTopProcesses|tail -$hShowTopProcesses1` + elif [ `uname` = 'Linux' ]; then + hOutput=`top -b -n 1|tail -$hShowTopProcesses1` + fi + + echo "PID\tUsername\tTime\tCPU\tCommand" > "$hTemporaryFile" + + echo "$hOutput"|while read LINE; + do + + if [ ! -z "$LINE" ]; then + + if [ `uname` = 'SunOS' ]; then + hPID=`echo $LINE|cut -d " " -f1` + hUsername=`echo $LINE|cut -d " " -f2` + hTime=`echo $LINE|cut -d " " -f9` + hCPU=`echo $LINE|cut -d " " -f10` + hCommand=`echo $LINE|cut -d " " -f11` + elif [ `uname` = 'Linux' ]; then + hPID=`echo $LINE|cut -d " " -f1` + hUsername=`echo $LINE|cut -d " " -f2` + hTime=`echo $LINE|cut -d " " -f11` + hCPU=`echo $LINE|cut -d " " -f9` + hCommand=`echo $LINE|cut -d " " -f12` + fi + + #hPID=`GetColumnValue "$LINE" "1"` + #hUsername=`GetColumnValue "$LINE" "2"` + #hTime=`GetColumnValue "$LINE" "9"` + #hCPU=`GetColumnValue "$LINE" "10"` + #hCommand=`GetColumnValue "$LINE" "11"` + + + echo "$hPID\t$hUsername\t$hTime\t$hCPU\t$hCommand" >> "$hTemporaryFile" + + fi + + done + + # copy it to .2, because SendMultilineEmail deletes the temp files + # this .2 is used in LoadAvg alert + cp "$hTemporaryFile" "$hTemporaryFile.2" + +fi + + +if [ "$hCPUBusy" -ge "$hCPUPageLimit" ]; then + + hMessage="CPU is [$hCPUBusy%] Busy. Crossed Page Limit [$hCPUPageLimit%]" + + `WriteLogFile $hScriptLogFile "$hMessage" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + if [ "$hShowTopProcesses" -gt 0 ]; then + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject:CPU=$hCPUBusy%" "$hPageAlertTitle <br> [$hMessage]" "5"` + else + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject:CPU=$hCPUBusy%" "$hPageAlertTitle" "$hMessage"` + fi + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + +elif [ "$hCPUBusy" -ge "$hCPUMailLimit" ]; then + + hMessage="CPU is [$hCPUBusy%] Busy. Crossed Mail Limit [$hCPUMailLimit%]" + + `WriteLogFile $hScriptLogFile "$hMessage" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + if [ "$hShowTopProcesses" -gt 0 ]; then + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject:CPU=$hCPUBusy%" "$hMailAlertTitle <br> [$hMessage]" "5"` + else + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject:CPU=$hCPUBusy%" "$hMailAlertTitle" "$hMessage"` + fi + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + +fi + +# uptime | sed -e 's/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/' -e 's/ //g' +if [ `uname` = 'SunOS' ]; then + hLoadAvg=`uptime|awk -F: '{print $4}'|awk -F, '{print $1}'` +elif [ `uname` = 'Linux' ]; then + hLoadAvg=`uptime|awk -F: '{print $5}'|awk -F, '{print $1}'` +fi + +if [ "$hLoadAvg" -ge "$hLoadPageLimit" ]; then + + hMessage="Load Average [$hLoadAvg] has crossed allowed Load Average Page Limit of [$hLoadPageLimit]" + + `WriteLogFile $hScriptLogFile "$hMessage" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + if [ "$hShowTopProcesses" -gt 0 ]; then + `SendMultiLineEmail "$hTemporaryFile.2" "$hFromAlias" "$hPageAlias" "$hMailSubject:LoadAvg=$hLoadAvg" "$hPageAlertTitle <br> [$hMessage]" "5"` + else + `SendSingleLineEmail "$hTemporaryFile.2" "$hFromAlias" "$hPageAlias" "$hMailSubject:LoadAvg=$hLoadAvg" "$hPageAlertTitle" "$hMessage"` + fi + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + +elif [ "$hLoadAvg" -ge "$hLoadMailLimit" ]; then + + hMessage="Load Average [$hLoadAvg] has crossed allowed Load Average Mail Limit of [$hLoadMailLimit]" + + `WriteLogFile $hScriptLogFile "$hMessage" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + if [ "$hShowTopProcesses" -gt 0 ]; then + `SendMultiLineEmail "$hTemporaryFile.2" "$hFromAlias" "$hMailAlias" "$hMailSubject:LoadAvg=$hLoadAvg" "$hMailAlertTitle <br> [$hMessage]" "5"` + else + `SendSingleLineEmail "$hTemporaryFile.2" "$hFromAlias" "$hMailAlias" "$hMailSubject:LoadAvg=$hLoadAvg" "$hMailAlertTitle" "$hMessage"` + fi + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + +fi + +if [ -f "$hTemporaryFile.2" ]; then + rm "$hTemporaryFile.2" +fi + +# write history record +hTotalSeconds=`GetElapsedTime` +hReturn=`WriteHistoryRecord "$hCPUBusy\t$hLoadAvg\t$hConfigReadTime\t$hTotalSeconds"` + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hPreStop.sh b/bin/hPreStop.sh new file mode 100755 index 0000000..ae6b24f --- /dev/null +++ b/bin/hPreStop.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# Referenced Note 455154.1, modified it to my requirements +# Author: Habib Rangoonwala +# Updated: 14-MAY-2014 + +echo +echo ----------------------------------------------- +echo ----------- PRE-STOP EVENT SCRIPT ------------- +echo ----------------------------------------------- +echo + +echo "$*" + +. ~/.profile + +timeStamp="N/A" +instanceName="N/A" +componentId="N/A" +processType="N/A" +processSet="N/A" +processIndex="N/A" +stderrPath="N/A" # not available w/pre-start unless part of restart +stdoutPath="N/A" # not available w/pre-start unless part of restart +reason="N/A" +pid="N/A" # only available with pre-stop, post-crash +startTime="N/A" # only available with pre-stop, post-crash + +while [ $# -gt 0 ]; do + case $1 in + -timeStamp) timeStamp=$2; shift;; + -instanceName) instanceName=$2; shift;; + -componentId) componentId=$2; shift;; + -processType) processType=$2; shift;; + -processSet) processSet=$2; shift;; + -processIndex) processIndex=$2; shift;; + -stderr) stderrPath=$2; shift;; + -stdout) stdoutPath=$2; shift;; + -reason) reason=$2; shift;; + -pid) pid=$2; shift;; + -startTime) startTime=$2; shift;; + *) echo "Option Not Recognized: [$1]"; shift;; + esac + shift +done + +echo timeStamp=$timeStamp +echo instanceName=$instanceName +echo componentId=$componentId +echo processType=$processType +echo processSet=$processSet +echo processIndex=$processIndex +echo stderr=$stderrPath +echo stdout=$stdoutPath +echo reason=$reason +echo pid=$pid +echo startTime=$startTime + +if [ "$reason" == "http_request" ]; then + echo "Exiting as its user initiated request" + kill -3 $pid + +else + hFilePrefix="$CONTEXT_NAME.`date +%Y.%m.%d.%H.%M.%S`.PID-$pid" + hThreadDumpLoc="$APPLCSF/threaddump/" + hFilename="${hThreadDumpLoc}${hFilePrefix}" + + + echo "`date` - Running KILL -3" + kill -3 $pid &> ${hFilename}_threaddump.log + echo "`date` - Running JMAP..." + jmap -dump:format=b,file=${hFilename}_heapdump.hprof $pid + echo "`date` - Running TOP..." + top -b -n 1 > ${hFilename}_top.log + echo "`date` - Running PMAP.." + pmap -x $pid &> ${hFilename}_pmap.log + echo "`date` - Running PSTACK..." + pstack $pid &> ${hFilename}_pstack.log + echo "`date` - Running LSOF..." + lsof -p $pid &> ${hFilename}_lsof.log + echo "`date` - Running JSTACK..." + jstack $pid > ${hFilename}_jstack.log + + echo "`date` - Sending email..." + mailx -s "$CONTEXT_NAME OACORE Pre-Stop ${hFilename}" no-reply@example.com < /dev/null + +fi +echo "`date` - PRE-STOP Script Completed ... exiting." +kill -3 $pid diff --git a/bin/hProcessMemory.ksh b/bin/hProcessMemory.ksh new file mode 100755 index 0000000..3ec8039 --- /dev/null +++ b/bin/hProcessMemory.ksh @@ -0,0 +1,26 @@ +#!/bin/bash +# Author: Habib Rangoonwala +# Updated: 14-SEP-2012 +# Provides information about one Java PID, RSS [Resident Set Size], Heap Utilization, memory using pmap. + + + +printf "TimeStamp \t\t\t\t Process Mem \t\t JVMUsage \t\t hPMAP \n" + +while true +do + + hTimeStamp=`date` + hPSMem=`ps -p $1 -O rss | tail -1| gawk '{ print $2/1024 };' ` + hJVMUsage=`jstat -gc $1 | tail -1 |gawk '{print ($3+$4+$6+$8)/1024};'|head -1` + hPMAP=`pmap $1 | tail -1 | gawk '{print $2};'` + + printf "$hTimeStamp \t\t\t $hPSMem \t\t $hJVMUsage \t\t $hPMAP \n" + + sleep 1 + +done +exit 0 + +#ps -C $1 -O rss | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =",count; print "Memory usage per process =",sum/1024/count, "MB"; print "Total memory usage =", sum/1024, "MB" ;};' + diff --git a/bin/hProfileOptionMonitor.ksh b/bin/hProfileOptionMonitor.ksh new file mode 100644 index 0000000..6ed7225 --- /dev/null +++ b/bin/hProfileOptionMonitor.ksh @@ -0,0 +1,129 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 20-Jul-2010 +# Updation Date: +############################################################### + +# define Alert Title +hMailAlertTitle="Profile Option Monitor [Mail Alert]" +hPageAlertTitle="Profile Option Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1" "True"` +hSendEMail=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SendEMail"` +hDataFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DataFile" "True"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "DataFile: $hDataFile $hNewLine" "$hDateFormat"` + +#run SQLPlus +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +hMailErrorCount=0 + +while true +do + + if [ ! -f "$hDataFile.lock" ]; then + touch "$hDataFile.lock" + `WriteLogFile $hScriptLogFile "Acquired WRITE LOCK on $hDataFile $hNewLine" "$hDateFormat"` + break + else + `WriteLogFile $hScriptLogFile "Waiting for the WRITE LOCK on $hDataFile $hNewLine" "$hDateFormat"` + sleep 1 + fi + +done + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hInstance=`GetColumnValue "$LINE" "1"` + hProfileOptionName=`GetColumnValue "$LINE" "2"` + hLevel=`GetColumnValue "$LINE" "3"` + hLevelValue=`GetColumnValue "$LINE" "4"` + hProfileOptionValue=`GetColumnValue "$LINE" "5"` + hUpdateDate=`GetColumnValue "$LINE" "6"` + hUpdatedBy=`GetColumnValue "$LINE" "7"` + + #if [ ! -f "$hDataFile" ]; then + if [ $hMailErrorCount -eq 0 ]; then + printf "___TABLE___\t7\t$hInstance\n" >> $hDataFile + printf "Instance\tProfileOptionName\tLevel\tLevel Value\tProfileOptionValue\tUpdated\tUpdatedBy\n" >> $hDataFile + fi + + #if [ $hMailErrorCount -eq 0 ]; then + # printf "Instance:<TD colspan=6>$hInstance</TD>\t___SKIPLINE___\n" >> $hDataFile + #fi + printf "$hInstance\t$hProfileOptionName\t$hLevel\t$hLevelValue\t$hProfileOptionValue\t$hUpdateDate\t$hUpdatedBy\n" >> $hDataFile + + hMailErrorCount=`expr $hMailErrorCount + 1` + + fi + +done + +chmod -f 777 "$hDataFile" +cp "$hDataFile" "$hTemporaryFile" + +rm "$hDataFile.lock" + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hSendEMail" = "True" ]; then + + if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [Count=$hMailErrorCount]" "7"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile" + fi + + if [ -f "$hDataFile" ]; then + rm "$hDataFile" + fi + +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hResponsibilityMonitor.ksh b/bin/hResponsibilityMonitor.ksh new file mode 100644 index 0000000..bd59e49 --- /dev/null +++ b/bin/hResponsibilityMonitor.ksh @@ -0,0 +1,184 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-Jul-2010 +# Updation Date: +############################################################### + +# define Alert Title +hMailAlertTitle="Responsibility Monitor [Mail Alert]" +hPageAlertTitle="Responsibility Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1" "True"` +hSendEMail=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SendEMail"` +hDataFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DataFile" "True"` +hExceptionFile=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ExceptionFile" "True"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "DataFile: $hDataFile $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ExceptionFile: $hExceptionFile $hNewLine" "$hDateFormat"` + +# Check if the exception file exists +if [ ! -f "$hExceptionFile" ]; then + `WriteLogFile $hScriptLogFile "ExceptionFile: $hExceptionFile does not exist $hNewLine" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hExceptionFile does not exist"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 + +fi + + +hResponsibilityList="''" +cat "$hExceptionFile"|while read LINE; +do + + hResponsibility=`GetColumnValue "$LINE" "1" ":"` + hUserList=`GetColumnValue "$LINE" "2" ":"` + + hResponsibilityList=`echo $hResponsibilityList,"'"$hResponsibility"'"` + +done + +# generate a SQL File with all the responsibilities which needs to be queries +sed -e "s/\&1/$hResponsibilityList/" "$hSQL1" > "$hTemporaryFile.sql" +hSQL1="$hTemporaryFile.sql" + +#run SQLPlus +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + # remove the temporary sql created + if [ -f "$hSQL1" ]; then + rm "$hSQL1" + fi + + if [ -f "$hSQLPlusOutFile" ]; then + rm -f "$hSQLPlusOutFile" + fi + exit 1 + +fi + +# remove the temporary sql created +if [ -f "$hSQL1" ]; then + rm "$hSQL1" +fi + +hMailErrorCount=0 + +while true +do + + if [ ! -f "$hDataFile.lock" ]; then + touch "$hDataFile.lock" + `WriteLogFile $hScriptLogFile "Acquired WRITE LOCK on $hDataFile $hNewLine" "$hDateFormat"` + break + else + `WriteLogFile $hScriptLogFile "Waiting for the WRITE LOCK on $hDataFile $hNewLine" "$hDateFormat"` + sleep 1 + fi + +done + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hInstance=`GetColumnValue "$LINE" "1"` + hResponsibilityName=`GetColumnValue "$LINE" "2"` + hUsername=`GetColumnValue "$LINE" "3"` + hStartDate=`GetColumnValue "$LINE" "4"` + hEndDate=`GetColumnValue "$LINE" "5"` + + #if [ ! -f "$hDataFile" ]; then + if [ $hMailErrorCount -eq 0 ]; then + printf "___TABLE___\t6\t$hInstance\n" >> $hDataFile + printf "Instance\tResponsibilityName\tUsername\tStart Date\tEnd Date\tStatus\n" >> $hDataFile + fi + + #if [ $hMailErrorCount -eq 0 ]; then + # printf "Instance:<TD colspan=4>$hInstance</TD>\t___SKIPLINE___\n" >> $hDataFile + #fi + hOutput=`grep "$hResponsibilityName": "$hExceptionFile"|grep "$hUsername"` + if [ ! -z "$hOutput" ]; then + hStatus='Allowed' + else + + hOutput=`grep "ALL:" "$hExceptionFile"|grep "$hUsername"` + if [ ! -z "$hOutput" ]; then + hStatus='Allowed' + else + hStatus='Not Allowed' + printf "$hInstance\t$hResponsibilityName\t$hUsername\t$hStartDate\t$hEndDate\t$hStatus\n" >> $hDataFile + fi + fi + hMailErrorCount=`expr $hMailErrorCount + 1` + + fi + +done + +if [ -f "$hDataFile" ]; then + chmod -f 777 "$hDataFile" + cp "$hDataFile" "$hTemporaryFile" +fi + +rm "$hDataFile.lock" + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hSendEMail" = "True" ]; then + + if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [Count=$hMailErrorCount]" "6"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" + fi + fi + + if [ -f "$hDataFile" ]; then + rm "$hDataFile" + fi + +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hRunawayMonitor.ksh b/bin/hRunawayMonitor.ksh new file mode 100644 index 0000000..1ff9319 --- /dev/null +++ b/bin/hRunawayMonitor.ksh @@ -0,0 +1,231 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 01-Sep-2008 +# Updation Date: 01-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Runaway Monitor [Mail Alert]" +hPageAlertTitle="Runaway Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +#hUserID="" +hTemporaryFile1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile1" "True"` +hTemporaryFile2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile2" "True"` + +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` +hSQL2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2"` + +hCPULimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "CPULimit"` +hCommand1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Command1"` +hDBSessionIdleLimit=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DBSessionIdleLimit"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "TemporaryFile1: $hTemporaryFile1 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "TemporaryFile2: $hTemporaryFile2 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "CPULimit: $hCPULimit $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "DBSessionIdleLimit:$hDBSessionIdleLimit sec $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Command1: $hCommand1 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +# run PS command to get the output + +echo "$hCommand1" > $hTemporaryFile2 +chmod 755 $hTemporaryFile2 +hOutput=`sh $hTemporaryFile2` +hMailErrorCount=0 +hPID=0 + +hHeaderPrinted=0 +hDBSessionFound=0 + +# truncate temporary file + +echo "OS-PID\tCPU\tOSUser\tCommand\tSID\tSerial#\tProgram\tModule\tAction\tUsername\tHostname\tStatus\tLastCallET" > $hTemporaryFile2 +hCPULimit=`echo "$hCPULimit * 100"|bc` + +echo "$hOutput"|while read LINE; +do + + if [ -z "$LINE" ]; then + break; + fi + + hHeaderPrinted=0 + hDBSessionFound=0 + hLastCallET=0 + + hCPU=`echo $LINE|awk '{print $2}` + hCPU=`echo "$hCPU * 100"|bc` + + if [ "$hCPU" -ge "$hCPULimit" ]; then + + `WriteLogFile $hScriptLogFile "Verifying Process $LINE $hNewLine" "$hDateFormat"` + + hPID=`GetColumnValue "$LINE" "1"` + hCPU=`GetColumnValue "$LINE" "2"` + hUser=`GetColumnValue "$LINE" "3"` + hComm=`GetColumnValue "$LINE" "4"` + + #run SQLPlus [without V$process] + + hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1 '$hPID'" "$hSQLPlusExecutable" "$hTemporaryFile1"` + + if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + + fi + + #echo "$hSQLPlusOutput"|while read LINE2; + cat "$hSQLPlusOutFile"|while read LINE2; + do + + if [ ! -z "$LINE2" ]; then + + hDBSessionFound=1 + + hSID=`GetColumnValue "$LINE2" "1"` + hSerialNo=`GetColumnValue "$LINE2" "2"` + hProgram=`GetColumnValue "$LINE2" "3"` + hModule=`GetColumnValue "$LINE2" "4"` + hAction=`GetColumnValue "$LINE2" "5"` + hUsername=`GetColumnValue "$LINE2" "6"` + hHostname=`GetColumnValue "$LINE2" "7"` + hStatus=`GetColumnValue "$LINE2" "8"` + hLastCallET=`GetColumnValue "$LINE2" "9"` + + + if [ "$hLastCallET" -ge "$hDBSessionIdleLimit" ]; then + + if [ $hHeaderPrinted -eq 0 ]; then + echo "$hPID\t$hCPU\t$hUser\t$hComm\t-\t-\t-\t-\t-\t-\t-\t-\t-" >> $hTemporaryFile2 + hHeaderPrinted=1 + fi + + echo "-\t-\t-\t-\t$hSID\t$hSerialNo\t$hProgram\t$hModule\t$hAction\t$hUsername\t$hHostname\t$hStatus\t$hLastCallET" >> $hTemporaryFile2 + + else + + `WriteLogFile $hScriptLogFile "Skipping SID=$hSID CurrentLastCallET=$hLastCallET $hNewLine" "$hDateFormat"` + + fi + + fi + + done + + #run SQLPlus 2 [with v$process] + + hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL2 '$hPID'" "$hSQLPlusExecutable" "$hTemporaryFile1"` + + if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + + fi + + #echo "$hSQLPlusOutput"|while read LINE2; + cat "$hSQLPlusOutFile"|while read LINE2; + do + + if [ ! -z "$LINE2" ]; then + + hDBSessionFound=1 + + hSID=`GetColumnValue "$LINE2" "1"` + hSerialNo=`GetColumnValue "$LINE2" "2"` + hProgram=`GetColumnValue "$LINE2" "3"` + hModule=`GetColumnValue "$LINE2" "4"` + hAction=`GetColumnValue "$LINE2" "5"` + hUsername=`GetColumnValue "$LINE2" "6"` + hHostname=`GetColumnValue "$LINE2" "7"` + hStatus=`GetColumnValue "$LINE2" "8"` + hLastCallET=`GetColumnValue "$LINE2" "9"` + + if [ "$hLastCallET" -ge "$hDBSessionIdleLimit" ]; then + + if [ $hHeaderPrinted -eq 0 ]; then + echo "$hPID\t$hCPU\t$hUser\t$hComm\t-\t-\t-\t-\t-\t-\t-\t-\t-" >> $hTemporaryFile2 + hHeaderPrinted=1 + fi + + echo "-\t-\t-\t-\t$hSID\t$hSerialNo\t$hProgram\t$hModule\t$hAction\t$hUsername\t$hHostname\t$hStatus\t$hLastCallET" >> $hTemporaryFile2 + + else + + `WriteLogFile $hScriptLogFile "Skipping SID=$hSID CurrentLastCallET=$hLastCallET $hNewLine" "$hDateFormat"` + + fi + + fi + + done + + if [ $hDBSessionFound -eq 0 -a $hHeaderPrinted -eq 0 ]; then + echo "$hPID\t$hCPU\t$hUser\t$hComm\t-\t-\t-\t-\t-\t-\t-\t-\t-" >> $hTemporaryFile2 + hHeaderPrinted=1 + fi + + if [ $hHeaderPrinted -eq 1 ]; then + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + else + + `WriteLogFile $hScriptLogFile "Skipped Process $LINE $hNewLine" "$hDateFormat"` + + fi + +done + +if [ -f "$hSQLPlusOutFile" ]; then + rm "$hSQLPlusOutFile" +fi + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile2" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [ProcessCount=$hMailErrorCount]" "13"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile2" +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile1 +mv $hTemporaryFile1 $hScriptLogFile +exit 0 diff --git a/bin/hSFMQueueMonitor.ksh b/bin/hSFMQueueMonitor.ksh new file mode 100644 index 0000000..4aaee8e --- /dev/null +++ b/bin/hSFMQueueMonitor.ksh @@ -0,0 +1,131 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 09-Sep-2008 +# Updation Date: 09-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="SFM Queue Monitor [Mail Alert]" +hPageAlertTitle="SFM Queue Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hSQL1=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1") + +hSFMQueueMailLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SFMQueueMailLimit") +hSFMQueuePageLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SFMQueuePageLimit") + +hConfigReadTime=$(GetElapsedTime) + +# write Script Specific Details to logfile +$(WriteLogFile $hScriptLogFile "SFMQueueMailLimit: $hSFMQueueMailLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "SFMQueuePageLimit: $hSFMQueuePageLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat") + +#run SQLPlus + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + $(WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +hMailErrorCount=0 +hPageErrorCount=0 + +printf "Status\tCount\tLast Message TimeStamp\tLimit\n" > $hTemporaryFile + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hMessageStatus=$(GetColumnValue "$LINE" "1") + hMessageCount=$(GetColumnValue "$LINE" "2") + hLastMessageTimeStamp=$(GetColumnValue "$LINE" "3") + hLimit="" + + if [ "$hMessageStatus" = "READY" ]; then + if [ "$hMessageCount" -gt "$hSFMQueuePageLimit" ]; then + + hPageErrorCount=$hMessageCount + hLimit="$hSFMQueuePageLimit page limit" + + else + if [ "$hMessageCount" -gt "$hSFMQueueMailLimit" ]; then + + hMailErrorCount=$hMessageCount + hLimit="$hSFMQueueMailLimit mail limit" + + fi + fi + fi + + printf "$hMessageStatus\t$hMessageCount\t$hLastMessageTimeStamp\t$hLimit\n" >> $hTemporaryFile + + # write history record + hReturn=$(WriteHistoryRecord "$hConfigReadTime\t$hMessageStatus\t$hMessageCount\t$hSFMQueueMailLimit\t$hSFMQueuePageLimit") + + fi + +done + +if [ "$hPageErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject [SFM Queue Critical COUNT=$hPageErrorCount]" "$hPageAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") +else + $(WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat") + + if [ "$hMailErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject [SFM Queue Warning COUNT=$hMailErrorCount]" "$hMailAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat") + else + $(WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat") + fi + +fi + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +$(WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat") + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 + diff --git a/bin/hTSMonitor.ksh b/bin/hTSMonitor.ksh new file mode 100644 index 0000000..0feb2f3 --- /dev/null +++ b/bin/hTSMonitor.ksh @@ -0,0 +1,132 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 27-May-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Tablespace Monitor [Mail Alert]" +hPageAlertTitle="Tablespace Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hTemporaryFileMail=$hTemporaryFile.mail +hTemporaryFilePage=$hTemporaryFile.page + +hMailCondition=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailCondition"` +hPageCondition=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageCondition"` +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "MailCondition: $hMailCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageCondition: $hPageCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +#run SQLPlus + +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +# find out mail/page percentage +hMailPCT=`echo "$hMailCondition"|cut -d, -f1` +hMailMB=`echo "$hMailCondition"|cut -d, -f2` + +hPagePCT=`echo "$hPageCondition"|cut -d, -f1` +hPageMB=`echo "$hPageCondition"|cut -d, -f2` + +# truncate temporary files + +echo "Tablespace Name\tTotal Size [MB]\tUsed Space [MB]\tFree Space [MB]\tFree [%]" > $hTemporaryFileMail +echo "Tablespace Name\tTotal Size [MB]\tUsed Space [MB]\tFree Space [MB]\tFree [%]" > $hTemporaryFilePage + +hPageErrorCount=0 +hMailErrorCount=0 + +#echo "$hSQLPlusOutput"|while read LINE; +cat "$hSQLPlusOutFile"|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hTSName=`GetColumnValue "$LINE" "1"` + hTotalMB=`GetColumnValue "$LINE" "2"` + hUsedMB=`GetColumnValue "$LINE" "3"` + hFreeMB=`GetColumnValue "$LINE" "4"` + hFreePCT=`GetColumnValue "$LINE" "5"` + + hFreePCT=`expr 100 - $hFreePCT` + + # check for mail condition + if [ "$hFreePCT" -lt "$hMailPCT" -a "$hFreeMB" -lt "$hMailMB" ]; then + echo "$hTSName\t$hTotalMB\t$hUsedMB\t$hFreeMB\t$hFreePCT" >> $hTemporaryFileMail + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + + # check for page condition + if [ "$hFreePCT" -lt "$hPagePCT" -a "$hFreeMB" -lt "$hPageMB" ]; then + echo "$hTSName\t$hTotalMB\t$hUsedMB\t$hFreeMB\t$hFreePCT" >> $hTemporaryFilePage + hPageErrorCount=`expr $hPageErrorCount + 1` + fi + + fi + +done + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFileMail" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "5"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFileMail" +fi + +if [ "$hPageErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFilePage" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "5"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFilePage" +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +if [ -f "$hSQLPlusOutFile" ]; then + rm $hSQLPlusOutFile +fi + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hTempTSMonitor.ksh b/bin/hTempTSMonitor.ksh new file mode 100644 index 0000000..32f7dc6 --- /dev/null +++ b/bin/hTempTSMonitor.ksh @@ -0,0 +1,182 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 18-Feb-2009 +# Updation Date: 19-Feb-2009 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Temp TS Monitor [Mail Alert]" +hPageAlertTitle="Temp TS Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hTemporaryFile2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile2" "True"` +hSQL1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1"` +hSQL2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2"` + +hMailCondition=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailCondition"` +hPageCondition=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageCondition"` +hListTopSessionCount=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ListTopSessionCount"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "MailCondition: $hMailCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageCondition: $hPageCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ListTopSession: $hListTopSessionCount session(s) $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` +#run SQLPlus + +hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile"` + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + +# truncate temporary file +echo "Tablespace Name\tTotal Size[GB]\tUsed Size[GB]\tFree Size[GB]\tMax Size[GB] Ever Used\tMax Size[GB] Used by Sorts\tUsed Percentage" > $hTemporaryFile + +hPageErrorCount=0 +hMailErrorCount=0 + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hTablespaceName=`GetColumnValue "$LINE" "1"` + hTotalSize=`GetColumnValue "$LINE" "2"` + hUsedSize=`GetColumnValue "$LINE" "3"` + hFreeSize=`GetColumnValue "$LINE" "4"` + hMaxSize=`GetColumnValue "$LINE" "5"` + hMaxUsedSize=`GetColumnValue "$LINE" "6"` + hUsedPercentage=`GetColumnValue "$LINE" "7"` + + + echo "$hTablespaceName\t$hTotalSize\t$hUsedSize\t$hFreeSize\t$hMaxSize\t$hMaxUsedSize\t$hUsedPercentage" >> $hTemporaryFile + + if [ "$hUsedPercentage" -ge "$hPageCondition" ]; then + hPageErrorCount=`expr $hPageErrorCount + 1` + else + if [ "$hUsedPercentage" -ge "$hMailCondition" ]; then + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + fi + + # write history record + hTotalTime=`GetElapsedTime` + hReturn=`WriteHistoryRecord "$hTablespaceName\t$hTotalSize\t$hUsedSize\t$hFreeSize\t$hMaxSize\t$hMaxUsedSize\t$hUsedPercentage\t$hTotalTime"` + + fi + +done + +# check if the top sessions/queries to be listed +if [ "$hListTopSessionCount" -gt 0 ]; then + + if [ "$hMailErrorCount" -gt 0 -o "$hPageErrorCount" -gt 0 ]; then + + hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL2 $hListTopSessionCount" "$hSQLPlusExecutable" "$hTemporaryFile2"` + + if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + + fi + + if [ ! -z "$hSQLPlusOutput" ]; then + printf "___TABLE___\t10\tTop SORT Consuming Sessions\n" >> $hTemporaryFile + printf "Tablespace\tSID\tSerialNo\tProgram\tModule\tAction\tDB Username\tOS Username\t$Temp Used [MB]\tSQL\n" >> $hTemporaryFile + fi + + cat $hSQLPlusOutFile|while read LINE; + do + + if [ ! -z "$LINE" ]; then + + hTablespace=`GetColumnValue "$LINE" "1"` + hSID=`GetColumnValue "$LINE" "2"` + hSerialNo=`GetColumnValue "$LINE" "3"` + hProgram=`GetColumnValue "$LINE" "4"` + hModule=`GetColumnValue "$LINE" "5"` + hAction=`GetColumnValue "$LINE" "6"` + hUsername=`GetColumnValue "$LINE" "7"` + hOSUser=`GetColumnValue "$LINE" "8"` + hSizeMB=`GetColumnValue "$LINE" "9"` + hSQLText=`GetColumnValue "$LINE" "10"` + + printf "$hTablespace\t$hSID\t$hSerialNo\t$hProgram\t$hModule\t$hAction\t$hUsername\t$hOSUser\t$hSizeMB\t$hSQLText\n" >> $hTemporaryFile + + fi + + done + + + fi + +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "7"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + + if [ "$hPageErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "7"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat"` + rm "$hTemporaryFile" + fi + +fi + +if [ -f $hTemporaryFile ]; then + rm $hTemporaryFile +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hTranslateFile.ksh b/bin/hTranslateFile.ksh new file mode 100644 index 0000000..32fe5a8 --- /dev/null +++ b/bin/hTranslateFile.ksh @@ -0,0 +1,60 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 05-Aug-2009 +############################################################### + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/HSR.env + +hSourceUpper=`ToUpper $1` +hTargetUpper=`ToUpper $2` + +hSourceLower=`ToLower $1` +hTargetLower=`ToLower $2` + +# sourcing the source environment ini +. $hDirName/$hSourceUpper.source.ini + +TMPFILE=`mktemp` + +cat $hDirName/hTranslateFile.ini|grep -v '^#'|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + #hSource=`echo "$LINE"|awk -F= '{print $1}'` + #hTarget=`echo "$LINE"|awk -F= '{print $2}'` + + hSource=$(echo "$LINE"|cut -d "=" -f1) + hTarget=$(echo "$LINE"|cut -d "=" -f2) + + sudo cp "$hSource" "$hTarget" + + cat $hDirName/$hTargetUpper.target.ini|grep -v '^#'|while read LINE2; + do + + if [ ! -z "$LINE2" ]; then + + hSTR=$(MyEval "$LINE2") + + hCMD="sudo sed -e 's!"$hSTR"!g' $hTarget" + echo "$hCMD > $TMPFILE" > /tmp/h.sh + sh /tmp/h.sh + sudo mv "$TMPFILE" "$hTarget" + + fi + + done + + fi + +done + +#sed -e "s|$hSourceUpper|$hTargetUpper|g" -e "s|$hSourceLower|$hTargetLower|g" $ORACLE_HOME/dbs/initORCL.ora + +exit 0 + +#/HSR_SCRIPTS/hScripts/hTranslateFile.ksh ORCL NEWORCL diff --git a/bin/hUNDOTSMonitor.ksh b/bin/hUNDOTSMonitor.ksh new file mode 100644 index 0000000..a6fa1f8 --- /dev/null +++ b/bin/hUNDOTSMonitor.ksh @@ -0,0 +1,204 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 18-Feb-2009 +# Updation Date: 19-Feb-2009 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="UNDO Tablespace Monitor [Mail Alert]" +hPageAlertTitle="UNDO Tablespace Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +#hUserID="" +hTemporaryFile2=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile2" "True") + +hSQL1=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1" "True") +hSQL2=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2") + +hMailCondition=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailCondition") +hPageCondition=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageCondition") +hListTopSessionCount=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ListTopSessionCount") + +hConfigReadTime=$(GetElapsedTime) + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "MailCondition: $hMailCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "PageCondition: $hPageCondition $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "ListTopSession: $hListTopSessionCount session(s) $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +#run SQLPlus +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + +fi + + +# truncate temporary file + +printf "Description\tValue\n" > $hTemporaryFile + +hPageErrorCount=0 +hMailErrorCount=0 + +cat "$hSQLPlusOutFile"|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + + hTSSizeInMB=$(GetColumnValue "$LINE" "1") + hUndoPerSecInKB=$(GetColumnValue "$LINE" "2") + hUndoForMaxQueryInMB=$(GetColumnValue "$LINE" "3") + hMaxQueryLengthInSec=$(GetColumnValue "$LINE" "4") + hUndoAdvisoryInMB=$(GetColumnValue "$LINE" "5") + hMaxTRNSizeInMB=$(GetColumnValue "$LINE" "6") + hTotalUsedSizeInMB=$(GetColumnValue "$LINE" "7") + hTRNCount=$(GetColumnValue "$LINE" "8") + hUndoRetentionInSec=$(GetColumnValue "$LINE" "9") + hTunedUndoRetentionInSec=$(GetColumnValue "$LINE" "10") + hMinTunedUndoRetentionInSec=$(GetColumnValue "$LINE" "11") + + echo "UNDO TableSpace Size [in MB]\t$hTSSizeInMB" >> $hTemporaryFile + echo "UNDO/SEC [in KB]\t$hUndoPerSecInKB" >> $hTemporaryFile + echo "UNDO Required based on MAX QUERY LENGTH [in MB]\t$hUndoForMaxQueryInMB" >> $hTemporaryFile + echo "Max Query Length [in sec]\t$hMaxQueryLengthInSec" >> $hTemporaryFile + echo "UNDO Required based on UNDO Advisory\t$hUndoAdvisoryInMB" >> $hTemporaryFile + echo "Highest UNDO consuming transaction size [in MB]\t$hMaxTRNSizeInMB" >> $hTemporaryFile + echo "Total UNDO Utilization [in MB]\t$hTotalUsedSizeInMB" >> $hTemporaryFile + echo "Total Number of Active Transactions\t$hTRNCount" >> $hTemporaryFile + echo "UNDO_RETENTION [v\$parameter]\t$hUndoRetentionInSec" >> $hTemporaryFile + echo "V\$UNDOSTAT.tuned_undoretention [in sec]\t$hTunedUndoRetentionInSec" >> $hTemporaryFile + echo "MIN of V\$UNDOSTAT.tuned_undoretention [in sec]\t$hMinTunedUndoRetentionInSec" >> $hTemporaryFile + + if [ "$hTunedUndoRetentionInSec" -le "$hPageCondition" ]; then + hPageErrorCount=`expr $hPageErrorCount + 1` + else + if [ "$hTunedUndoRetentionInSec" -le "$hMailCondition" ]; then + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + fi + + # write history record + hReturn=$(WriteHistoryRecord "$hConfigReadTime\t$hTSSizeInMB\t$hUndoPerSecInKB\t$hUndoForMaxQueryInMB\t$hMaxQueryLengthInSec\t$hUndoAdvisoryInMB\t$hMaxTRNSizeInMB\t$hTotalUsedSizeInMB\t$hTRNCount\t$hUndoRetentionInSec\t$hTunedUndoRetentionInSec\t$hMinTunedUndoRetentionInSec") + + fi + +done + + +# check if the top sessions/queries to be listed +if [ "$hListTopSessionCount" -gt 0 ]; then + + if [ "$hMailErrorCount" -gt 0 -o "$hPageErrorCount" -gt 0 ]; then + + hSQLPlusOutput=`RunSQLCommand "$hCredentials" "$hSQL2 $hListTopSessionCount" "$hSQLPlusExecutable" "$hTemporaryFile2"` + + if [ $? -eq 1 ]; then + + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + + exit 1 + + fi + + if [ ! -z "$hSQLPlusOutput" ]; then + printf "___TABLE___\t10\tTop UNDO Consuming Sessions\n" >> $hTemporaryFile + printf "SID\tSerialNo\tProgram\tModule\tAction\tDB Username\tOS Username\t$UNDO Used [MB]\tSQL\n" >> $hTemporaryFile + fi + + cat $hSQLPlusOutFile|while read LINE; + do + + if [ ! -z "$LINE" ]; then + + hSID=`GetColumnValue "$LINE" "1"` + hSerialNo=`GetColumnValue "$LINE" "2"` + hProgram=`GetColumnValue "$LINE" "3"` + hModule=`GetColumnValue "$LINE" "4"` + hAction=`GetColumnValue "$LINE" "5"` + hUsername=`GetColumnValue "$LINE" "6"` + hOSUser=`GetColumnValue "$LINE" "7"` + hSizeMB=`GetColumnValue "$LINE" "8"` + hSQLText=`GetColumnValue "$LINE" "9"` + + printf "$hSID\t$hSerialNo\t$hProgram\t$hModule\t$hAction\t$hUsername\t$hOSUser\t$hSizeMB\t$hSQLText\n" >> $hTemporaryFile + + fi + + done + + + fi + +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "2"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` + + if [ "$hPageErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "2"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + else + `WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat"` + fi + +fi + +if [ -f $hTemporaryFile ]; then + rm $hTemporaryFile +fi + +if [ -f $hTemporaryFile2 ]; then + rm $hTemporaryFile2 +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hURLCheck.java b/bin/hURLCheck.java new file mode 100644 index 0000000..a5a8e25 --- /dev/null +++ b/bin/hURLCheck.java @@ -0,0 +1,42 @@ +import java.net.*; +import java.io.*; + +/* + HTTP 200 is success, + everything else is failure + +############################################################### + # Author: Habib Rangoonwala + # Created: 12-DEC-2009 + # Updated: 05-FEB-2010 +############################################################### + +*/ + + public class hURLCheck { + + public static void main(String args[]) { + if (args.length == 0) { + System.err.println + ("NO URL Provided!"); + } else { + String urlString = args[0]; + try { + URL url = new URL(urlString); + URLConnection connection = + url.openConnection(); + if (connection instanceof HttpURLConnection) { + HttpURLConnection httpConnection = + (HttpURLConnection)connection; + httpConnection.connect(); + int response = + httpConnection.getResponseCode(); + System.out.println( + "Response: " + response); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } diff --git a/bin/hURLMonitor.ksh b/bin/hURLMonitor.ksh new file mode 100644 index 0000000..450c307 --- /dev/null +++ b/bin/hURLMonitor.ksh @@ -0,0 +1,107 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 12-Dec-2009 +# Updation Date: 12-Dec-2009 +# Updation Date: 12-Dec-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="URL Monitor [Mail Alert]" +hPageAlertTitle="URL Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# Read Script Specific Configuration Parameter +hTemporaryFile1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile1" "True"` +hURLList=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "URLList" "True"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "URLList: $hURLList $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +# truncate temporary file +echo "Serial #\tName\tURL\tStatus\tOutput" > $hTemporaryFile + +hPageErrorCount=0 +hSRNo=1 +CLASSPATH=$hDirName:$CLASSPATH ; export CLASSPATH + +# Check if the URLList is configured +if [ ! -f "$hURLList" ]; then + `WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "FILE: $hURLList is not configured" "$hDateFormat"` + + `WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat"` + `SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "FILE: $hURLList is NOT configured"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` + exit 1 +fi +hTotalURLs=`wc -l $hURLList` + +cat "$hURLList"|while read LINE; +do + if [ -z "$LINE" ]; then + continue; + fi + + hName=`GetColumnValue "$LINE" "1"` + hURL=`GetColumnValue "$LINE" "2"` + + # if the line is commented, please ignore it + if [ `echo "$hName"|cut -c1` = "#" ]; then + echo ".\t$hName\t$hURL\tIgnored\tURL is commented out in config file" >> $hTemporaryFile + `WriteLogFile $hScriptLogFile "Success $hNewLine" "$hDateFormat"` + continue + fi + + `WriteLogFile $hScriptLogFile "Checking ***$hSRNo of $hTotalURLs*** [$hName]:[$hURL] . . . . . $hNewLine" "$hDateFormat"` + + hOutput=`java -cp $CLASSPATH hURLCheck $hURL 2>$hTemporaryFile1` + echo "$hOutput" >> $hTemporaryFile1 + #hOutput="`expand $hTemporaryFile1|tail -1`" + hOutput="`sed -e 's/ /<br>/' $hTemporaryFile1 |tr -d '\n'`" + hOutput2="`cat $hTemporaryFile1" + + hResponse=`echo $hOutput | awk '{print $2}'` + if [ "$hResponse" = "200" -o "$hResponse" = "301" -o "$hResponse" = "302" ]; then + echo "$hSRNo\t$hName\t$hURL\tSuccess [$hResponse]\t$hOutput" >> $hTemporaryFile + `WriteLogFile $hScriptLogFile "Success $hNewLine" "$hDateFormat"` + elif [ "$hResponse" = "500" ]; then + echo "$hSRNo\t$hName\t$hURL\tFailure [$hResponse]\t$hOutput" >> $hTemporaryFile + `WriteLogFile $hScriptLogFile "Failed $hNewLine $hOutput2" "$hDateFormat"` + hPageErrorCount=`expr $hPageErrorCount + 1` + else + echo "$hSRNo\t$hName\t$hURL\tFailure [$hResponse]\t$hOutput" >> $hTemporaryFile + `WriteLogFile $hScriptLogFile "Failed $hNewLine $hOutput2" "$hDateFormat"` + hPageErrorCount=`expr $hPageErrorCount + 1` + fi + hSRNo=`expr $hSRNo + 1` + +done + +if [ "$hPageErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Page to $hPageAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "$hMailSubject FAILEDCount=$hPageErrorCount" "$hPageAlertTitle <br> $hPageErrorCount [Failed] out of $hTotalURLs" "5"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat"` +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hWFInBoundMailMonitor.ksh b/bin/hWFInBoundMailMonitor.ksh new file mode 100644 index 0000000..e773dd2 --- /dev/null +++ b/bin/hWFInBoundMailMonitor.ksh @@ -0,0 +1,147 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 09-Sep-2008 +# Updation Date: 09-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="WF InBound Mail Monitor [Mail Alert]" +hPageAlertTitle="WF InBound Mail Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hTemporaryFile2=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile2" "True") +hSQL1="" + +hInboxFile=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "InboxFile" "True") +hProcessedFile=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "ProcessedFile" "True") +hDiscardFile=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "DiscardFile" "True") + +hMailLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "MailLimitInMinutes") +hPageLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "PageLimitInMinutes") + +hConfigReadTime=$(GetElapsedTime) + +# write Script Specific Details to logfile +$(WriteLogFile $hScriptLogFile "InboxFile: $hInboxFile $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "ProcessedFile: $hProcessedFile $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "DiscardFile: $hDiscardFile $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "MailLimit: $hMailLimit mins $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "PageLimit: $hPageLimit mins $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat") + +hMailErrorCount=0 +hPageErrorCount=0 + +hInboxFileTimestamp=$(ls -E "$hInboxFile" | awk '{print $6$7}'|cut -d. -f1) +hProcessedFileTimestamp=$(ls -E "$hProcessedFile" | awk '{print $6$7}'|cut -d. -f1) +hDiscardFileTimestamp=$(ls -E "$hDiscardFile" | awk '{print $6$7}'|cut -d. -f1) + +printf "Filename\tLast Update TimeStamp\tDifference in Minutes\tLimit\n" > $hTemporaryFile2 + +hSQL1=" +SELECT ROUND((TO_DATE('$hInboxFileTimestamp','yyyy-mm-ddhh24:mi:ss') - TO_DATE('$hProcessedFileTimestamp','yyyy-mm-ddhh24:mi:ss')) * 1440)||CHR(9)|| +ROUND((TO_DATE('$hInboxFileTimestamp','yyyy-mm-ddhh24:mi:ss') - TO_DATE('$hDiscardFileTimestamp','yyyy-mm-ddhh24:mi:ss')) * 1440) FROM dual +" + +#run SQLPlus + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + $(WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +#cat $hSQLPlusOutFile|while read LINE; +echo "$hSQLPlusOutput"|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hLimit1=$(GetColumnValue "$LINE" "1") + hLimit2=$(GetColumnValue "$LINE" "2") + + if [ "$hLimit1" -gt "$hLimit2" ]; then + hLimit=$hLimit2 + else + hLimit=$hLimit1 + fi + + if [ "$hLimit" -gt "$hPageLimit" ]; then + hPageErrorCount=`expr $hPageErrorCount + 1` + else + if [ "$hLimit" -gt "$hMailLimit" ]; then + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + fi + + printf "$hInboxFile\t$hInboxFileTimestamp\t0\t MailLimit $hMailLimit min, PageLimit $hPageLimit min\n" >> $hTemporaryFile2 + printf "$hProcessedFile\t$hProcessedFileTimestamp\t$hLimit1\t MailLimit $hMailLimit min, PageLimit $hPageLimit min\n" >> $hTemporaryFile2 + printf "$hDiscardFile\t$hDiscardFileTimestamp\t$hLimit2\t MailLimit $hMailLimit min, PageLimit $hPageLimit min\n" >> $hTemporaryFile2 + + fi + +done + +if [ "$hPageErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile2" "$hFromAlias" "$hPageAlias" "$hMailSubject" "$hPageAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") +else + $(WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat") + + if [ "$hMailErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile2" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat") + else + $(WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat") + fi + +fi + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +if [ -f "$hTemporaryFile2" ]; then + rm "$hTemporaryFile2" +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +$(WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat") + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hWFQueueMonitor.ksh b/bin/hWFQueueMonitor.ksh new file mode 100644 index 0000000..fff4159 --- /dev/null +++ b/bin/hWFQueueMonitor.ksh @@ -0,0 +1,161 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 09-Sep-2008 +# Updation Date: 09-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="WF Queue Monitor [Mail Alert]" +hPageAlertTitle="WF Queue Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# source SQLPlus environment +. $hDirName/hInitializeSQLPlus.ksh +if [ $? -eq 1 ]; then + `WriteLogFile $hScriptLogFile "Unable to Load SQLPlus environment $hNewLine" "$hDateFormat"` + exit 1 +fi + +# Read Script Specific Configuration Parameter +hTemporaryFile2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "TemporaryFile2" "True"` + +hSQL1=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL1") +hSQL2=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "SQL2") + +hWFQueueMailLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "WFQueueMailLimit") +hWFQueuePageLimit=$(GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "WFQueuePageLimit") + +hConfigReadTime=$(GetElapsedTime) + +# write Script Specific Details to logfile +$(WriteLogFile $hScriptLogFile "WFQueueMailLimit: $hWFQueueMailLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "WFQueuePageLimit: $hWFQueuePageLimit $hNewLine" "$hDateFormat") +$(WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat") + +#run SQLPlus + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL1" "$hSQLPlusExecutable" "$hTemporaryFile") + +if [ $? -eq 1 ]; then + + $(WriteLogFile $hScriptLogFile "Following error occurred $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "$hSQLPlusOutput" "$hDateFormat") + + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendSingleLineEmail "$hTemporaryFile" "$hFromAlias" "$hPageAlias" "FAILED:$hMailSubject" "$hPageAlertTitle" "$hSQLPlusOutput") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") + + exit 1 + +fi + +hMailErrorCount=0 +hPageErrorCount=0 +hComponentDown="False" + +printf "Component Name\tComponent Status\tComponent Status Info\tLast Update TimeStamp\n" > $hTemporaryFile2 + +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hComponentName=$(GetColumnValue "$LINE" "1") + hComponentStatus=$(GetColumnValue "$LINE" "2") + hComponentStatusInfo=$(GetColumnValue "$LINE" "3") + hComponentTimeStamp=$(GetColumnValue "$LINE" "4") + + if [ "$hComponentStatus" != "RUNNING" ]; then + hComponentDown="True" + fi + + printf "$hComponentName\t$hComponentStatus\t$hComponentStatusInfo\t$hComponentTimeStamp\n" >> $hTemporaryFile2 + + fi + +done + +hSQLPlusOutput=$(RunSQLCommand "$hCredentials" "$hSQL2" "$hSQLPlusExecutable" "$hTemporaryFile") +cat $hSQLPlusOutFile|while read LINE; +do + + if [ ! -z "$LINE" ]; then + + hMailStatus=$(GetColumnValue "$LINE" "1") + hStatus=$(GetColumnValue "$LINE" "2") + hCount=$(GetColumnValue "$LINE" "3") + hNID=$(GetColumnValue "$LINE" "4") + + if [ "$hComponentDown" = "True" ]; then + printf "___TABLE___\t5\tWF Pending Notification Status\n" >> $hTemporaryFile2 + printf "Mail Status\tStatus\tPending Count\tLatest NID\tLimit\n" >> $hTemporaryFile2 + else + printf "Mail Status\tStatus\tPending Count\tLatest NID\tLimit\n" > $hTemporaryFile2 + fi + + if [ "$hCount" -gt "$hWFQueuePageLimit" ]; then + hPageErrorCount=`expr $hPageErrorCount + 1` + printf "$hMailStatus\t$hStatus\t$hCount\t$hNID\t$hWFQueuePageLimit PageLimit\n" >> $hTemporaryFile2 + else + if [ "$hCount" -gt "$hWFQueueMailLimit" ]; then + hMailErrorCount=`expr $hMailErrorCount + 1` + printf "$hMailStatus\t$hStatus\t$hCount\t$hNID\t$hWFQueueMailLimit MailLimit\n" >> $hTemporaryFile2 + fi + fi + + # write history record + hReturn=$(WriteHistoryRecord "$hConfigReadTime\t$hMailStatus\t$hStatus\t$hCount\t$hWFQueueMailLimit\t$hWFQueuePageLimit") + + fi +done + +if [ "$hComponentDown" = "True" ]; then + hPageErrorCount=`expr $hPageErrorCount + 1` +fi + +if [ "$hPageErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Page Alert Count $hPageErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hPageAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile2" "$hFromAlias" "$hPageAlias" "$hMailSubject [WF Queue CRITICAL COUNT=$hCount]" "$hPageAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hPageAlias $hNewLine" "$hDateFormat") +else + $(WriteLogFile $hScriptLogFile "No Page Alert $hNewLine" "$hDateFormat") + + if [ "$hMailErrorCount" -gt 0 ]; then + $(WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat") + $(WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat") + $(SendMultiLineEmail "$hTemporaryFile2" "$hFromAlias" "$hMailAlias" "$hMailSubject [WF Queue WARNING COUNT=$hCount]" "$hMailAlertTitle" "4") + $(WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat") + else + $(WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat") + fi + +fi + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +if [ -f "$hTemporaryFile2" ]; then + rm "$hTemporaryFile2" +fi + +if [ -f $hSQLPlusOutFile ]; then + rm $hSQLPlusOutFile +fi + +$(WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat") + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/bin/hZombieMonitor.ksh b/bin/hZombieMonitor.ksh new file mode 100644 index 0000000..9b016cb --- /dev/null +++ b/bin/hZombieMonitor.ksh @@ -0,0 +1,109 @@ +#!/bin/ksh + +############################################################### +# Author: Habib Rangoonwala +# Creation Date: 08-Sep-2008 +# Updation Date: 08-Sep-2008 +# Updation Date: 19-Feb-2009 +############################################################### + +# define Alert Title +hMailAlertTitle="Zombie Monitor [Mail Alert]" +hPageAlertTitle="Zombie Monitor [Page Alert]" + +# source the main environment file +hDirName=`dirname $0` +. $hDirName/hInitialize.ksh "$0" +if [ $? -eq 1 ]; then + exit 1 +fi + +# Read Script Specific Configuration Parameter +hCommand1=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Command1"` +hCommand2=`GetScriptParameter "$hInstance" "$hHost" "$H_SCRIPTSECTION" "Command2"` + +# write Script Specific Details to logfile +`WriteLogFile $hScriptLogFile "Command1: $hCommand1 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "Command2: $hCommand2 $hNewLine" "$hDateFormat"` +`WriteLogFile $hScriptLogFile "$hTmpStr $hNewLine" "$hDateFormat"` + +# run PS command to get the output +echo "$hCommand1" > $hTemporaryFile +chmod 755 $hTemporaryFile +hOutput=`sh $hTemporaryFile` +hCount=`echo "$hOutput"|wc -l` +hMailErrorCount=0 +hPID=0 + +# truncate temporary file +echo "PPID\tPID\tCommand\tOwner\tCPU\tMemory\tTime\tParent Process" > $hTemporaryFile + +`WriteLogFile $hScriptLogFile "Processing $hCount entries $hNewLine" "$hDateFormat"` + +echo "$hOutput"|while read LINE; +do + + if [ -z "$LINE" ]; then + break; + fi + + hPPID=`GetColumnValue "$LINE" "1"` + hPID=`GetColumnValue "$LINE" "2"` + hStatus=`GetColumnValue "$LINE" "3"` + hComm=`GetColumnValue "$LINE" "4"` + hOwner=`GetColumnValue "$LINE" "5"` + hCPU=`GetColumnValue "$LINE" "6"` + hMemory=`GetColumnValue "$LINE" "7"` + hTime=`GetColumnValue "$LINE" "8"` + + if [ ! -z "$hPPID" ]; then + hPS=`ps -p $hPPID -o "comm args"|tail -1` + else + hPS="." + fi + + if [ "$hStatus" = "Z" ]; then + + `WriteLogFile $hScriptLogFile "Sleeping for 10 Seconds and rechecking PID=$hPID $hNewLine" "$hDateFormat"` + + # wait for 10 sec to get it cleared automatically + sleep 10 + + echo "$hCommand2 $hPID" > $hTemporaryFile.2 + chmod 755 $hTemporaryFile.2 + hOutput2=`sh $hTemporaryFile.2` + rm $hTemporaryFile.2 + LINE2=`echo "$hOutput2"|grep $hPID` + hStatus=`echo $LINE2 |cut -d " " -f3` + + if [ "$hStatus" = "Z" ]; then + + `WriteLogFile $hScriptLogFile "PID=$hPID OWNER=$hOwner - $hComm - is in ZOMBIE status after recheck $hNewLine" "$hDateFormat"` + + echo "$hPPID\t$hPID\t$hComm\t$hOwner\t$hCPU\t$hMemory\t$hTime\t$hPS" >> $hTemporaryFile + hMailErrorCount=`expr $hMailErrorCount + 1` + fi + + fi + +done + +if [ "$hMailErrorCount" -gt 0 ]; then + `WriteLogFile $hScriptLogFile "Mail Alert Count $hMailErrorCount $hNewLine" "$hDateFormat"` + `WriteLogFile $hScriptLogFile "Sending Alert to $hMailAlias $hNewLine" "$hDateFormat"` + `SendMultiLineEmail "$hTemporaryFile" "$hFromAlias" "$hMailAlias" "$hMailSubject" "$hMailAlertTitle [ProcessCount=$hMailErrorCount]" "8"` + `WriteLogFile $hScriptLogFile "Alert Sent to $hMailAlias $hNewLine" "$hDateFormat"` +else + `WriteLogFile $hScriptLogFile "No Mail Alert $hNewLine" "$hDateFormat"` +fi + +`WriteLogFile $hScriptLogFile "Script completed $hNewLine" "$hDateFormat"` + +if [ -f "$hTemporaryFile" ]; then + rm "$hTemporaryFile" +fi + +# truncate log file <hScriptLogFileSize> lines +tail "-$hScriptLogFileSize" $hScriptLogFile > $hTemporaryFile +mv $hTemporaryFile $hScriptLogFile +exit 0 diff --git a/conf/ORCL.URLList.ini b/conf/ORCL.URLList.ini new file mode 100644 index 0000000..27e324a --- /dev/null +++ b/conf/ORCL.URLList.ini @@ -0,0 +1,8 @@ +LBURL http://ebsdev1.example.com/ +LBLocalLogin http://ebsdev1.example.com/OA_HTML/AppsLocalLogin.jsp +APP1LocalLogin http://ebsappnode01.example.com:8001/OA_HTML/AppsLocalLogin.jsp +APP1JTFLogin http://ebsappnode01.example.com:8001/OA_HTML/jtflogin.jsp +APP2LocalLogin http://ebsappnode02.example.com:8001/OA_HTML/AppsLocalLogin.jsp +APP2JTFLogin http://ebsappnode02.example.com:8001/OA_HTML/jtflogin.jsp +APP3LocalLogin http://ebsappnode03.example.com:8001/OA_HTML/AppsLocalLogin.jsp +APP3JTFLogin http://ebsappnode03.example.com:8001/OA_HTML/jtflogin.jsp diff --git a/conf/ORCL.config.ini b/conf/ORCL.config.ini new file mode 100644 index 0000000..fe17998 --- /dev/null +++ b/conf/ORCL.config.ini @@ -0,0 +1,33 @@ +# ORCL Instance Specific settings, this is sample file, +# Author: Habib Rangoonwala +# Created: 09-Sep-2009 +# The backup portion is assumed to be using a snapshot technology like NetApp, you can customize it by modifying the config.ini section +########################################################################################################################################## + +ORCL.dbhost01.hHotBackup.Volumes=ebsfiler01:vol_home;ebsfiler01:vol_appltop;ebsfiler01:vol_applcsf;ebsfiler01:vol_oradata01;svldevflr502:vol_oradata02 +ORCL.dbhost01.hHotBackup.ArchVolumes=ebsfiler01:vol_arch01 +ORCL.dbhost01.hHotBackup.CLONEPreparationVolume=ebsfiler01:vol_dbbin01 +ORCL.dbhost01.hHotBackup.IsEnabled=True + +ORCL.ebscmhost01.hProfileOptionMonitor.IsEnabled=True +ORCL.ebscmhost01.hProfileOptionMonitor.SendEMail=True +ORCL.ebscmhost01.hResponsibilityMonitor.IsEnabled=True +ORCL.ebscmhost01.hResponsibilityMonitor.SendEMail=True +ORCL.ebscmhost01.hWFInBoundMailMonitor.IsEnabled=True + +ORCL.default.hAlertLogMonitor.IsEnabled=False +ORCL.default.hTSMonitor.IsEnabled=True +ORCL.default.hDBSessionMonitor.IsEnabled=True +ORCL.default.hLockMonitor.IsEnabled=True +ORCL.default.hTempTSMonitor.IsEnabled=True +ORCL.default.hCMQueueMonitor.IsEnabled=True +ORCL.default.hSFMQueueMonitor.IsEnabled=True +ORCL.default.hWFQueueMonitor.IsEnabled=True +ORCL.default.hUNDOTSMonitor.IsEnabled=True +ORCL.default.hRunawayMonitor.IsEnabled=True +ORCL.default.hURLMonitor.IsEnabled=True +ORCL.default.hZombieMonitor.IsEnabled=True +ORCL.default.hOSMonitor.IsEnabled=True + +ORCL.default.hOSMonitor.LoadMailLimit=$(echo $($H_SCRIPT_TOP/hGetCPUCount.ksh)*1|bc) +ORCL.default.hOSMonitor.LoadPageLimit=$(echo $($H_SCRIPT_TOP/hGetCPUCount.ksh)*2|bc) \ No newline at end of file diff --git a/conf/ResponsibilityMonitor.config.ini b/conf/ResponsibilityMonitor.config.ini new file mode 100644 index 0000000..d84e3e7 --- /dev/null +++ b/conf/ResponsibilityMonitor.config.ini @@ -0,0 +1,5 @@ +ALL:SYSADMIN,HABIB +System Administrator:USER01 +System Administration:USER01 +Workflow Administrator:WFUSER +Application Administrator:APPDBA01 \ No newline at end of file diff --git a/conf/default.config.ini b/conf/default.config.ini new file mode 100644 index 0000000..f38bf4c --- /dev/null +++ b/conf/default.config.ini @@ -0,0 +1,182 @@ +############################################################### +# +# Author: Habib Rangoonwala +# Creation Date: 16-Mar-2007 +# Updation Date: 02-Aug-2007 +# Updation Date: 19-Feb-2009 +# Updation Date: 11-Feb-2010 [Coldbackup Included, SuccessFlagFile Changes] +# Following is the format of this file +# +# Instance.Hostname.Section.Key=Value +# +############################################################### + +default.default.DefaultSection.MailSubject=$ORACLE_SID$TWO_TASK:$H_SCRIPTSECTION:$H_HOSTNAME +default.default.DefaultSection.EnvironmentFile=$HOME/.profile +default.default.DefaultSection.FromAlias="$ORACLE_SID$TWO_TASK-$(id|tr '(' ' '|tr ')' ' '|awk '{print $2}')" '<no-reply@example.com>' +default.default.DefaultSection.MailAlias=mailalias@example.com +default.default.DefaultSection.PageAlias=pager@example.com +default.default.DefaultSection.TempDirectory=/tmp/ +default.default.DefaultSection.LogDirectory=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK +default.default.DefaultSection.LockFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/lock/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.lock +default.default.DefaultSection.ScriptLogFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.log +default.default.DefaultSection.RunLogFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/run/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.`date +"%d%b%Y_%H%M"`.run.log +default.default.DefaultSection.HistoryFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/his/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.his +default.default.DefaultSection.TemporaryFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/tmp/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.0.$H_HOSTNAME.tmp.$$ +default.default.DefaultSection.TemporaryFile1=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/tmp/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.1.$H_HOSTNAME.tmp.$$ +default.default.DefaultSection.TemporaryFile2=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/tmp/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.2.$H_HOSTNAME.tmp.$$ +default.default.DefaultSection.DateFormat=%a %d-%b-%Y %H:%M:%S [%Z] +default.default.DefaultSection.NewLine=\\n +default.default.DefaultSection.ScriptLogFileSize=1000 +default.default.DefaultSection.CryptKey=supersecret +default.default.DefaultSection.SYSDBA=True +default.default.DefaultSection.Credentials=$H_SCRIPT_TOP/../auth/$ORACLE_SID$TWO_TASK.SYSTEM.credentials +default.default.DefaultSection.SQLPlusExecutable=$ORACLE_HOME/bin/sqlplus -s +default.default.DefaultSection.SQLPlusOutFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/tmp/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.$$.out +default.default.DefaultSection.IsEnabled=False + +default.default.hAlertLogMonitor.AlertLogFile=$HOME/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log +default.default.hAlertLogMonitor.ScriptReferenceFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/ref/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.ref +default.default.hAlertLogMonitor.MailKeywords=error fail ora- app- start shut stop select +default.default.hAlertLogMonitor.MailKeywordsIgnoreList=ORA-00060 ORA-3136 starting stopping TNS-12535 TNS-00505 started +default.default.hAlertLogMonitor.PageKeywords=ora- app- +default.default.hAlertLogMonitor.PageKeywordsIgnoreList=ORA-00060 ORA-12161 ORA-3136 started +default.default.hAlertLogMonitor.DisplayFullRecord=True +default.default.hAlertLogMonitor.ScriptLogFileSize=1000 +default.default.hAlertLogMonitor.IsEnabled=False + +default.default.hTSMonitor.SQL1=SELECT tsname||CHR(9)||ROUND(total_mb,2)||CHR(9)||ROUND(used_mb,2)||CHR(9)||ROUND(free_mb,2)||CHR(9)||round(used_mb/total_mb*100,0) from ( select ddf.tsname,total_mb, total_mb-(free_mb+(total_mb-used_mb)) used_mb, free_mb+(total_mb-used_mb) free_mb from ( select tablespace_name tsname, round(sum(decode(maxbytes,0,bytes,maxbytes)/1024/1024),0) total_mb, round(sum(bytes/1024/1024),0) used_mb from dba_Data_files group by tablespace_name ) ddf, ( select tablespace_name tsname, sum(bytes/1024/1024) free_mb from dba_free_space group by tablespace_name ) dfs where ddf.tsname=dfs.tsname(+) ) where round(used_mb/total_mb*100,0) > 50 +default.default.hTSMonitor.MailCondition=20,2048 +default.default.hTSMonitor.PageCondition=5,1024 +default.default.hTSMonitor.IsEnabled=False + +default.default.hOSMonitor.CPUMailLimit=80 +default.default.hOSMonitor.CPUPageLimit=95 +default.default.hOSMonitor.LoadMailLimit=$(echo $(psrinfo|wc -l)*1|bc) +default.default.hOSMonitor.LoadPageLimit=$(echo $(psrinfo|wc -l)*2|bc) +default.default.hOSMonitor.ShowTopProcesses=10 +default.default.hOSMonitor.IsEnabled=False + +default.default.hLockMonitor.SQL1=select s1.sid||CHR(9)||s1.serial#||CHR(9)||s1.username||CHR(9)||s1.machine||CHR(9)||s1.program||CHR(9)||s1.module||CHR(9)||s1.action||CHR(9)||s1.status||CHR(9)||s1.last_call_et||CHR(9)||REPLACE(sa1.sql_text,CHR(9),' ')||CHR(9)||s2.sid||CHR(9)||s2.serial#||CHR(9)||s2.username||CHR(9)||s2.machine||CHR(9)||s2.program||CHR(9)||s2.module||CHR(9)||s2.action||CHR(9)||s2.status||CHR(9)||s2.last_call_et||CHR(9)||REPLACE(sa2.sql_Text,CHR(9),' ') from v$lock l1, v$session s1, v$sqlarea sa1,v$lock l2, v$session s2,v$sqlarea sa2 where s1.sid=l1.sid and s2.sid=l2.sid and l1.BLOCK=1 and l2.request > 0 and l1.id1 = l2.id1 and l2.id2 = l2.id2 and s1.sql_address=sa1.address(+) and s2.sql_Address=sa2.address (+) +default.default.hLockMonitor.ShowSQL=True +default.default.hLockMonitor.IsEnabled=False + +default.default.hRunawayMonitor.SQL1=select sid||CHR(9)||serial#||CHR(9)||program||CHR(9)||module||CHR(9)||action||CHR(9)||username||CHR(9)||machine||CHR(9)||status||CHR(9)||last_call_et from v$session where process = +default.default.hRunawayMonitor.SQL2=select a.sid||CHR(9)||a.serial#||CHR(9)||CHR(9)||a.program||CHR(9)||a.module||CHR(9)||a.action||CHR(9)||a.username||CHR(9)||a.machine||CHR(9)||a.status||CHR(9)||a.last_call_et from v$session a, v$process b where a.paddr=b.addr and b.spid = +default.default.hRunawayMonitor.CPULimit=3 +default.default.hRunawayMonitor.DBSessionIdleLimit=3600 +default.default.hRunawayMonitor.Command1=ps -e -o "pid pcpu user comm"|grep -i f60webmx +default.default.hRunawayMonitor.IsEnabled=False + +default.default.hZombieMonitor.Command1=ps -e -o "ppid pid s comm user pcpu pmem time" |grep `id|tr "(" " "|tr ")" " "|awk '{print $2}'`|grep Z +default.default.hZombieMonitor.Command2=ps -o "ppid pid s comm user pcpu pmem time" -p +default.default.hZombieMonitor.IsEnabled=False + +default.default.hDBSessionMonitor.SQL1=select sid||CHR(9)||serial#||CHR(9)||program||CHR(9)||module||CHR(9)||action||CHR(9)||username||CHR(9)||NVL(terminal,machine)||CHR(9)||osuser||CHR(9)||status||CHR(9)||last_call_et from v$session where (module like '%T.O.A.D%' OR module like '%TOAD%' OR module like '%coverer%' OR upper(module) like '%TOAD%' or upper(program) like '%TOAD%' or module like '%SQL%D%' ) AND status NOT IN ('ACTIVE','KILLED') and last_call_et >= +default.default.hDBSessionMonitor.IdleTimeInSeconds=21600 +default.default.hDBSessionMonitor.IsEnabled=False + +default.default.hTempTSMonitor.SQL1=SELECT a.tablespace_name||CHR(9)||ROUND((c.total_blocks*b.block_size)/1024/1024/1024,2)||CHR(9)||ROUND((a.used_blocks*b.block_size)/1024/1024/1024,2)||CHR(9)||ROUND(((c.total_blocks-a.used_blocks)*b.block_size)/1024/1024/1024,2)||CHR(9)||ROUND((a.max_blocks*b.block_size)/1024/1024/1024,2)||CHR(9)||ROUND((a.max_used_blocks*b.block_size)/1024/1024/1024,2)||CHR(9)||ROUND((a.used_blocks/c.total_blocks)*100,2) FROM V$sort_segment a,dba_tablespaces b,(SELECT tablespace_name,SUM(blocks) total_blocks FROM dba_temp_files GROUP by tablespace_name) c WHERE a.tablespace_name=b.tablespace_name AND a.tablespace_name=c.tablespace_name +default.default.hTempTSMonitor.SQL2=SELECT * FROM ( SELECT d.tablespace_name||CHR(9)||a.sid||CHR(9)||a.serial#||CHR(9)||a.program||CHR(9)||a.module||CHR(9)||a.action||CHR(9)||a.username||CHR(9)||a.osuser||CHR(9)||ROUND((b.blocks*d.block_size)/1024/1024,2)||CHR(9)||c.sql_text FROM v$session a, v$tempseg_usage b, v$sqlarea c,dba_tablespaces d WHERE a.saddr = b.session_addr AND c.address= a.sql_address AND c.hash_value = a.sql_hash_value AND d.tablespace_name=b.tablespace ORDER BY b.tablespace, b.blocks DESC ) WHERE ROWNUM <= +default.default.hTempTSMonitor.MailCondition=50 +default.default.hTempTSMonitor.PageCondition=90 +default.default.hTempTSMonitor.ListTopSessionCount=10 +default.default.hTempTSMonitor.IsEnabled=False + +default.default.hHotBackup.SQL1=$H_SCRIPT_TOP/../sql/hBeginBackup.10g.sql +default.default.hHotBackup.SQL2=$H_SCRIPT_TOP/../sql/hEndBackup.10g.sql +default.default.hHotBackup.GetCurrentSequenceSQL=SELECT sequence# FROM v$log WHERE status='CURRENT' +default.default.hHotBackup.CryptKey= +default.default.hHotBackup.SYSDBA=True +default.default.hHotBackup.Credentials= +default.default.hHotBackup.Volumes= +default.default.hHotBackup.RedoVolumes= +default.default.hHotBackup.ArchVolumes= +default.default.hHotBackup.CreateSnapshotCommand=rsh -n $FILER snap create $VOLUME $SNAPSHOT +default.default.hHotBackup.RenameSnapshotCommand=rsh -n $FILER snap rename $VOLUME $FROM_SNAPSHOT $TO_SNAPSHOT +default.default.hHotBackup.DeleteSnapshotCommand=rsh -n $FILER snap delete $VOLUME $SNAPSHOT +default.default.hHotBackup.ListSnapshotCommand=rsh -n $FILER snap list $VOLUME +default.default.hHotBackup.SnapshotKeepDays=6 +default.default.hHotBackup.NamePattern=hotbackup_$ORACLE_SID +default.default.hHotBackup.RetryAttempt=10 +default.default.hHotBackup.RetryDelayInSeconds=6 +default.default.hHotBackup.ArchCleanUpScript=$H_SCRIPT_TOP/hArchCleanup.ksh +default.default.hHotBackup.ArchKeepDays=5 +default.default.hHotBackup.CLONEDirectory=$HOME/hCLONE +default.default.hHotBackup.CLONEPreparationScript=$H_SCRIPT_TOP/hCLONEPreparation.ksh +default.default.hHotBackup.CLONEPreparationVolume= +default.default.hHotBackup.SuccessFlagFile=$H_SCRIPT_TOP/../logs/$ORACLE_SID$TWO_TASK/$ORACLE_SID$TWO_TASK.$H_SCRIPTSECTION.$H_HOSTNAME.success +default.default.hHotBackup.Force=True +default.default.hHotBackup.IsEnabled=False + +default.default.hCMQueueMonitor.SQL1=SELECT fcqtl.concurrent_queue_name||CHR(9)||fcqtl.user_concurrent_queue_name||CHR(9)||MAX(fcq.max_processes)||CHR(9)||MAX(fcq.running_processes)||CHR(9)||SUM(DECODE(phase_code,'P',1,0))||CHR(9)||SUM(DECODE(phase_code,'R',1,0)) FROM apps.fnd_concurrent_worker_requests fcwr,apps.fnd_concurrent_queues_tl fcqtl,apps.fnd_concurrent_queues fcq WHERE fcwr.queue_application_id = fcqtl.application_id AND fcwr.concurrent_queue_id=fcqtl.concurrent_queue_id AND fcq.application_id = fcqtl.application_id AND fcq.concurrent_queue_id = fcqtl.concurrent_queue_id AND hold_flag != 'Y' AND requested_start_date <= SYSDATE GROUP BY fcqtl.concurrent_queue_name,fcqtl.user_concurrent_queue_name +default.default.hCMQueueMonitor.SQL2=$H_SCRIPT_TOP/../sql/hCMStatus.generic.sql +default.default.hCMQueueMonitor.QueueMailLimit=STANDARD:40;FNDCRM:20;DEFAULT:20 +default.default.hCMQueueMonitor.QueuePageLimit=STANDARD:80;FNDCRM:40;DEFAULT:50 +default.default.hCMQueueMonitor.IsEnabled=False + +default.default.hSFMQueueMonitor.SQL1=SELECT msg_status||CHR(9)||count(*)||CHR(9)||MAX(TO_CHAR(last_update_date,'DD-MON-RRRR HH24:MI:SS')) FROM apps.xnp_msgs GROUP BY msg_status +default.default.hSFMQueueMonitor.SFMQueueMailLimit=500 +default.default.hSFMQueueMonitor.SFMQueuePageLimit=800 +default.default.hSFMQueueMonitor.IsEnabled=False + +default.default.hWFQueueMonitor.SQL1=SELECT component_name||CHR(9)||component_status||CHR(9)||component_status_info||CHR(9)||TO_CHAR(last_update_date,'DD-MON-RRRR HH24:MI:SS') FROM apps.fnd_svc_components WHERE concurrent_queue_id = ( SELECT concurrent_queue_id FROM apps.fnd_concurrent_queues WHERE concurrent_queue_name = 'WFALSNRSVC' )ORDER BY component_type, component_id +default.default.hWFQueueMonitor.SQL2=SELECT mail_status||CHR(9)||status||CHR(9)||COUNT(*)||CHR(9)||MAX(notification_id) FROM apps.wf_notifications WHERE mail_status='MAIL' AND status='OPEN' GROUP BY status ,mail_status +default.default.hWFQueueMonitor.WFQueueMailLimit=500 +default.default.hWFQueueMonitor.WFQueuePageLimit=1000 +default.default.hWFQueueMonitor.IsEnabled=False + +default.default.hUNDOTSMonitor.SQL1=$H_SCRIPT_TOP/../sql/hUNDOTSMonitor.SQL1.10g.sql +default.default.hUNDOTSMonitor.SQL2=SELECT * FROM ( SELECT a.sid||CHR(9)||a.serial#||CHR(9)||a.program||CHR(9)||a.module||CHR(9)||a.action||CHR(9)||a.username||CHR(9)||a.osuser||CHR(9)||ROUND((b.used_ublk*(SELECT value FROM v$parameter WHERE name='db_block_size'))/1024/1024,2)||CHR(9)||c.sql_text FROM v$session a, v$transaction b, v$sqlarea c WHERE a.taddr = b.addr AND c.address(+) = a.sql_address AND c.hash_value(+) = a.sql_hash_value ORDER BY b.used_ublk DESC ) WHERE ROWNUM <= +default.default.hUNDOTSMonitor.MailCondition=70000 +default.default.hUNDOTSMonitor.PageCondition=40000 +default.default.hUNDOTSMonitor.ListTopSessionCount=10 +default.default.hUNDOTSMonitor.IsEnabled=False + +default.default.hWFInBoundMailMonitor.InboxFile=/var/mail/wf$(id|tr '(' ' '|tr ')' ' '|awk '{print $2}'|cut -c3-8) +default.default.hWFInBoundMailMonitor.ProcessedFile=$HOME/mail/PROCESS +default.default.hWFInBoundMailMonitor.DiscardFile=$HOME/mail/DISCARD +default.default.hWFInBoundMailMonitor.MailLimitInMinutes=60 +default.default.hWFInBoundMailMonitor.PageLimitInMinutes=120 +default.default.hWFInBoundMailMonitor.IsEnabled=False + +default.default.hDBObjectMonitor.SQL1=SELECT owner||CHR(9)||object_type||CHR(9)||object_name||CHR(9)||TO_CHAR(created,'DD-MON-RRRR HH24:MI:SS')||CHR(9)||TO_CHAR(last_ddl_time,'DD-MON-RRRR HH24:MI:SS') FROM dba_objects WHERE TRUNC(created) > TRUNC(SYSDATE)-8 AND ( owner||'.'||object_name NOT LIKE 'APPS.EUL4%' AND owner||'.'||object_name NOT LIKE 'APPLSYS.WF%' AND owner||'.'||object_name NOT LIKE 'SYS.WRH$%' AND owner||'.'||object_name NOT LIKE 'EUL5_US.EUL%' AND owner||'.'||object_name NOT LIKE 'APPS.EUL%') ORDER BY created DESC +default.default.hDBObjectMonitor.MailSubject=$ORACLE_SID$TWO_TASK:$H_SCRIPTSECTION:$H_HOSTNAME:$(date +'%d-%b-%Y') ****New Objects**** +default.default.hDBObjectMonitor.IsEnabled=True + +default.default.hURLMonitor.URLList=$H_SCRIPT_TOP/../conf/$ORACLE_SID$TWO_TASK.URLList.ini +default.default.hURLMonitor.IsEnabled=False + +## @@@<scriptsection> inherits the values from that section +default.default.hColdBackup.SQL1=SELECT open_mode FROM v\$database +default.default.hColdBackup.CreateSnapshotCommand=@@@hHotBackup +default.default.hColdBackup.RenameSnapshotCommand=@@@hHotBackup +default.default.hColdBackup.DeleteSnapshotCommand=@@@hHotBackup +default.default.hColdBackup.ListSnapshotCommand=@@@hHotBackup +default.default.hColdBackup.RetryAttempt=@@@hHotBackup +default.default.hColdBackup.RetryDelayInSeconds=@@@hHotBackup +default.default.hColdBackup.Volumes=@@@hHotBackup +default.default.hColdBackup.RedoVolumes=@@@hHotBackup +default.default.hColdBackup.ArchVolumes=@@@hHotBackup +default.default.hColdBackup.CLONEPreparationVolume=@@@hHotBackup +default.default.hColdBackup.Force=True +default.default.hColdBackup.IsEnabled=False + +default.default.hProfileOptionMonitor.SQL1=$H_SCRIPT_TOP/../sql/hProfileOptions.generic.sql +default.default.hProfileOptionMonitor.DataFile=$H_SCRIPT_TOP/../logs/$H_SCRIPTSECTION.dat +default.default.hProfileOptionMonitor.SendEMail=False +default.default.hProfileOptionMonitor.IsEnabled=False +default.default.hProfileOptionMonitor.MailSubject=$H_SCRIPTSECTION:$H_HOSTNAME:Profile Option Monitor + +default.default.hResponsibilityMonitor.SQL1=$H_SCRIPT_TOP/../sql/hAdminResponsibility.generic.sql +default.default.hResponsibilityMonitor.DataFile=$H_SCRIPT_TOP/../logs/$H_SCRIPTSECTION.dat +default.default.hResponsibilityMonitor.ExceptionFile=$H_SCRIPT_TOP/../conf/$ORACLE_SID$TWO_TASK.ResponsibilityMonitor.config.ini +default.default.hResponsibilityMonitor.SendEMail=False +default.default.hResponsibilityMonitor.IsEnabled=False +default.default.hResponsibilityMonitor.MailSubject=$H_SCRIPTSECTION:$H_HOSTNAME:Responsibility Monitor + +default.default.hAuditAppsUsers.IsEnabled=True +default.default.hAuditAppsUsers.SQL1=SELECT A.USER_NAME||CHR(9)||B.RESPONSIBILITY_NAME||CHR(9)||C.USER_FORM_NAME||CHR(9)||TO_CHAR(K.START_TIME, 'DD-MON-RR HH24:MI:SS')||CHR(9)||TO_CHAR(K.END_TIME, 'DD-MON-RR HH24:MI:SS') FROM APPS.FND_LOGINS U, APPS.FND_LOGIN_RESPONSIBILITIES R,APPS.FND_USER A, APPS.FND_RESPONSIBILITY_VL B, APPS.FND_FORM_VL C, APPS.FND_LOGIN_RESP_FORMS K WHERE (U.USER_ID = A.USER_ID) AND (R.RESPONSIBILITY_ID = B.RESPONSIBILITY_ID) AND (U.LOGIN_ID = R.LOGIN_ID) AND (R.RESP_APPL_ID = B.APPLICATION_ID) AND (R.LOGIN_ID = K.LOGIN_ID) AND (R.LOGIN_RESP_ID = K.LOGIN_RESP_ID) AND (K.FORM_APPL_ID = C.APPLICATION_ID) AND (K.FORM_ID = C.FORM_ID) AND K.START_TIME >= SYSDATE-1 order by K.START_TIME DESC + +default.default.hAuditDbLogins.IsEnabled=True +default.default.hAuditDbLogins.SQL1=SELECT USERID||CHR(9)||USERHOST||CHR(9)||TERMINAL||CHR(9)||SPARE1||CHR(9)||TO_CHAR(new_time(ntimestamp#,'GMT','PDT'), 'DD-MON-RRRR HH24:MI:SS') FROM sys.aud$ where userid not in ('DBSNMP','APPLSYSPUB') and userhost not in ( SELECT host FROM apps.fnd_nodes WHERE host is not null) AND ntimestamp# >= sysdate -1 ORDER BY ntimestamp# desc diff --git a/sql/hAdminResponsibility.generic.sql b/sql/hAdminResponsibility.generic.sql new file mode 100644 index 0000000..37aac42 --- /dev/null +++ b/sql/hAdminResponsibility.generic.sql @@ -0,0 +1,25 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SELECT + (SELECT instance_name FROM v$instance)||CHR(9)|| + frt.responsibility_name||CHR(9)|| + fu.user_name||CHR(9)|| + TO_CHAR(furg.start_date,'DD-MON-RRRR HH24:MI:SS')||CHR(9)|| + TO_CHAR(furg.end_date,'DD-MON-RRRR HH24:MI:SS') +FROM + apps.fnd_user_resp_groups_direct furg, + apps.fnd_responsibility fr, + apps.fnd_responsibility_tl frt, + apps.fnd_user fu +WHERE fu.user_id = furg.user_id +AND furg.responsibility_id = fr.responsibility_id +AND frt.responsibility_id = fr.responsibility_id +AND furg.end_date IS NULL +AND fu.end_date IS NULL +AND frt.responsibility_name IN (&1) +ORDER BY + 1 +; diff --git a/sql/hBeginBackup.10g.sql b/sql/hBeginBackup.10g.sql new file mode 100644 index 0000000..a3c6d24 --- /dev/null +++ b/sql/hBeginBackup.10g.sql @@ -0,0 +1,9 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SELECT name FROM v$database; +SELECT sequence# FROM v$log WHERE status='CURRENT'; +ALTER DATABASE BEGIN BACKUP; +exit; diff --git a/sql/hBeginBackup.9i.sql b/sql/hBeginBackup.9i.sql new file mode 100644 index 0000000..cd85b66 --- /dev/null +++ b/sql/hBeginBackup.9i.sql @@ -0,0 +1,17 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SET FEEDBACK off +SET PAGESIZE 0 + +SELECT name FROM v$database; +SELECT sequence# FROM v$log WHERE status='CURRENT'; + +SPOOL $hLogDirectory/begin.sql +SELECT 'ALTER TABLESPACE ' ||tablespace_name ||' BEGIN BACKUP;' FROM dba_tablespaces WHERE tablespace_name NOT IN ('TEMP'); +SPOOL OFF +@$hLogDirectory/begin +!rm $hLogDirectory/begin.sql +EXIT; diff --git a/sql/hCMStatus.generic.sql b/sql/hCMStatus.generic.sql new file mode 100644 index 0000000..f40152a --- /dev/null +++ b/sql/hCMStatus.generic.sql @@ -0,0 +1,43 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM # Updatid: 05-AUG-2010 [Method 2, WHERE CLAUSE to use session_id, instead of OS_PROCESS_ID +REM ############################################################### + +SET SERVEROUTPUT ON SIZE 20000 +REM ============================================================ +REM ALTER SESSION ensures that FND_CONCURRENT call does not fail +REM ============================================================ + +ALTER SESSION SET CURRENT_SCHEMA=APPS; + +DECLARE + hTarget NUMBER; + hActive NUMBER; + hPMON VARCHAR2(100); + hStat NUMBER; + hMessage1 VARCHAR2(100); + hMessage2 VARCHAR2(100); +BEGIN + + -- Method 1 + APPS.FND_CONCURRENT.Get_Manager_Status(targetp => hTarget,activep => hActive,pmon_method => hPMON,callstat => hStat); + IF (hStat = 0 AND hActive > 0) THEN + hMessage1:='RUNNING'; + ELSE + hMessage1:='DOWN'; + END IF; + + -- Method 2 + SELECT DECODE(COUNT(DISTINCT 1),1,'RUNNING','DOWN') + INTO hMessage2 + FROM apps.fnd_concurrent_processes a, + v$session b + WHERE a.concurrent_queue_id=1 + AND a.session_id=b.audsid; + + DBMS_OUTPUT.PUT_LINE(hMessage1||' '||hMessage2); + +END; +/ diff --git a/sql/hEndBackup.10g.sql b/sql/hEndBackup.10g.sql new file mode 100644 index 0000000..e717c3e --- /dev/null +++ b/sql/hEndBackup.10g.sql @@ -0,0 +1,12 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +ALTER DATABASE END BACKUP; +ALTER SYSTEM SWITCH LOGFILE; +ALTER SYSTEM SWITCH LOGFILE; +ARCHIVE LOG ALL +SELECT sequence# FROM v$log WHERE status='CURRENT'; +ALTER DATABASE BACKUP CONTROLFILE TO TRACE; +exit; diff --git a/sql/hEndBackup.9i.sql b/sql/hEndBackup.9i.sql new file mode 100644 index 0000000..dc01eb1 --- /dev/null +++ b/sql/hEndBackup.9i.sql @@ -0,0 +1,23 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### + +SET FEEDBACK off +SET PAGESIZE 0 + +SELECT name FROM v$database; +SELECT sequence# FROM v$log WHERE status='CURRENT'; + +SPOOL $hLogDirectory/end.sql +SELECT 'ALTER TABLESPACE ' ||tablespace_name ||' END BACKUP;' FROM dba_tablespaces WHERE tablespace_name NOT IN ('TEMP'); +SPOOL OFF +@$hLogDirectory/end + +ALTER SYSTEM SWITCH LOGFILE; +ARCHIVE LOG ALL +SELECT sequence# FROM v$log WHERE status='CURRENT'; +ALTER DATABASE BACKUP CONTROLFILE TO TRACE; +!rm $hLogDirectory/end.sql +EXIT; diff --git a/sql/hProfileOptions.generic.sql b/sql/hProfileOptions.generic.sql new file mode 100644 index 0000000..792429e --- /dev/null +++ b/sql/hProfileOptions.generic.sql @@ -0,0 +1,30 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SELECT +(SELECT instance_name FROM v$instance)||CHR(9)|| +e.profile_option_name||CHR(9)|| +DECODE(a.level_id,10001,'Site',10002,'Application',10003,'Resp',10004,'User')||CHR(9)|| +DECODE(a.level_id,10001,'Site',10002,c.application_short_name,10003,b.responsibility_name,10004,d.user_name)||CHR(9)|| +NVL(a.profile_option_value,'Is Null')||CHR(9)|| +TO_CHAR(a.last_update_date,'dd-Mon-yyyy hh24:mi:ss')||CHR(9)|| +f.user_name||'['||a.last_updated_by||']' +FROM +applsys.fnd_profile_option_values a, +applsys.fnd_responsibility_tl b, +applsys.fnd_application c, +applsys.fnd_user d, +applsys.fnd_profile_options e, +applsys.fnd_user f +WHERE +e.profile_option_id = a.profile_option_id +AND a.level_value = b.responsibility_id (+) +AND a.level_value = c.application_id (+) +AND a.level_value = d.user_id (+) +AND a.last_update_date > SYSDATE-7 +AND a.last_updated_by = f.user_id +ORDER BY +a.level_id, +a.last_update_date DESC; diff --git a/sql/hShutdown.10g.sql b/sql/hShutdown.10g.sql new file mode 100644 index 0000000..4029325 --- /dev/null +++ b/sql/hShutdown.10g.sql @@ -0,0 +1,7 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SHUTDOWN IMMEDIATE +exit; diff --git a/sql/hStartup.10g.sql b/sql/hStartup.10g.sql new file mode 100644 index 0000000..4a90c7d --- /dev/null +++ b/sql/hStartup.10g.sql @@ -0,0 +1,7 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +STARTUP +exit; diff --git a/sql/hUNDOTSMonitor.SQL1.10g.sql b/sql/hUNDOTSMonitor.SQL1.10g.sql new file mode 100644 index 0000000..f95e743 --- /dev/null +++ b/sql/hUNDOTSMonitor.SQL1.10g.sql @@ -0,0 +1,36 @@ +REM ############################################################### +REM # Author: Habib Rangoonwala +REM # Created: 16-Mar-2007 +REM # Updated: 05-FEB-2010 +REM ############################################################### +SELECT ts_size_mb||CHR(9)|| +ROUND((undo_block_per_sec*dbblksize/1024),2)||CHR(9)|| +ROUND((undo_block_per_sec*mxqrylen*dbblksize)/1024/1024,2)||CHR(9)|| +mxqrylen||CHR(9)|| +DBMS_UNDO_ADV.RBU_MIGRATION||CHR(9)|| +ROUND((trn_max_used_blk*dbblksize)/1024/1024,2)||CHR(9)|| +ROUND((trn_total_used_blk*dbblksize)/1024/1024,2)||CHR(9)|| +trn_count||CHR(9)|| +undo_retention||CHR(9)|| +tuned_undoretention||CHR(9)|| +min_tuned_undoretention +FROM +( +SELECT (SUM(undoblks))/ SUM ((end_time - begin_time) * 24*60*60) undo_block_per_sec, MAX(maxquerylen) mxqrylen, MIN(tuned_undoretention) min_tuned_undoretention FROM v$undostat +), +( +SELECT NVL(SUM(used_ublk),0) trn_total_used_blk ,NVL(MAX(used_ublk),0) trn_max_used_blk,COUNT(*) trn_count FROM v$transaction +), +( +SELECT value dbblksize from v$parameter where name='db_block_size' +), +( +SELECT ROUND(SUM(bytes)/1024/1024) ts_size_mb FROM dba_data_files WHERE tablespace_name = (SELECT UPPER(value) FROM v$parameter WHERE name='undo_tablespace') +), +( +SELECT tuned_undoretention FROM ( SELECT * FROM v$undostat ORDER BY end_time DESC) WHERE ROWNUM < 2 +), +( +SELECT value undo_retention FROM v$parameter WHERE name='undo_retention' +); +