Way to success...

--"Running Away From Any PROBLEM Only Increases The DISTANCE From The SOLUTION"--.....--"Your Thoughts Create Your FUTURE"--.....--"EXCELLENCE is not ACT but a HABIT"--.....--"EXPECT nothing and APPRECIATE everything"--.....

Sunday, May 15, 2016

SOX Audit Report : Applied Patches (adpatch) History in Oracle EBS 11i and R12

Applied Patches (adpatch) History Report in Oracle EBS 11i and R12 for SOX Audit

You may want to be able to audit recently applied patches (adpatch) history report in Oracle EBS 11i/R12.

If you want to query information about patches applied history report:

Query for EBS R12:



select distinct aap.patch_name,  apr.patch_top,  aat.name,  aap.patch_type,                        
       aap.creation_date,  fav.APPLICATION_NAME, apd.patch_abstract
from apps.ad_patch_runs apr,
     apps.ad_patch_drivers apd,
     apps.ad_applied_patches aap,
     apps.ad_patch_run_bugs aprb,
     apps.ad_appl_tops aat,
     apps.fnd_application_vl fav
where apr.appl_top_id = aat.appl_top_id
  and apr.patch_driver_id = apd.patch_driver_id
  and apr.patch_run_id = aprb.patch_run_id
  and apd.applied_patch_id = aap.applied_patch_id
  and UPPER(aprb.application_short_name) =fav.application_short_name
  and aprb.applied_flag = 'Y'
and aap.creation_date >= to_date('01-APR-2016','DD-MM-YYYY')
and aap.creation_date <= to_date('30-APR-2016','DD-MM-YYYY')
order by aap.creation_date;



Query for EBS 11i:



select distinct aap.patch_name,  apr.patch_top,  aat.name,  aap.patch_type,                        
       aap.creation_date,  fav.APPLICATION_NAME
from apps.ad_patch_runs apr,
     apps.ad_patch_drivers apd,
     apps.ad_applied_patches aap,
     apps.ad_patch_run_bugs aprb,
     apps.ad_appl_tops aat,
     apps.fnd_application_vl fav
where apr.appl_top_id = aat.appl_top_id
  and apr.patch_driver_id = apd.patch_driver_id
  and apr.patch_run_id = aprb.patch_run_id
  and apd.applied_patch_id = aap.applied_patch_id
  and UPPER(aprb.application_short_name) =fav.application_short_name
  and aprb.applied_flag = 'Y'
and aap.creation_date >= to_date('01-APR-2016','DD-MM-YYYY')
and aap.creation_date <= to_date('30-APR-2016','DD-MM-YYYY')
order by aap.creation_date;


This will give the output with patch details which have been applied during the period of 01-APR-2016 to 30-APR-2016


Friday, May 13, 2016

SOX Audit Report : Oracle Discoverer Reports access/execution History With User Details


Oracle Discoverer Reports Access/Execution History for SOX Audit

You may want to be able to audit user's access information to run Discoverer worksheets to a specific workbook.

If you want to query information about users who have executed a specific report:

Query:


SELECT   qs_doc_name AS "Workbook Name", qs_doc_details AS "Worksheet Name"
        ,CASE
           WHEN INSTR (qs_created_by, '#') = 0
             THEN qs_created_by
           WHEN INSTR (qs_created_by, '#') > 0 AND INSTR (qs_created_by, '#', 2) = 0
             THEN (SELECT fu.user_name
                     FROM fnd_user fu
                    WHERE fu.user_id = SUBSTR (qs_created_by, 2, 9))
           ELSE NULL
         END "Worksheet Run By"
        ,qs_created_date "Run Date"
    FROM EUL_OWNER.eul5_qpp_stats
   WHERE LOWER (qs_doc_name) LIKE LOWER ('%oracle%') --Enter Workbook Name Here
     AND qs_created_date >= TO_DATE ('01-APR-2016 00:00:00', 'DD-MON-YYYY HH24:MI:SS')
     AND qs_created_date <= TO_DATE ('30-APR-2016 23:59:59', 'DD-MON-YYYY HH24:MI:SS')
   --AND qs_created_date >= (SYSDATE - 10)
ORDER BY qs_created_date DESC;

Note : Replace EUL_OWNER with corresponding EUL owner of your environment in above query.

This query will give the output with users details who have executed a specific report from 01-APR-2016 to 30-APR-2016.


Thursday, May 12, 2016

SOX Audit Report : Oracle Discoverer Reports Change History With User Details


Oracle Discoverer Reports Change History for SOX Audit

You may want to be able to audit log which user has made changes to a specific workbook.

If you want to query information about user that has made the last update/change to a workbook:

Query:


SELECT DISTINCT disco_docs.doc_name "Discoverer Workbook",
                CASE
                   WHEN INSTR
                          (disco_docs.doc_created_by,
                           '#'
                          ) = 0
                      THEN disco_docs.doc_created_by
                   WHEN INSTR (disco_docs.doc_created_by, '#') > 0
                   AND INSTR (disco_docs.doc_created_by, '#', 2) = 0
                      THEN (SELECT fu.user_name
                              FROM fnd_user fu
                             WHERE fu.user_id =
                                      SUBSTR (disco_docs.doc_created_by, 2, 9))
                   ELSE NULL
                END "Workbook Owner/Creator",
                disco_docs.doc_created_by,
                disco_docs.doc_created_date "Creation Date/Time",
                CASE
                   WHEN INSTR
                          (disco_docs.doc_updated_by,
                           '#'
                          ) = 0
                      THEN disco_docs.doc_updated_by
                   WHEN INSTR (disco_docs.doc_updated_by, '#') > 0
                   AND INSTR (disco_docs.doc_updated_by, '#', 2) = 0
                      THEN (SELECT fu.user_name
                              FROM fnd_user fu
                             WHERE fu.user_id =
                                      SUBSTR (disco_docs.doc_updated_by, 2, 9))
                   ELSE NULL
                END "Workbook Updated by",
                disco_docs.doc_updated_by,
                disco_docs.doc_updated_date "Update Date/Time"
           FROM EUL_OWNER.eul5_documents disco_docs,
                EUL_OWNER.eul5_eul_users disco_users
            WHERE disco_users.eu_username(+) NOT IN ('EUL5', 'PUBLIC')
              AND disco_docs.doc_updated_date >= TO_DATE ('01-APR-2016 00:00:00', 'DD-MON-YYYY HH24:MI:SS')
              AND disco_docs.doc_updated_date <= TO_DATE ('30-APR-2016 23:59:59', 'DD-MON-YYYY HH24:MI:SS')
            --AND disco_docs.doc_updated_date >= (SYSDATE - 10)
            --AND disco_docs.doc_name LIKE '%Oracle%'
            ORDER BY doc_updated_date DESC;

Note : Replace EUL_OWNER with corresponding EUL owner of your environment in above query.

This query will give the output for the oracle discoverer report changes history from 01-APR-2016 to 30-APR-2016.



Wednesday, May 11, 2016

Script To Monitor "Gather Schema Statistics" concurrent request


Pre-requisites to Run the script:

Make sure mailx and sendmail is installed on your OS, also check below environements/file is created prior to execute the scripts.

This script is tested on Linux Server.

This script needs to be deployed in database node/server.

#Base location for the DBA scripts
DBA_SCRIPTS_HOME=$HOME/DBA_MON

#OS User profile where database environment file is set
$HOME/.bash_profile

Create Custom .sysenv file for scripts

Download(.sysenv)

Download .sysenv file and save it under $HOME/DBA_MON
$ chmod 777 .sysenv
$ cat $HOME/DBA_MON/.sysenv

export DBA_SCRIPTS_HOME=$HOME/DBA_MON
export PATH=${PATH}:$DBA_SCRIPTS_HOME
export DBA_EMAIL_LIST=kiran.jadhav@domain.com,jadhav.kiran@domain.com
#Below parameter is used in script, whenever there is planned downtime you can set it to Y so there will be no false alert.
export DOWNTIME_MODE=N


Script MonGSSRequest.sh Script To Monitor "Gather Schema Statistics" concurrent request.



Download(MonGSSRequest.sh)

Download MonGSSRequest.sh and save it under $HOME/DBA_MON/bin/
$ chmod 755 MonGSSRequest.sh

#!/bin/bash

#############################################################################################################
# Script Name : MonGSSRequest.sh                                                                            #
#                                                                                                           #
# Description:                                                                                              #
# Script To Monitor "Gather Schema Statistics" concurrent request.                                          #
# If error-out then send notification to DBA Team                                                           # 
#                                                                                                           #
# Usage : sh <script_name> <ORACLE_SID> <History_No_Days>                                                           #
# For example : sh MonGSSRequest.sh ORCL 7                                                                  #
#                                                                                                           #
# Created by : Kiran Jadhav - (https://h2hdba.blogspot.com)                                                 #
#############################################################################################################

# Initialize variables

INSTANCE=$1
THRESHOLD=$2
HOST_NAME=`hostname | cut -d'.' -f1`
PROGRAM=`basename $0 | cut -d'.' -f1`
export DBA_SCRIPTS_HOME=$HOME/DBA_MON
APPS_ID=`echo $INSTANCE | tr '[:lower:]' '[:upper:]'`
LOG_DIR=$DBA_SCRIPTS_HOME/logs/$HOST_NAME
OUT_FILE=$LOG_DIR/`echo $PROGRAM`_$APPS_ID.html.out
LOG_FILE=$LOG_DIR/`echo $PROGRAM`_$APPS_ID.log
ERR_FILE=$LOG_DIR/`echo $PROGRAM`_$APPS_ID.err
LOG_DATE=`date`


