#!/usr/bin/ksh
# whatsup ()
#------------------------------------------------------------------------------#
#    Module Name:  whatsup                                                     #
#                                                                              #
#    Purpose:      Report on the NCA Environment Oracle Applications 11i:      #
#                     Database, Database-Listener Apps-Listener, ConcManager,  #
#                     FormsWeb-Listener, Forms60-Listener, Reports-Listener,   #
#                     TCF-Listener, Metric-Data-Listener, Metric-Req-Listener, #
#                     and Other Information.                                   #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    10-Oct-2009   T.Robinette   Module design/creation                        #
#                  F.Bender      Module design/creation                        #
#                  A.Estrada     Module design/creation                        #
#                  M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)
                
	clear
	echo
	echo  " #--------------------------------------------------------#"
	echo  " # whatsup:    Oracle Apps Services/Processes (Executing) #"
	echo  " #--------------------------------------------------------#"
	echo

	#------------------------------------------------------------------#
	#  Trap:  Set CNTL-C CNTL-D CNTL-\ Before Password Protection      #
	#------------------------------------------------------------------#
	trap        "stty echo; return"     2
	trap        "stty echo; return"     3
	stty -echo

	read PASSWD?" Please Enter the Oracle [7mAPPS[0m Passwd: " 
            
	stty echo
	echo
	#------------------------------------------------------------------#
	#  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
	#------------------------------------------------------------------#
	trap        2
	trap        3

	clear
	ORANAM=${ORASID}
	ORALST=${ORASID}

#-----------------------------------------------------------------------------#
#-  Initializing                                                             -#
#-----------------------------------------------------------------------------#
echo
echo "                        [7m $HNAME Apps-11i Survey [0m"
echo
echo "            A p p l i c a t i o n   ConcManager     D a t a b a s e"
echo "               S e r v i c e s       Services       S e r v i c e s"
echo "          Frm --  Apache  --  App   App App App   10g 10g"
echo " Apps     F60 Svr Svr Svr JRE DB    DB  Rpt Cnc   DB  Ora  WF-Java WF-Java"
echo " SIDs     Svr iAS PLS 920 Svr Lnr   Lnr Svr Mgr   Lsr DB   Server  AgntLst"
echo " -------- --- --- --- --- --- ---   --- --- ---   --- ---  ------- -------"

