May 01 2009
A Simple Monitoring Script to monitor devices or hosts

At work we have a few routers, switches and servers that if they go down we want to know right away. The last thing we want is the CEO coming to our desk asking why the mail server is down or why the webserver it not responding.
I wrote a little script a very simple one that given a list of hosts and IP addresses will ping a host and if it is detected as down it will send you an email right away.
########## Instructions on how to use this monitor script ############
Make a directory called scripts
mkdir /scripts then inside create using your favorite text editor the following script
#!/bin/bash
# Ping Alert Monitor by Marco Maldonado V 1.0
# Create a hosts file and save it somewhere on your server
# specify a path and an email address where you want to send alerts
#
# Note: Your hosts file should have the IP address of the host followed by a space and the name
# of the server: Example Below
#
# 69.147.76.15 www.yahoo.com
# 209.85.165.147 wwww.google.com
#
# Path to your hosts file
HOSTS="/scripts/hosts"
# Email address where to send alerts, you can add more addresses followed by a comma
EMAIL="yourname@yourdomain,someaddres@gmail.com"
### Do not edit anything below ############
for myHost in `cat $HOSTS | cut -d' ' -f1` ; do
ping -c 1 $myHost > /dev/null
if [ $? -ne 0 ] ; then
echo “Server `grep $myHost $HOSTS` is down reported down at `date`” | mail -s “Ping Alert Server `grep $myHost $HOSTS` might be down” $EMAIL
fi ;
done
Continua”A Simple Monitoring Script to monitor devices or hosts”
