[OCI] Monitorización Dataguard
![[OCI] Monitorización Dataguard](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1751267264284%2F5af656c5-219a-434b-9088-3a0c15c8db4b.jpeg&w=3840&q=75)
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!
![[26ai] Hybrid Read-Only Mode PDB](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F65605419d28f19cc44df7ef1%2Fde208bd2-5e24-4fd3-acf7-8e5394d95283.png&w=3840&q=75)
![[26ai] ALERT_LOG_MAX_SIZE](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F65605419d28f19cc44df7ef1%2Fcbb365d0-4428-4a41-930d-516ce59e3355.jpg&w=3840&q=75)
![[26ai] ConnStr Tool](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F65605419d28f19cc44df7ef1%2F5005f06e-946c-49ba-bfe8-7fe18d1075d9.png&w=3840&q=75)
![[26ai] Instalación de Oracle26ai en Linux 9](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F65605419d28f19cc44df7ef1%2Fd9a6ba10-eb2d-4fee-8a0c-f4957cbdc676.png&w=3840&q=75)
![[OCI] Montaje de un Bucket como un FS](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F65605419d28f19cc44df7ef1%2F05595570-0fbd-46ce-9db4-d2f0e9f09003.png&w=3840&q=75)