#-------------------------------------------------------------------------#
#-  LOOP                                                                 -#
#-------------------------------------------------------------------------#
	for  ORASID  in $(echo $ORALST)
	do
	#---------------------------------------------------------------------#
	#-  Initialize LOOP Variables                                        -#
	#---------------------------------------------------------------------#
	typeset APPSID=$(echo "[7m${ORASID}[0m")
	ORASIDLOWER=$(echo $ORASID |   \
	sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')

	#----------------------------------------------------------------------#
	#  SHELL: Variables                                                    #
	#----------------------------------------------------------------------#

	#---------------------------------------------------------------------#
	#-  Running Processes for FORMWEB Server                             -#
	#---------------------------------------------------------------------#
	FRMIND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep -c f60webmx)
	if  [[ $FRMIND -gt 0 ]]
	then
	#-----------------------------------------------------------------#
	#-  Forms-Server Startup will Show 2-Connections.                -#
	#-----------------------------------------------------------------#
	  typeset -i   FRMCNT=${FRMIND}-2
	  typeset -i   FRMWEB=$FRMCNT
	else
	  typeset -i   FRMWEB=$FRMIND
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for F60SRVVM                                   -#
	#---------------------------------------------------------------------#
	F60IND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep -c f60srvm)
	FRMIND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep -c f60webmx)

	if  [[ $F60IND -gt 0 ]]
	then
	  typeset   F60SVR="Yes"
	else
	  typeset   F60SVR="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Report Server                              -#
	#---------------------------------------------------------------------#
	RPTIND=$(ps -efa | grep -v grep | grep $ORASID | grep -c rwmts60)

	if  [[ $RPTIND -gt 0 ]]
	then
	typeset   RPTSVR="Yes"
	else
	typeset   RPTSVR="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Apache iAS HTTP WebServer                  -#
	#---------------------------------------------------------------------#
	APAIND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep Apache | \
	grep -c http)

	if  [[ $APAIND -gt 0 ]]
	then
	typeset   APAIAS="Yes"
	else
	typeset   APAIAS="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Apache iAS RotateLogs WebServer            -#
	#---------------------------------------------------------------------#
	APAIND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep Apache | \
	grep -c rotatelogs)

	if  [[ $APAIND -gt 0 ]]
	then
	typeset   APAPLS="Yes"
	else
	typeset   APAPLS="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Apache 920 WebServer                       -#
	#---------------------------------------------------------------------#
	APAIND=$(ps -efa | grep -v grep | grep $ORASIDLOWER | grep Apache | \
	grep -c http)

	if  [[ $APAIND -gt 0 ]]
	then
	typeset   APA920="Yes"
	else
	typeset   APA920="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for (JRE) Java Runtime Executables             -#
	#---------------------------------------------------------------------#
	JREIND=$(ps -efa | grep jre | grep -v grep | grep -ic $ORASID)

	if  [[ $JREIND -gt 0 ]]
	then
	typeset   JRESVR="Yes"
	else
	typeset   JRESVR="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Database LSNRCTL (Listener)                -#
	#---------------------------------------------------------------------#
	LSNIND=$(ps -efa | grep -i "tnslsnr $ORASIDLOWER" | grep -v grep    \
	| grep -c $ORASIDLOWER)
	if  [[ $LSNIND -gt 0 ]]
	then
	typeset   LSNDBA="Yes"
	else
	typeset   LSNDBA="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Apps LSNRCTL (Listener)                    -#
	#---------------------------------------------------------------------#
	typeset   LSNAPP="No "
	typeset   LSNADB="No "

	LSNIND=$(ps -efa | grep -i "tnslsnr APPS_${ORASID}" | grep -v grep  \
	| grep -c $ORASID)
	if  [[ $LSNIND -gt 0 ]]
	then
	    LSNCNT=$(ps -efa | grep ora_pmon_${ORASID} | grep -v grep    \
	    |  grep -c $ORASID)

	    if  [ $LSNCNT -gt 0 ]
	    #-----------------------------------------------------------------#
	    #-  DBTier                                                       -#
	    #-----------------------------------------------------------------#
	    then
		typeset   LSNADB="Yes"
	    else
	    #-----------------------------------------------------------------#
	    #-  AppsTier                                                     -#
	    #-----------------------------------------------------------------#
		typeset   LSNAPP="Yes"
	    fi
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes for Oracle Instance                            -#
	#---------------------------------------------------------------------#
	ORAIND=$(ps -efa | grep -v grep | grep -c ora_pmon_${ORASID})

	if  [[ $ORAIND -gt 0 ]]
	then
	typeset   ORASVR="Yes"
	else
	typeset   ORASVR="No "
	fi

	#---------------------------------------------------------------------#
	#-  Running Processes: Concurrent Manager                            -#
	#---------------------------------------------------------------------#
        typeset   APPMGR="No "

	for FNDPIDS in $(ps -efa | grep FNDSM | grep -v grep | cut -c10-15)
	do
	  APPIND=$(ps -efa |grep $FNDPIDS | grep -v grep | grep -i -c $ORASID)
	  if  [[ $APPIND -gt 0 ]]
	  then
		typeset   APPMGR="Yes"
	  fi
	done

	sqlplus -s apps/$PASSWD > /dev/null <<-ENDFILE
	set	heading 	off
	set     feedback        off
	set     flush           off
	set     pause           off
	set     space           1
	set     termout         off
	set     verify          off
	set     linesize        80
	set     pagesize        0
	spool /tmp/whatsup.cnt

	SELECT count(*)
	FROM   fnd_concurrent_requests
	WHERE  phase_code = 'R';
	EXIT;
	
	ENDFILE

	if  [[ -f /tmp/whatsup.cnt ]]
	then
	    CNCREQ=$(tail -2 /tmp/whatsup.cnt | head -1)
	    rm /tmp/whatsup.cnt
	fi

	#---------------------------------------------------------------------#
	#-  Processes for Oracle WorkFlow Notification Mail Server/Listener  -#
	#---------------------------------------------------------------------#
	WFMIND=$(ps -efa | grep -v grep | grep GSMSvcComponentContainer | \
	grep -c ${ORASIDLOWER})

	if  [[ $WFMIND -gt 2 ]]
	then
	    typeset   ORAWFM="Running"
	    typeset   ORAWFL="Running"
	else
	    typeset   ORAWFM="Stopped"
	    typeset   ORAWFL="Stopped"
	fi


	sqlplus -s apps/$PASSWD > /dev/null <<-ENDFILE
	set	heading 	off
	set     feedback        off
	set     flush           off
	set     pause           off
	set     space           1
	set     termout         off
	set     verify          off
	set     linesize        80
	set     pagesize        0
	spool /tmp/whatsup.wfm

	SELECT	INITCAP(component_status)
	FROM	fnd_svc_components
	WHERE	component_name = 'Workflow Notification Mailer';
	EXIT;
	
	ENDFILE

	if  [[ -f /tmp/whatsup.wfm ]]
	then
	    ORAWFM=$(tail -2 /tmp/whatsup.wfm | head -1 | cut -c1-7)
	    rm /tmp/whatsup.wfm
	fi

	sqlplus -s apps/$PASSWD > /dev/null <<-ENDFILE
	set	heading 	off
	set     feedback        off
	set     flush           off
	set     pause           off
	set     space           1
	set     termout         off
	set     verify          off
	set     linesize        80
	set     pagesize        0
	spool /tmp/whatsup.wfl

	SELECT INITCAP(component_status)
	FROM   fnd_svc_components
	WHERE  component_name = 'Workflow Inbound Notifications Agent Listener';
	EXIT;
	
	ENDFILE

	if  [[ -f /tmp/whatsup.wfl ]]
	then
	    ORAWFL=$(tail -2 /tmp/whatsup.wfl | head -1 | cut -c1-7)
	    rm /tmp/whatsup.wfl
	fi

	#---------------------------------------------------------------------#
	#-  Processes for Apache Connections                                 -#
	#---------------------------------------------------------------------#
	APADIR=$IAS_ORACLE_HOME/Apache/Apache/logs/access_log
	if  [[ -f ${APADIR}* ]]
	then
	    APALOG=$(ls -t $APADIR.*  | head -1)
	    APADTE=$(date '+%d/%b/%C%y')
	    APAWEB=$(grep '$APADTE' $APALOG | grep -c AppsLocalLogin.jsp)
	fi

    #-------------------------------------------------------------------------#
    #-  Print Detail Line                                                    -#
    #-------------------------------------------------------------------------#
    echo \
" $APPSID     $F60SVR $APAIAS $APAPLS $APA920 $JRESVR $LSNAPP   $LSNADB $RPTSVR $APPMGR   $LSNDBA $ORASVR  $ORAWFM $ORAWFL "


    echo 
    echo 
    echo "             Current Activity"
    echo "             ------------------------------"
    echo "             Forms-Connections:           $FRMWEB"
    echo "             ConcReqs Running:   $CNCREQ"
    echo 
    echo "             Daily Activity"
    echo "             ------------------------------"
    echo "             Web-AppsLocalLogin Today:    $APAWEB"
    echo 
    done

    #-------------------------------------------------------------------------#
    #-  Print Blank Line                                                     -#
    #-------------------------------------------------------------------------#
    echo
}
