Monitor Golden Gate
A continuación pongo un ejemplo de como realizo el monitoreo a nivel de golden gate, para avisarme en caso que un proceso este en estado stopped o abended.
Como podeis observar en un sh sencillo que lo que hace es enviarte una alerta al correo electrónico en caso que tengamos un proceso ko.
El sh lo que hace es obtener la información de los procesos de nuestro proceso ogg "info all" y leer esa información en búsca de procesos que cumplan el criterio que buscamos "egrep 'STOP|ABEND'".
El script como podéis observar no utilizo mailx sino utiliza la api de Oracle utl_smtp por cuestiones de seguridad dentro del propio cliente.
#!/bin/sh
LOG=`date +"%d%m%y%H%M%S"`.log
EMAIL="XXXXXXX"
OIFS=$IFS
IFS="
"
NIFS=$IFS
function getInfo {
INFO=`$OGG_HOME/ggsci << EOF
info all
exit
EOF`
}
function readInfo {
for line in $INFO
do
if [[ $(echo "${line}"|egrep 'STOP|ABEND' >/dev/null;echo $?) = 0 ]]
then
NAME=$(echo "${line}" | awk -F" " '{print $3}')
STATS=$(echo "${line}" | awk -F" " '{print $2}')
TYPE=$(echo "${line}" | awk -F" " '{print $1}')
$ORACLE_HOME/bin/sqlplus -s ${VUSER}/${VPASS}@${LOCAL_SID} <<-EoLoad
Declare
AUTH_SENDER Varchar2(100) := XXXXX;
AUTH_ROBOT_USER Varchar2(100) := XXXX;
AUTH_ROBOT_PASS Varchar2(100) := XXXXXX;
AUTH_PORT Varchar2(100) := XXXXX;
AUTH_SMTP Varchar2(100) := XXXXX;
v_Username_B64 Varchar2(1000);
v_Password_B64 Varchar2(1000);
id_Smtp_Enel Utl_Smtp.Connection;
v_Replies Utl_Smtp.Replies;
l_Boundary Varchar2(50) := '----=*#abc1234321cba#*=';
Begin
v_Username_B64 := Utl_Raw.Cast_To_Varchar2(Utl_Encode.Base64_Encode(Utl_Raw.Cast_To_Raw(AUTH_ROBOT_USER)));
v_Password_B64 := Utl_Raw.Cast_To_Varchar2(Utl_Encode.Base64_Encode(Utl_Raw.Cast_To_Raw(AUTH_ROBOT_PASS)));
id_Smtp_Enel := Utl_Smtp.Open_Connection( AUTH_SMTP, AUTH_PORT );
v_Replies := Utl_Smtp.Ehlo(id_Smtp_Enel, AUTH_SMTP );
Utl_Smtp.command(id_Smtp_Enel,'AUTH', 'LOGIN');
Utl_Smtp.command(id_Smtp_Enel, v_Username_B64);
Utl_Smtp.command(id_Smtp_Enel, v_Password_B64);
Utl_Smtp.Mail(id_Smtp_Enel,AUTH_SENDER);
Utl_Smtp.rcpt(id_Smtp_Enel, '${EMAIL}');
Utl_Smtp.Open_Data(id_Smtp_Enel);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'Date: ' || To_Char(Sysdate, 'DD-MON-YYYY HH24:MI:SS') || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'To: '||AUTH_SENDER||' ' || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'From: '||AUTH_SENDER||' ' || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'Subject: '||'${TYPE}:${NAME} - STATUS: ${STATS}'||' '|| Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'Reply-To: ${EMAIL}' || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, 'MIME-Version: 1.0' || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel,'Content-Type: multipart/alternative; boundary="' ||l_Boundary || '"' || Utl_Tcp.Crlf || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, '--' || l_Boundary || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel,'Content-Type: text/html; charset="iso-8859-1"' ||Utl_Tcp.Crlf || Utl_Tcp.Crlf);
Utl_Smtp.write_data(id_Smtp_Enel, 'The process ${NAME} is ${STATS}');
Utl_Smtp.Write_Data(id_Smtp_Enel, Utl_Tcp.Crlf || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, Utl_Tcp.Crlf || Utl_Tcp.Crlf);
Utl_Smtp.Write_Data(id_Smtp_Enel, '--' || l_Boundary || '--' || Utl_Tcp.Crlf);
Utl_Smtp.Close_Data(id_Smtp_Enel);
Utl_Smtp.Quit(id_Smtp_Enel);
End;
/
EoLoad
fi
done
}
export OGG_HOME=/ogg/19c
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1
export LD_LIBRARY_PATH=/u01/app/oracle/product/19.0.0.0/dbhome_1/lib
getInfo
readInfo
El script lo programo vía crontab cada 5 minutos.
*/5 * * * * /home/ogguser/scripts/getinfo.sh > /home/ogguser/scripts/getinfo.log
Pongo un ejemplo de un envío de una alerta
¡Espero que os sirva!