APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Dirk Hart > A simple remote site monitor
Printer Friendly Version




A simple remote site monitor


By Dirk Hart
Adanac Software
Email: dhart@mailstarusa.com

(This is part 1 of a two part article. Part Two is here.)

One of the many things I do is run a mailserver for hire ( www.mailstarusa.com). Understandably, folks like to have high availability on that machine - as do I since I get all the calls if that machine is down. It was surprising when I got a call from one customer saying the machine had been up and down a lot since I had experienced no problems with it at all. And the fact that this customer was connected through Hell South made me a bit suspicious.`

I decided that the thing to do was to monitor their IP adress for a while and see how many droputs they had. I searched the net and found many monitors, some of them very nice, but what I wanted was something very simple that would record the events in a log file. There didn't seem to be much but I did come across pingchecker ( http://www.pingangel.com/pingchecker.htm).

Pingchecker seemed simple enough for me, so I pasted it into a file and modified it to check my clients site. I put in my own email address. I edited crontab (/etc/crontab) to kick it off every 5 minutes and waited. This seemed like less and less like a good idea after a while. I wasn't getting much email and it seemd to take a long time. The problem was with the command does actually does the deed: ping -c 2 $pagesite. Perhaps the default behaviour of ping is different with the unix that pingchecker was written for but on RedHat Linux 8.0 it looks like ping -c2 $pagesite will happily wait until the next millenium. Consulting the manual I re-arranged things until I got ping -c2 -w10 $pagesite.












Well, that was pretty good but there were still some spurious results. Also, I don't usually spend my time waiting for email to arrive - computer guy likes to get out and about. So a couple of new features were added at this point.

First of all I wanted to be notified by phone when I was out moving and shaking, and I was still getting some false positives when connections were slow rather than actually down. Also, I wanted to be able to monitor more than 1 site. Since this was a brand new effort I renamed it pink.


#!/bin/bash
# reads sites from a file
# ping a site if no response then email a message
logfile="/var/log/pink.log"
smsnotify="5085551515 @vtext.com"
mailnotify="monitor@yourdomain.com"

cat /usr/lib/pink/pink.sites|while read pingsite pingname
do
       ping -c 2 -w 10 -Q 0x04 $pingsite 2>&1 > /dev/null
       #if 100% packet loss - a bad ping
       if [ $? -gt 0 ]
       then
       echo no reply from $pingsite \($pingname\) on `date` >>$logfile
       echo $pingname $pingsite "Alert" `date`| mail -s "$pingname" $mailnotif
y
       echo no reply from $pingname $pingsite | mail -s "$pingname" $smsnotify
       else touch "$logfile"
       fi
done    
 

Verizon customers can send themselves SMS messages for $0.02 each through vtext.com, so I added

echo no reply from $pingname $pingsite | mail -s "$pingname" $smsnotify 
 

to the script. This way you can get a message on your cell phone and call your client right away - they'll think you are possessed of supernatural powers.

Note also that if the remote site is pinged correctly the date and time on the log file are updated using touch. This is a handy way to see if your script is indeed running.

More than one site can be checked:

cat /usr/lib/pink/pink.sites|while read pingsite pingname
do
...
done   
 

This loop reads an IP address (or domain name) and a short description for reporting purposes from a file named pink.sites.

Pink.sites contains:

123.123.123.123    Fake Site - never pings
146.115.8.20    Ultranet DNS
198.6.1.5       UUNet DNS
pcunix.com pcunix
 

This way I can now monitor several clients sites and get reports on failures even while I am on the road.

In the next installment we'll see why it is important to actually read the documentation, and we'll make improvements to the quality of the results.


If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?




More Articles by Dirk Hart



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




 I sell and support
 Kerio Mail server
g_face.jpg

This post tagged:

       - DirkHart
       - Networking




Unix/Linux Consultants

Skills Tests

Guest Post Here