RE: tcl script for listener alert

  • From: Herring Dave - dherri <Dave.Herring@xxxxxxxxxx>
  • To: Oracle-L Freelists <oracle-l@xxxxxxxxxxxxx>
  • Date: Mon, 7 Mar 2005 15:21:27 -0600

FYI, I couldn't find any TCL examples, so I wrote a ksh version to do this.
What I haven't had time to do is add in something for dealing with the
listener being down for an extended time, not sending email every x minutes,
instead once on being down, once on being back up again.

He's the code, in case anyone's interested:

############################################################################
###
#
#  listener_error_check.ksh
#
#  This script will check for any new errors found in the listener's
logfile.
#  As part of this check, it will also validate that the listener is up.
This
#  job is a crutch for OEM until this functionality is available within OEM.
#
#  Arguments
#       -p              Optional argument to signify that the listener is
#                       encrypted password protected.
#       -t <TNS_ADMIN>  This value is required if you are using this
#                       env variable.
#
#  Maintenance  History
#
#  Date         Name/Description
#  ------------
---------------------------------------------------------------
#  03/07/2005   Dave Herring
#               Initial Version.
#
############################################################################
###

. $ORACLE_BASE/admin/sourced_files/std_script_env.ksh

LISTENER_LOG_NAME=
LISTENER_LOG_NAME_PREFIX=
LISTENER_LOG_DIR=
LISTENER_PASS=
LISTENER_PASS_PROTECTED=
LISTENER_PASS_STRING=
NEW_LISTENER_ERRORS=0
NODENAME=$(hostname -s)
OLD_LISTENER_ERRORS=0
SAVED_ERROR_FILE=$ORACLE_BASE/admin/shell/listener_error_check.err
TEMP_LSNRCTL_FILE="/tmp/${THISFILE_BASE}.$$.txt"
TNS_ADMIN="$ORACLE_HOME/network/admin"

############################################################################
###
function USAGE
{
        echo "$THISFILE -p -t <TNS_ADMIN>"
        exit 1
}

############################################################################
###
function PROCESS_LISTENER
{
        RETURN_CODE_PL="0"
        touch $TEMP_LSNRCTL_FILE
        chmod 700 $TEMP_LSNRCTL_FILE

        if [ "$LISTENER_PASS_PROTECTED" = "YES" ]; then
           LISTENER_PASS=`grep "PASSWORDS_LISTENER" $TNS_ADMIN/listener.ora
| cut -d' ' -f3`
           LISTENER_PASS_STRING="set password $LISTENER_PASS"
        fi

#----------------------------------------\
# First, determine the listener's status.
#----------------------------------------/
        echo "[$(date +%m/%d/%Y' '%H:%M:%S)] Checking the listener's status
..."

        echo "
        $LISTENER_PASS_STRING
        status
        exit" | lsnrctl >>$TEMP_LSNRCTL_FILE
        RETURN_CODE_PL=$?

        if [ "$RETURN_CODE_PL" = "0" ]; then

#---------------------------------------------\
# Next, determine the listener's logfile name.
#---------------------------------------------/
           LISTENER_LOG_NAME=$(cat $TEMP_LSNRCTL_FILE | grep "^Listener Log
File" | awk '{print $4}')
           if [ -r "$LISTENER_LOG_NAME" ]; then

#-------------------------------\
# Check for new listener errors.
#-------------------------------/
              echo "[$(date +%m/%d/%Y' '%H:%M:%S)] Checking for new listener
errors ..."
              NEW_LISTENER_ERRORS=$(grep TNS- $LISTENER_LOG_NAME 2>/dev/null
| wc -l)
              if [ -r "$SAVED_ERROR_FILE" ]; then
                 OLD_LISTENER_ERRORS=$(grep TNS- $SAVED_ERROR_FILE | wc -l)
              else
                 touch $SAVED_ERROR_FILE
              fi

              if [ $NEW_LISTENER_ERRORS -gt $OLD_LISTENER_ERRORS ]; then
                 grep TNS- $LISTENER_LOG_NAME | sed -n
$((${OLD_LISTENER_ERRORS}+1))',$p' | tee -a $SAVED_ERROR_FILE
                 RETURN_CODE_PL="1"
              fi
           else
              echo "[$(date +%m/%d/%Y' '%H:%M:%S)] *** Error: listener
logfile is not readable: ${LISTENER_LOG_NAME}. ***"
              RETURN_CODE_PL="1"
           fi
        else
           echo "[$(date +%m/%d/%Y' '%H:%M:%S)] *** Error: listener status
check failed.  Listener may be down. ***"
        fi

        [[ -r "$TEMP_LSNRCTL_FILE" ]] && rm $TEMP_LSNRCTL_FILE

        return $RETURN_CODE_PL
}

############################################################################
###

COMMAND_LINE="$THISFILE $*"
echo "[$(date +%m/%d/%Y' '%H:%M:%S)] Starting script $THISFILE"
echo "[$(date +%m/%d/%Y' '%H:%M:%S)] Command line used was: $COMMAND_LINE"

while getopts "pt:" OPT
do
   case $OPT in
      p ) export LISTENER_PASS_PROTECTED="YES";;

