#!/usr/bin/ksh
# whatsup ()
#------------------------------------------------------------------------------#
#    Module Name:  whatsup                                                     #
#                                                                              #
#    Purpose:      Report on the NCA Environment Oracle Applications 12:       #
#                     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 APPS 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 "                         $HNAME Apps-12.1 Survey "
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 "          -OC4J/J2EE-   -Apache-    App App     10g 10g"
echo " Apps     OA  OA  OA    App App     DB  Cnc     DB  Ora  WF-Java WF-Java"
echo " SIDs     FM  FRM Core  Log Lnr     Lnr Mgr     Lsr DB   Server  AgntLst"
echo " -------- --- --- ---   --- ---     --- ---     --- ---  ------- -------"

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

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

        #---------------------------------------------------------------------#
        #-  Running Processes for Oracle 10.1.2 Forms-Server                 -#
        #---------------------------------------------------------------------#
        FRMIND=$(ps -efa | grep -v grep | grep $ORASID | grep -c forms)
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset -i   FRMCNT=${FRMIND}
          typeset -i   FRMWEB=$FRMCNT
          typeset      FRMSVR="Yes"
        else
          typeset -i   FRMWEB=$FRMIND
          typeset      FRMSVR="No "
        fi

        #---------------------------------------------------------------------#
        #-  Running Processes for OPMN OACore (Framework)                    -#
        #---------------------------------------------------------------------#
        APAOAC=$(ps -efa | grep -v grep | grep $ORASID | grep Apache | \
        grep -c httpd)

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

        #---------------------------------------------------------------------#
        #-  Running Processes for Apache OPMN WebServer                      -#
        #---------------------------------------------------------------------#
        APAIND=$(ps -efa | grep -v grep | grep $ORASID | grep -c opmn)

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

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

        if  [[ $APAIND -gt 0 ]]
        then
        typeset   APALOG="Yes"
        else
        typeset   APALOG="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 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 Database LSNRCTL (Listener)                -#
        #---------------------------------------------------------------------#
        LSNIND=$(ps -efa | grep -i "tnslsnr $ORASIDLOWER" | grep -v grep    \
        | grep $ORASID | grep -c 11.1.0)
        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 APPS_${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"
                typeset   LSNAPP="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_CR
        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_CR

        if  [[ -f /tmp/whatsupCR.cnt ]]
        then
            CNCREQ=$(tail -2 /tmp/whatsupCR.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_WF
        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_WF

        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_WN
        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_WN

        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=$LOG_HOME/ora/10.1.3/Apache/access_log
        if  [ -f ${APADIR}* ]
        then
            APAACC=$(ls -t $APADIR.*  | head -1)
            APADTE=$(date '+%d/%b/%C%y')
            APAWEB=$(grep $APADTE $APAACC | grep -c 'GET /OA_HTML/RF.jsp')
        fi

    #-------------------------------------------------------------------------#
    #-  Print Detail Line                                                    -#
    #-------------------------------------------------------------------------#
    echo \
" $APPSID     $FRMSVR $APAIAS $APAOPM   $APALOG $LSNAPP     $LSNADB $APPMGR     $LSNDBA $ORASVR  $ORAWFM $ORAWFL "


    echo 
    echo 
    echo "             Concurrent Request Activity"
    echo "             ------------------------------"
    echo "             ConcReqs Running:   $CNCREQ"
    echo 
    echo "             Daily Activity"
    echo "             ------------------------------"
    echo "             Web-AppsLocalLogin Today:    $APAWEB"
    echo 
    done

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