Table of Contents

Overview

This way partially uses the script method but this time, instead of receiving spam A LOT. I will integrate the script with nagios so I can be notified ONLY when there is a problem.

Nagios Basics

You can use ANY script with nagios as soon as it provides the correct exit status. Nagios script should exit with:

Knowing that, I have modified the previous script to exit accordingly:

Script to be integrated with Nagios

#!/bin/bash
OIFS=$IFS
IFS="
"
NIFS=$IFS
function status {
OUTPUT=`$GG_HOME/ggsci << EOF
info all
exit
EOF`
}
function alert {
for line in $OUTPUT
do
GNAME=$(echo "${line}" | awk -F" " '{print $3}')
GSTAT=$(echo "${line}" | awk -F" " '{print $2}')
GTYPE=$(echo "${line}" | awk -F" " '{print $1}')
if [[ ${GTYPE} == "MANAGER" ]] || [[ ${GTYPE} == "REPLICAT" ]] || [[ ${GTYPE} == "EXTRACT" ]]
then
  case ${GSTAT} in
    STOPPED)
     STAT="STOP"
    ;;
    ABENDED)
     STAT="ABEND"
    ;;
    RUNNING)
     STAT="OK"
    ;;
    *)
     STAT="UNKNOWN"
    ;;
  esac
fi
done
echo ${STAT}
case ${STAT} in
  ABEND)
   exit 2
   ;;
  STOP)
   exit 1
   ;;
  OK)
   exit 0
   ;;
  *)
   exit 3
   ;;
esac
}
export GG_HOME=$(find /u01/app -name "ggsci"  2>&1 | grep -v "Permission denied");
export GG_HOME=${GG_HOME%??????}
export ORACLE_HOME=$(echo `tail -1 /etc/oratab` | awk -F":" '{print $2}')
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_SID=$(echo `tail -1 /etc/oratab` | awk -F":" '{print $1}')
status
alert

The following scripts, exports the ORACLE_HOME, ORACLE_SID (as long as it is the last one) and the Golden Gate Home location (as long as it is somewhere under /u01/app). The scripts also exits appropriately as listed above.

Now to make that script works we have to make coupel things:

Configure The monitoring

We have to configure two thigns here:

The client configuration will involve re-configuring the NRPE cfg and sudoers (as we need nagios to execute the script as oracle owner) The Server Configuration Will include adding this config on the nagios server.

Configure Nagios Client

Nagios usually comes with plugin called NRPE. Locate where is the nrpe.cfg and edit it as follows by appending this line at the end:

Edit NRPE cfg

command[check_gg_oracle]=sudo -u oracle /usr/local/nagios/libexec/check_gg_oracle.sh

It is import the script to be executed with Oracle user as the golden gate doesn't have a client way of connecting to the console.

Once that is done, we have to update the sudoers as well. I know there is way more secure way, but I have done as follows:

Update Sudoers

## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
nagios ALL=(ALL) NOPASSWD: ALL

That will allow the nagios to execute any command as any user. I know quite unsecure, feel free to change it with ALL=(oracle)

Once this is done, it is ready to add that in the nagios itself :)

Configure the Nagios Server

Once this is all done, we are ready to add this feature to our server:

Go to:

  1. Configure → Core Config
  2. Services
  3. Add New → Fill the fields as follows:

After all this is done, you should be able to see the monitoring status for that service in your dashboard.