#!/bin/bash
# Middleware Port Monitor Script
# Author : Sampathkumar
# mkdir -p /home/mw/scripts/ ; touch /home/mw/scripts/PortMon.sh;chmod +x /home/mw/scripts/PortMon.sh;touch /home/mw/scripts/portlist
# crontab -e & add the below entry
# Monitor Middleware Instance's Port every minutes using PortMon.sh
# * * * * * /home/mw/scripts/PortMon.sh > /home/mw/scripts/PortMon.log 2>&1
# The following code may be needed on few of the servers to work the mailing services properly
# uuencode $MAIL_OP $MAIL_OP |/usr/bin/mail -r '' -s "$SUBJ" "$TOList"
TODAY=`date +%d%m%y`
TIME=`date +%R`
host=`hostname`
AppName=''
Env='PRD'
PortStatus=/home/mw/scripts/PortMon.log
cat /dev/null> $PortStatus
TOList=
SUBJ="["$Env"-"$AppName"]Port:"$port" on "$host" is DOWN!!! `date +%d-%m-%Y`"
for port in `cat /home/mw/scripts/portlist`
do
echo "^]" | telnet $host $port > /dev/null 2>&1
ec=`echo $?`
if [ $ec -eq 0 ]
then
echo "Port $port is up.." > /dev/null
else
SUBJ="["$Env"-"$AppName"]Port:"$port" on "$host" is DOWN!!! `date +%d-%m-%Y`"
echo "Hi Service Desk," > $PortStatus
echo "Please raise an Incident Ticket & assign to Middleware team immediately to check the port "$port" & respective services as its is not running on the Server "$host"." >> $PortStatus
echo "" >> $PortStatus
echo "Importance: High" >> $PortStatus
echo "Time: `date`" >> $PortStatus
echo "Requestor Name: Middleware" >> $PortStatus
echo "">> $PortStatus
echo "Description: The port "$port" is on the server "$host" not running currently." >> $PortStatus
echo "Affected Application: ["$AppName"]" >> $PortStatus
echo "Port: ["$port"]" >> $PortStatus
echo "Environment: ["$Env"]" >> $PortStatus
echo "Initial Assignment Group:[Middleware]" >> $PortStatus
echo "Incident queue : []" >> $PortStatus
echo "Severity: [S3]" >> $PortStatus
echo "" >> $PortStatus
echo "With Regards," >> $PortStatus
echo "Middleware Team| Support" >> $PortStatus
echo "" >> $PortStatus
/usr/bin/mail -r "" -s "$SUBJ" "$TOList" < $PortStatus
#rm $PortStatus
fi
done
exit 0
#
# Author : Sampathkumar
# mkdir -p /home/mw/scripts/ ; touch /home/mw/scripts/PortMon.sh;chmod +x /home/mw/scripts/PortMon.sh;touch /home/mw/scripts/portlist
# crontab -e & add the below entry
# Monitor Middleware Instance's Port every minutes using PortMon.sh
# * * * * * /home/mw/scripts/PortMon.sh > /home/mw/scripts/PortMon.log 2>&1
# The following code may be needed on few of the servers to work the mailing services properly
# uuencode $MAIL_OP $MAIL_OP |/usr/bin/mail -r '
TODAY=`date +%d%m%y`
TIME=`date +%R`
host=`hostname`
AppName='
Env='PRD'
PortStatus=/home/mw/scripts/PortMon.log
cat /dev/null> $PortStatus
TOList=
SUBJ="["$Env"-"$AppName"]Port:"$port" on "$host" is DOWN!!! `date +%d-%m-%Y`"
for port in `cat /home/mw/scripts/portlist`
do
echo "^]" | telnet $host $port > /dev/null 2>&1
ec=`echo $?`
if [ $ec -eq 0 ]
then
echo "Port $port is up.." > /dev/null
else
SUBJ="["$Env"-"$AppName"]Port:"$port" on "$host" is DOWN!!! `date +%d-%m-%Y`"
echo "Hi Service Desk," > $PortStatus
echo "Please raise an Incident Ticket & assign to Middleware team immediately to check the port "$port" & respective services as its is not running on the Server "$host"." >> $PortStatus
echo "" >> $PortStatus
echo "Importance: High" >> $PortStatus
echo "Time: `date`" >> $PortStatus
echo "Requestor Name: Middleware" >> $PortStatus
echo "">> $PortStatus
echo "Description: The port "$port" is on the server "$host" not running currently." >> $PortStatus
echo "Affected Application: ["$AppName"]" >> $PortStatus
echo "Port: ["$port"]" >> $PortStatus
echo "Environment: ["$Env"]" >> $PortStatus
echo "Initial Assignment Group:[Middleware]" >> $PortStatus
echo "Incident queue : [
echo "Severity: [S3]" >> $PortStatus
echo "" >> $PortStatus
echo "With Regards," >> $PortStatus
echo "Middleware Team|
echo "" >> $PortStatus
/usr/bin/mail -r "
#rm $PortStatus
fi
done
exit 0
No comments:
Post a Comment