APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

A simple remote site monitor


© July 2003 Dirk Hart
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 ( https://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.


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> A simple remote site monitor


Inexpensive and informative Apple related e-books:

Digital Sharing Crash Course

Take Control of Numbers

Take Control of Automating Your Mac

Take control of Apple TV, Second Edition

Take Control of iCloud




More Articles by © Dirk Hart




Printer Friendly Version

Have you tried Searching this site?

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.

Contact us


Printer Friendly Version





The man who receives five thousand dollars a year wants six thousand dollars a year, and the man who owns eight or nine hundred thousand dollars will want a hundred thousand dollars more to make it a million, while the man who has his millions will want everything he can lay his hands on and then raise his voice against the poor devil who wants ten cents more a day. (Samuel Gompers)




Linux posts

Troubleshooting posts


This post tagged:

DirkHart

Networking



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode





SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)
www.SCOsales.com