Wednesday, July 27, 2011

Monitoring ip server & notifikasi YM

#!/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

Wednesday, July 6, 2011

YM server console bash script

#!/bin/bash

listym="angga_funkadelic funkadelic_angga"
for ymlist in $listym
do
header="$(/usr/bin/tail -5 /root/.centerim/y$ymlist/history | /usr/bin/head -1)"
msgnumber="$(/usr/bin/tail -3 /root/.centerim/y$ymlist/history | /usr/bin/head -1 | /usr/bin/tail -1)"
message="$(/usr/bin/tail -3 /root/.centerim/y$ymlist/history | /usr/bin/tail -1)"
lastid="$(/bin/cat /tmp/lastid$ymlist)"
if [ "$header" = "IN" ]; then
        if [ "$msgnumber" = "$lastid" ]; then
                echo "no action" > /dev/null
        else
                echo "$message" > /tmp/exec$ymlist
                /tmp/exec$ymlist > /tmp/hasil$ymlist
                kirimkan="$(/bin/cat /tmp/hasil$ymlist)"
                /bin/echo "$kirimkan" | /usr/bin/centerim -s msg -p yahoo -t $ymlist > /dev/null
                echo "$msgnumber" > /tmp/lastid$ymlist
        fi
fi
done