# Source the env
. $HOME/.bash_profile
. $DBA_SCRIPTS_HOME/.sysenv

if [ $? -ne 0 ]; then
   echo "$LOG_DATE" > $LOG_FILE  
   echo "Please pass correct environment : exiting the script  \n" >> $LOG_FILE
   cat $LOG_FILE
   exit
fi

if [ -s $OUT_FILE ]; then
 echo "$LOG_DATE" > $LOG_FILE
 echo "Deleting existing output file $OUT_FILE" >> $LOG_FILE
 rm -f $OUT_FILE
 cat $LOG_FILE
fi

# If there is a plan downtime then create $ORACLE_SID.down file in $DBA_SCRIPTS_HOME to silent the alerts during maintenance window.

if [ -f $DBA_SCRIPTS_HOME/`echo $ORACLE_SID`.down ]; then
 echo "$LOG_DATE" >> $LOG_FILE
        echo "Host: $HOST_NAME | Instance: $ORACLE_SID is under maintenance: exiting the script" >> $LOG_FILE
        cat $LOG_FILE
 exit
fi

if [ $DOWNTIME_MODE = "Y" ]; then
 echo "$LOG_DATE" >> $LOG_FILE
 echo "Host: $HOST_NAME | Instance: $ORACLE_SID is under maintenance: exiting the script" >> $LOG_FILE
 cat $LOG_FILE
 exit
fi

usage()
{
  echo "$LOG_DATE" > $LOG_FILE
        echo "Script to monitor Gather Schema Statistics Conc. request"  >> $LOG_FILE
        echo "Usage   : sh <script_name> <ORACLE_SID> <no_days> " >> $LOG_FILE
  echo "For example : sh $PROGRAM.sh $ORACLE_SID 7" >> $LOG_FILE
        echo
}

