check proses down

#!/bin/bash
# email notifikasi problem down – error – run proses
# Sigit Afandhi – Mei 2014
# Mailto: anti.trust30@yahoo.com.sg

lb1=’192.168.10.4′
lb2=’192.168.10.5′
mdb1=’192.168.10.6′
mdb2=’192.168.10.7′
mdb3=’192.168.10.8′

email=’kamu@emailkamu.com’

MYSQL_START=’service mysql start’
KEEP_START=’service keepalived start’
HA_START=’service haproxy start’
MYSQL=’mysql’
KEEP=’keepalived’
HA=’haproxy’
PGREP=’/usr/bin/pgrep’
sub_mysql1=’Mysql mdb1 down and controller handle up!’
sub_mysql2=’Mysql mdb2 down dan controller handle up!’
sub_mysql3=’Mysql mdb3 down dan controller handle up!’
sub_haproxy1=’Haproxy lb1 down and controller handle up!’
sub_haproxy2=’Haproxy lb2 down and controller handle up!’
sub_keep1=’Keepalived lb1 down and controller handle up!’
sub_keep2=’Keepalived lb2 down dan controller handle up’

#Mencari Proses Mysql di server mdb1,mdb2,mdb3

echo -e “[!] Check proses mysql $mdb1″
ssh $USER@$mdb1 “$PGREP $MYSQL”
if [ $? -ne 0 ]; then
ssh $USER@$mdb1 “$MYSQL_START”  |  mail -s “$sub_mysql1″ $email
fi

echo -e “[!] Check proses mysql $mdb2″
ssh $USER@$mdb2 “$PGREP $MYSQL”
if [ $? -ne 0 ]; then
ssh $USER@$mdb2 “$MYSQL_START”  |  mail -s “$sub_mysql2″ $email
fi

echo -e “[!] Check proses mysql $mdb3″
ssh $USER@$mdb3 “$PGREP $MYSQL”
if [ $? -ne 0 ]; then
ssh $USER@$mdb3 “$MYSQL_START”  |  mail -s “$sub_mysql3″ $email
fi

#Mencari Proses Haproxy di server lb1 dan lb2

echo -e “[!] Check proses balancer $lb1″
ssh $USER@$lb1 “$PGREP $HA”
if [ $? -ne 0 ]; then
ssh $USER@$lb1 “$HA_START”  |  mail -s “$sub_haproxy1″ $email
fi

echo -e “[!] Check proses balancer $lb2″
ssh $USER@$lb2 “$PGREP $HA”
if [ $? -ne 0 ]; then
ssh $USER@$lb2 “$HA_START”  |  mail -s “$sub_haproxy2″ $email
fi

#Mencari Proses KeepAlived di server lb1 dan lb2

echo -e “[!] Check proses keepalived $lb1″
ssh $USER@$lb1 “$PGREP $KEEP”
if [ $? -ne 0 ]; then
ssh $USER@$lb1 “$KEEP_START”  |  mail -s “$sub_keep1″ $email
fi

echo -e “[!] Check proses keepalived $lb2″
ssh $USER@$lb2 “$PGREP $KEEP”
if [ $? -ne 0 ]; then
ssh $USER@$lb2 “$KEEP_START”  |  mail -s “$sub_keep2″ $email
fi

,

Leave a Reply