#!/bin/ksh
# whatsup_eMail_RFPROD ()
## set -xv
#------------------------------------------------------------------------------#
#    Module Name:  whatsup_eMail_RFPROD                                        #
#                                                                              #
#    Purpose:      Report on the Oracle E-Business Applications 12.2:          #
#                     Database, Database-Listener Apps-Listener, ConcManager,  #
#                     OAFramework, OACore, FormsContainer4WebLogic, Forms      #
#                     and Other Information.                                   #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    27-Jul-2021                 Module design/creation                        #
#                                Module design/creation                        #
#                  M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        ORASRV=$(echo $CONTEXT_NAME | cut -f3 -d'_')
        HNAME=$(hostname -s)
 
        clear
        echo
        echo  " #--------------------------------------------------------#"
        echo  " # whatsup_eMail_RFPROD: Oracle Apps Services (Executing) #"
        echo  " #--------------------------------------------------------#"
        echo
 
        #---------------------------------------------------------------#
        #  TEST:  Number ($#) of arguments passed to this function?     #
        #---------------------------------------------------------------#
        if      [ $# = 0 ]
        then
            clear
            echo
            echo  " #---------------------------------------------------#"
            echo  " # whatsup_eMail_RFPROD:        What Services are UP #"
            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        "stty echo; return"     2
            trap        "stty echo; return"     3
            stty -echo
            read PASSWL?" Please Enter the Oracle WebLogic Server Passwd: "
            stty echo
            echo
 
            clear
        else
            PASSWD=$1
            PASSWL=$2
            clear
        fi
 
        #------------------------------------------------------------------#
        #  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
        #------------------------------------------------------------------#
        trap        2
        trap        3
 
        clear
        ORANAM=${ORASID}
        ORALST=${ORASID}
 
#-----------------------------------------------------------------------------#
#-  Initializing                                                             -#
#-----------------------------------------------------------------------------#
 
#-------------------------------------------------------------------------#
#-  LOOP                                                                 -#
#-------------------------------------------------------------------------#
        for  ORASID  in $(echo $ORALST)
        do
       date
        #---------------------------------------------------------------------#
        #-  Initialize LOOP Variables                                        -#
        #---------------------------------------------------------------------#
        typeset APPSID=$(echo "${ORASID}")
        ORASIDLOWER=$(echo $ORASID |   \
        sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
 
        #----------------------------------------------------------------------#
        #  SHELL: Variables                                                    #
        #----------------------------------------------------------------------#
 
        #----------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running OAFM/OACORE/Forms/Forms-C4WS           -#
        #----------------------------------------------------------------------#
        #- ./admanagedsrvctl.sh status oafm_server1        OAFM Server Status -#
        #- ./admanagedsrvctl.sh status oacore_server1    OACORE Server Status -#
        #- ./admanagedsrvctl.sh status forms-c4ws_server1 FORMS C4WS Status   -#
        #- ./admanagedsrvctl.sh status forms_server1      FORMS Server Status -#
        #----------------------------------------------------------------------#
 
        #----------------------------------------------------------------------#
        #- AppsTier1                                                          -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  oafm_server1 2>/dev/null |  \
                grep -c 'oafm_server1 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      OAFSV1="Running"
        else
          typeset      OAFSV1="Down"
        fi
 
        #----------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for OACore                   -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  oacore_server1 2>/dev/null |  \
                grep -c 'oacore_server1 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      OACSV1="Running"
        else
          typeset      OACSV1="Down"
        fi
        #---------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for FORMS Container for WLS -#
        #---------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  forms-c4ws_server1 2>/dev/null |  \
                grep -c 'forms-c4ws_server1 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      FRMWL1="Running"
        else
          typeset      FRMWL1="Running"
        fi
 
        #----------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for FORMS Server             -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  forms_server1 2>/dev/null |  \
                grep -c 'forms_server1 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      FRMSV1="Running"
        else
          typeset      FRMSV1="Down"
        fi
 
        #----------------------------------------------------------------------#
        #- AppsTier2                                                          -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  oafm_server2 2>/dev/null |  \
                grep -c 'oafm_server2 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      OAFSV2="Running"
        else
          typeset      OAFSV2="Down"
        fi
 
        #----------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for OACore                   -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  oacore_server2 2>/dev/null |  \
                grep -c 'oacore_server2 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      OACSV2="Running"
        else
          typeset      OACSV2="Down"
        fi
        #---------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for FORMS Container for WLS -#
        #---------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  forms-c4ws_server2 2>/dev/null |  \
                grep -c 'forms-c4ws_server2 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      FRMWL2="Running"
        else
          typeset      FRMWL2="Running"
        fi
 
        #----------------------------------------------------------------------#
        #-  E-Business 12.2 -- Running Processes for FORMS Server             -#
        #----------------------------------------------------------------------#
        FRMIND=$(echo  ${PASSWL} | ${ADMIN_SCRIPTS_HOME}/admanagedsrvctl.sh \
                status  forms_server2 2>/dev/null |  \
                grep -c 'forms_server2 is running')
 
        if  [[ $FRMIND -gt 0 ]]
        then
          typeset      FRMSV2="Running"
        else
          typeset      FRMSV2="Down"
        fi
 
        #---------------------------------------------------------------------#
        #-  Running Processes for Database LSNRCTL (Listener)                -#
        #---------------------------------------------------------------------#
        LSNNAM="tnslsnr $ORASID"
        if  [[ $LSNNAM != '' ]]
        then
            LSNIND=$(ssh oracle@ebspdb10 ps -efa|grep -i "$LSNNAM"|wc -l)
            if  [[ $LSNIND -gt 0 ]]
            then
                typeset   LSNDBA="Up"
            else
                typeset   LSNDBA="Down"
            fi
        else
            typeset   LSNDBA="Down"
        fi
 
        #---------------------------------------------------------------------#
        #-  Running Processes for Apps LSNRCTL (Listener)                    -#
        #---------------------------------------------------------------------#
        typeset   LSNADB="Down"
        typeset   LSNAPP="Down"
 
        LSNIND=$(ps -efa | grep -i "APPS_${ORASID}*" | grep -v grep  \
        | grep -c $ORASID)
        if  [[ $LSNIND -gt 0 ]]
        then
            typeset   LSNADB="Up"
            typeset   LSNAPP="Up"
        fi
 
        #---------------------------------------------------------------------#
        #-  Running Processes for Oracle Instance                            -#
        #---------------------------------------------------------------------#
        ORAIND=$(ssh oracle@ebspdb10 ps -efa|grep -v grep|grep -i ora_pmon_${ORASID}|wc -l)
 
        if  [[ $ORAIND -gt 0 ]]
        then
        typeset   ORASVR="Up"
        else
        typeset   ORASVR="Down"
        fi
 
        #---------------------------------------------------------------------#
        #-  Running Processes: Concurrent Manager                            -#
        #---------------------------------------------------------------------#
        typeset   APPMGR="Down"
 
        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 FNDSM)
          if  [[ $APPIND -gt 0 ]]
          then
                typeset   APPMGR="Running"
          fi
        done
 
        #---------------------------------------------------------------------#
        #-  Check Internal URL                                               -*
        #---------------------------------------------------------------------#
        LOGIN_PAGE="http://ebspap11.rfsuny.org:8000/OA_HTML/AppsLogin"
 
        LPIND=$(wget -S --spider ${LOGIN_PAGE} 2>&1|grep -w "200\|301"|wc -l)
 
        if  [[ $LPIND -gt 0 ]]
        then
        typeset   INTURL="Up"
        else
        typeset   INTURL="Down"
        fi
 
        #---------------------------------------------------------------------#
        #-  Check External URL                                               -*
        #---------------------------------------------------------------------#
        EXT_URL="https://ebs.rfsuny.org"
 
        EXTIND=$(wget -S --spider ${EXT_URL} 2>&1|grep -w "200\|301"|wc -l)
 
        if  [[ $EXTIND -gt 0 ]]
        then
        typeset   EXTURL="Up"
        else
        typeset   EXTURL="Down"
        fi
 
        #---------------------------------------------------------------------#
        #-  Check External URL                                               -*
        #---------------------------------------------------------------------#
        SSV_URL="https://selfserv.rfsuny.org"
 
        SSVIND=$(wget -S --spider ${SSV_URL} 2>&1|grep -w "200\|301"|wc -l)
 
        if  [[ $SSVIND -gt 0 ]]
        then
        typeset   SSVURL="Up"
        else
        typeset   SSVURL="Down"
        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_eMail_RFPROD.wfm
 
        SELECT  INITCAP(component_status)
        FROM    fnd_svc_components
        WHERE   component_name = 'Workflow Notification Mailer';
        EXIT;
 
ENDFILE
 
        if  [[ -f /tmp/whatsup_eMail_RFPROD.wfm ]]
        then
           ORAWFM=$(tail -2 /tmp/whatsup_eMail_RFPROD.wfm | head -1 | cut -c1-7)
           rm /tmp/whatsup_eMail_RFPROD.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_eMail_RFPROD.wfl
 
        SELECT INITCAP(component_status)
        FROM   fnd_svc_components
        WHERE  component_name = 'Workflow Inbound Notifications Agent Listener';
        EXIT;
 
ENDFILE
 
        if  [[ -f /tmp/whatsup_eMail_RFPROD.wfl ]]
        then
           ORAWFL=$(tail -2 /tmp/whatsup_eMail_RFPROD.wfl | head -1 | cut -c1-7)
          rm /tmp/whatsup_eMail_RFPROD.wfl
        fi
 
#-------------------------------------------------------------------------#
#-  Print Header Lines                                                   -#
#-------------------------------------------------------------------------#
echo
echo "-------------------------------------------------------" |  \
tee /tmp/whatsup_eMail_RFPROD_$$.txt
echo "$HNAME Apps-12.2 Survey (${APPSID})" |  \
      tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "-------------------------------------------------------" |  \
tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo
echo "Application Services"     | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "  OA-Framework Services:" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    OAFM Server1               ==> $OAFSV1" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    OACore Server1             ==> $OACSV1" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    Forms Server               ==> $FRMSV1" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "                                          " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    OAFM Server2               ==> $OAFSV2" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    OACore Server2             ==> $OACSV2" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    Forms Server               ==> $FRMSV2" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "                                          " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "  Apache Services:"       | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    Applications Listener      ==> $LSNAPP" | tee -a /tmp/whatsup_eMail_RFPROD__$$.txt
echo " " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "Concurrent Manager Services:" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    Applications DB Listener   ==> $LSNADB" | \
      tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "    Internal ConcurrentManager ==> $APPMGR" | \
      tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo " " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "Database Services:" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    TNS Listener               ==> $LSNDBA" | \
          tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "    Oracle 12c Database        ==> $ORASVR" | \
          tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo " " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "Workflow Services:" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    WF Notification Mailer     ==> $ORAWFM" | \
          tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "    Workflow Agent Listener    ==> $ORAWFL" | \
          tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo " " | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
echo "URL Pages:" | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    Internal Page ==> ${LOGIN_PAGE}"      | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "      Internal Login Page ==> $INTURL"    | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo " "                                        | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    External Page ==> ${EXT_URL}"         | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "      External Page ==> $EXTURL"          | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo " "                                        | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "    SelfSev Page  ==> ${SSV_URL}"         | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "      External Page ==> $SSVURL"          | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo " "                                        | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
echo "-------------------------------------------------------" | \
      tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
    #-------------------------------------------------------------------------#
    #-  Print Detail Line                                                    -#
    #-------------------------------------------------------------------------#
#    echo \
#" $APPSID $OAFSVR $OACSVR $FRMWLS $FRMSVR $LSNAPP    $LSNADB $APPMGR      $LSNDBA $ORASVR  $ORAWFM $ORAWFL "                     | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
    done
 
 
    #-------------------------------------------------------------------------#
    #-  Print Blank Line                                                     -#
    #-------------------------------------------------------------------------#
    echo                                         | tee -a /tmp/whatsup_eMail_RFPROD_$$.txt
 
print
print "Please see /tmp/whatsup_eMail_RFPROD_$$.txt"
print
date
}
