#!/bin/bash
#######################################
# instant messaging monitoring system #
# by angga_s@raharja-net.co.id #
#######################################
colocationlist="192.168.1.7"
dutalist="192.168.4.5 192.168.4.6"
routerlist="192.168.6.6"
serverlist="192.168.1.1"
ymlist="angga_funkadelic funkadelic_angga"
tanggal="$(/bin/date |/usr/bin/awk '{print $6$2$3,$4}')"
listip="$routerlist $serverlist $colocationlist"
for ipserver in $listip
do
cekfiles="$(/bin/ls /tmp/ip-$ipserver)"
if [ "$cekfiles" = "/tmp/ip-$ipserver" ]; then
/bin/echo "files ip-$ipserver udah ada" > /dev/null
else
/bin/echo "files $ipserver belum ada coba buat" > /dev/null
/bin/echo "1" > /tmp/ip-$ipserver
fi
pingsekarang="$(/bin/ping -c 1 $ipserver | /bin/grep 'received' | /usr/bin/awk -F',' '{ print $2 }' | /usr/bin/awk '{ print $1 }')"
lastping="$(/bin/cat /tmp/ip-$ipserver)"
if [ "$pingsekarang" = "1" ]; then
if [ "$lastping" = "1" ]; then
/bin/echo "ip $ipserver kondisi normal & no action" > /dev/null
elif [ "$lastping" = "0" ]; then
msgup="$tanggal - host $ipserver is UP"
/bin/echo "$msgup" >> /var/log/ping.log
for ymsend in $ymlist
do
/bin/echo "$msgup" | /usr/bin/centerim -s msg -p yahoo -t $ymsend > /dev/null
done
/bin/echo "1" > /tmp/ip-$ipserver
fi
elif [ "$pingsekarang" = "0" ]; then
if [ "$lastping" = "1" ]; then
msgdown="$tanggal - host $ipserver is DOWN"
/bin/echo "$msgdown" >> /var/log/ping.log
for ymsend in $ymlist
do
/bin/echo "$msgdown" | /usr/bin/centerim -s msg -p yahoo -t $ymsend > /dev/null
done
/bin/echo "0" > /tmp/ip-$ipserver
elif [ "$lastping" = "0" ]; then
/bin/echo "ip $ipserver kondisi down & no action" > /dev/null
fi
fi
done
No comments:
Post a Comment