Skip to main content

Command Palette

Search for a command to run...

[OCI] Monitorización Dataguard

Updated
2 min read
[OCI] Monitorización Dataguard

Os paso un script sencillo para supervisar nuestro Oracle Data Guard, cuya función es enviarnos una alerta si se detectan errores o advertencias.

En caso que nuestro script haya detectado problemas, nos enviará un correo con la siguiente información:

  • Estado del Data Guard.

  • Posibles errores ORA a nivel de primary o standby.

  • Lag actual del dataguard.

La alerta que nos llegaría sería la siguiente:

Este sería el script:

#!/bin/bash

. /home/oracle/.bashrc

getInfo_dgmgrl(){
  while read -a line;
  do
    if [[ "${line[2]}" == *"Primary"* ]];
    then
      echo "${line[0]}"
    elif [[ "${line[2]}" == *"Physical"* ]];
    then
      echo "${line[0]}"
    fi
  done <<< $1
}

check_output=$(getInfo_dgmgrl "`dgmgrl -silent /  "show configuration"`")

set ${check_output}
PRY=$1
STB=$2

LAG=`dgmgrl -silent /  "show configuration lag" | grep -ie 'transport' -ie 'apply' | sed 's/^[[:space:]]*//'`
STATUS=`dgmgrl -silent /  "show configuration" | grep -i status | awk 'END{print}'  | sed 's/^[[:space:]]*//' | awk '{printf $1}'`

SUMMARY_DATAGUARD=`
   dgmgrl -silent /  "show database '${PRY}' 'StatusReport'" | grep ORA | awk -F"ERROR|WARNING" '{ print $2 }' | \
   awk -v primary="${PRY}" '
   {
            printf "Primary database: " primary "\n"
            printf "Errores encontrados:"
            if ( $0 != "") {
             printf $0
            } else {
             printf "sin errores"
            }
            printf "\n\n"
   }
' &&
   dgmgrl -silent /  "show database '${STB}' 'StatusReport'" | grep ORA | awk -F"ERROR|WARNING" '{ print $2 }' | \
   awk -v standby="${STB}" '
   {
            printf "Standby database: " standby "\n"
            printf "Errores encontrados:"
            if ( $0 != "") {
             printf $0
            } else {
             printf "sin errores"
            }

   }
'`

if [[ ! "${STATUS}" =~ "SUCCESS" ]]; then
printf "Resumen de errores Dataguard\n\nFecha de Inicio=$(date '+%d-%m-%Y %H:%M:%S')\n\nStatus=${STATUS}\n\n${SUMMARY_DATAGUARD}\n\n${LAG}" | mailx -s "[${ORACLE_UNQNAME}] Summary Dataguard" ${EMAIL}
fi

Descarga desde github:

https://github.com/dbaenlasombra/MonitoreDataguard/

Ahora solo faltaría planificarlo en cron. En mi caso es diario y cada media hora.

[root@ scripts]# crontab -l
*/30 * * * * /root/scripts/check_backups.sh

Listo. ¡Espero que os sirva!