if [ $# -lt 2 ] || [ "$INSTANCE" != "$ORACLE_SID" ]; then
    usage
    echo "Error : Insufficient arguments." >> $LOG_FILE
 cat $LOG_FILE
    exit
fi

get_err_count()
{
 sqlplus -s '/as sysdba' <<!
 set heading off
 set feedback off
 select count(*) from
  (
  SELECT a.request_id "Req Id"
      ,substr(u.user_name,1,25) "Submitted by"
      ,decode(a.PHASE_CODE,'C','Completed','I','Inactive','P','Pending','R','Running','NA') "Phasecode",
      decode(a.STATUS_CODE, 'A','Waiting', 'B','Resuming', 'C','Normal', 'D','Cancelled', 'E','Error', 'F','Scheduled', 'G','Warning', 'H','On Hold', 'I','Normal', 'M',
      'No Manager', 'Q','Standby', 'R','Normal', 'S','Suspended', 'T','Terminating', 'U','Disabled', 'W','Paused', 'X','Terminated', 'Z','Waiting') "Status"
      , a.argument_text " Arguments "
      , TO_CHAR(actual_start_date, 'DD-MON-YYYY HH24:MI:SS') "Start Date"
      , TO_CHAR(actual_completion_date, 'DD-MON-YYYY HH24:MI:SS') "Completion Date"
      , ctl.user_concurrent_program_name "Conc Program Name",a.COMPLETION_TEXT "Error/Warning"
      FROM APPLSYS.fnd_Concurrent_requests a,APPLSYS.fnd_concurrent_processes b
      ,applsys.fnd_concurrent_queues q
      ,APPLSYS.fnd_concurrent_programs c
      ,APPLSYS.fnd_concurrent_programs_tl ctl
      ,APPLSYS.fnd_user u
      WHERE a.controlling_manager = b.concurrent_process_id
      AND a.concurrent_program_id = c.concurrent_program_id
      AND a.program_application_id = c.application_id
      AND a.status_code in ('D','E','G','H','M','S','T','U','X','W')  -- for the status ERROR
      AND a.phase_code = 'C' -- Phase code COMPLETED
      AND actual_start_date >= sysdate - $THRESHOLD
      AND b.queue_application_id = q.application_id
      AND b.concurrent_queue_id = q.concurrent_queue_id
      AND ctl.concurrent_program_id = c.concurrent_program_id
      AND ctl.LANGUAGE = 'US'
      AND a.REQUESTED_BY=u.user_id
      AND ctl.user_concurrent_program_name = 'Gather Schema Statistics'
  );
 
 exit;
!
}

err_count=`get_err_count`
#echo $err_count

echo "$LOG_DATE" > $ERR_FILE
get_err_count >> $ERR_FILE
ERR_FILE_COUNT=`grep "ORA-" $ERR_FILE |wc -l`

if [ $ERR_FILE_COUNT -gt 0 ]; then
 cat $ERR_FILE | mailx -s "<ERROR> Alert: $APPS_ID - Gather Schema Statistics Request not completed normal on $HOST_NAME " $DBA_EMAIL_LIST
 exit
fi

if [ $err_count -gt 0 ];
then

 sqlplus -s '/as sysdba' <<EOF

 SET ECHO OFF
 SET pagesize 1000
 set feedback off
 set lines 180
 SET MARKUP HTML ON SPOOL ON -
 HEAD '<title></title> -
 <style type="text/css"> -
    table { background: #eee; } -
    th { font:bold 10pt Arial,Helvetica,sans-serif; color:#b7ceec; background:#151b54; padding: 5px; align:center; } -
    td { font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding: 5px; align:center; } -
 </style>' TABLE "border='1' align='left'" ENTMAP OFF

 spool $OUT_FILE


 PROMPT Hi Team,

 PROMPT
 PROMPT Gather Schema Statistics request not completed normal, take necessary action ASAP.
 PROMPT


 SELECT a.request_id "Req Id"
    ,substr(u.user_name,1,25) "Submitted by"
    ,decode(a.PHASE_CODE,'C','Completed','I','Inactive','P','Pending','R','Running','NA') "Phasecode",
    decode(a.STATUS_CODE, 'A','Waiting', 'B','Resuming', 'C','Normal', 'D','Cancelled', 'E','Error', 'F','Scheduled', 'G','Warning', 'H','On Hold', 'I','Normal', 'M',
    'No Manager', 'Q','Standby', 'R','Normal', 'S','Suspended', 'T','Terminating', 'U','Disabled', 'W','Paused', 'X','Terminated', 'Z','Waiting') "Status"
    , a.argument_text " Arguments "
    , TO_CHAR(actual_start_date, 'DD-MON-YYYY HH24:MI:SS') "Start Date"
    , TO_CHAR(actual_completion_date, 'DD-MON-YYYY HH24:MI:SS') "Completion Date"
    , ctl.user_concurrent_program_name "Conc Program Name",a.COMPLETION_TEXT "Error/Warning"
    FROM APPLSYS.fnd_Concurrent_requests a,APPLSYS.fnd_concurrent_processes b
    ,applsys.fnd_concurrent_queues q
    ,APPLSYS.fnd_concurrent_programs c
    ,APPLSYS.fnd_concurrent_programs_tl ctl
    ,APPLSYS.fnd_user u
    WHERE a.controlling_manager = b.concurrent_process_id
    AND a.concurrent_program_id = c.concurrent_program_id
    AND a.program_application_id = c.application_id
    AND a.status_code in ('D','E','G','H','M','S','T','U','X','W')  -- for the status ERROR
    AND a.phase_code = 'C' -- Phase code COMPLETED
    AND actual_start_date >= sysdate - $THRESHOLD
    AND b.queue_application_id = q.application_id
    AND b.concurrent_queue_id = q.concurrent_queue_id
    AND ctl.concurrent_program_id = c.concurrent_program_id
    AND ctl.LANGUAGE = 'US'
    AND a.REQUESTED_BY=u.user_id
    AND ctl.user_concurrent_program_name = 'Gather Schema Statistics';

    SPOOL OFF
 SET MARKUP HTML OFF
 exit;

EOF

(
echo "To: $DBA_EMAIL_LIST"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/alternative; "
echo ' boundary="PAA08673.1018277622/server.xyz.com"'
echo "Subject: Alert: $APPS_ID - Gather Schema Statistics Request not completed normal on $HOST_NAME"
echo ""
echo "This is a MIME-encapsulated message"
echo ""
echo "--PAA08673.1018277622/server.xyz.com"
echo "Content-Type: text/html"
echo ""
cat $OUT_FILE
echo "--PAA08673.1018277622/server.xyz.com"
) | /usr/sbin/sendmail -t

echo "`date`" > $LOG_FILE
echo "Details sent through an email" >> $LOG_FILE
cat $LOG_FILE

else 
    echo "`date`" > $OUT_FILE
 echo "Gather Schema Statistics Request completed normal in last $THRESHOLD Days" >> $OUT_FILE
fi


Logs and Out files will be generated under $DBA_SCRIPTS_HOME/logs/$HOST_NAME
So make sure to create logs/$HOST_NAME directory under $DBA_SCRIPTS_HOME before executing 
the script.

Once the script is ready, then as per the requirement please schedule it in crontab/OEM.

Execute the Script as below:

Syntax :  sh <script_name> <ORACLE_SID> <History_No_Days>

$ cd $HOME/DBA_MON/bin
$ sh MonGSSRequest.sh ORCL 7
This script will send the notification with details if Gather Schema Statistics request is error out in Last 7 days.