#-------------------------------------------------------------------\
# TNS_ADMIN is EXPORTed because lsnrctl needs to pick up it's value.
#-------------------------------------------------------------------/
      t ) export TNS_ADMIN=$OPTARG;;
      \?) USAGE;;
      * ) USAGE;;
   esac
done

PROCESS_LISTENER
RETURN_CODE=$?

echo "[$(date +%m/%d/%Y' '%H:%M:%S)] Finished script $THISFILE, exit status
$RETURN_CODE"

exit $RETURN_CODE

-------------------------------------
Dave Herring, DBA
Acxiom Corporation
3333 Finley
Downers Grove, IL 60515
wk: 630.944.4762
<mailto:dherri@xxxxxxxxxx>
 
Myths Resolved: "A eye for eye, tooth for tooth, ... (Ex. 21:24) is normally
quoted as justification for revenge.  On the contrary, it was commanded to
stop people from taking greater revenge than the original injustice."
-------------------------------------
> -----Original Message-----
> From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx]
> On Behalf Of Herring Dave - dherri
> Sent: Thursday, March 03, 2005 10:19 AM
> To: Oracle-L Freelists
> Subject: tcl script for listener alert
> 
> Folks - OEM comes with a nice alert check defined in the event library for
> checking "alert_<dbname>.log" for new errors, but doesn't come with
> anything
> for checking error messages in "listener.log".  Instead of me trying to
> write a modified TCL script off the alert check one, does anyone out there
> already have something like this?
> 
> 
> Thanks.
> 
> 
> 
> -------------------------------------
> 
> Dave Herring, DBA
> 
> Acxiom Corporation
> 
> 3333 Finley
> 
> Downers Grove, IL 60515
> 
> wk: 630.944.4762
> 
> < <mailto:dherri@xxxxxxxxxx> mailto:dherri@xxxxxxxxxx>
> 
> 
> 
> Myths Resolved: "A eye for eye, tooth for tooth, ... (Ex. 21:24) is
> normally
> quoted as justification for revenge.  On the contrary, it was commanded to
> stop people from taking greater revenge than the original injustice."
> 
> -------------------------------------
> 
> 
> 
> 
> 
> **********************************************************************
> The information contained in this communication is
> confidential, is intended only for the use of the recipient
> named above, and may be legally privileged.
> If the reader of this message is not the intended
> recipient, you are hereby notified that any dissemination,
> distribution, or copying of this communication is strictly
> prohibited.
> If you have received this communication in error,
> please re-send this communication to the sender and
> delete the original message or any copy of it from your
> computer system. Thank You.
> 
> 
> 
> --
> //www.freelists.org/webpage/oracle-l
--
//www.freelists.org/webpage/oracle-l

Other related posts: