Checking host availability using cron and a few scripts
I like to be notified automatically when one of my servers decides to
roll over. The nagios package is perfectly appropriate for this, among
lots of other things.
However, these scripts are good for exactly one thing: sending me (or
someone) a message if a given piece of hardware at a given IP address
stops responding for more than a minute or so.
If that's the only itch you have, putting these scripts and files on
your loghost will let you scratch it in about two minutes. If you want a
much more thorough monitoring setup with an active user/developer base,
use nagios but be prepared to spend more than two minutes setting it up.
Installation:
-
Set up a directory to hold the results for any IP addresses you want to
monitor.
-
Move the accustamp script someplace ekg can find it. This script reads
stdin and writes accurate timestamps for each line to stdout.
-
Create a directory for root to store the ping results from each host.
Either change ekg to use that as the default, or change root's cron entry
to specify it on the command line.
-
Move the ishostup script to wherever your personal cron scripts live on
your system, and use an entry like this in your crontab file:
#+--------------------------- Minute (0-59)
#| +----------------------- Hour (0-23)
#| | +----------------- Day (1-31)
#| | | +------------- Month (1-12)
#| | | | +--------- Day of week (0-6, 0=Sunday)
#| | | | | +---- Command to be run
#| | | | | |
#v v v v v v
#=====================================================================
# Keep an eye on servers.
* * * * * $HOME/cron/ishostup
Create a directory called /var/tmp/ekg to hold files indicating who's been
notified about system activity and how recently. Make it writable by a
group that you're in. I used "staff":
me% ls -lFd /var/tmp/ekg
drwxrwsr-x 2 root staff 512 Jun 12 14:45 /var/tmp/ekg/
Install fping from ports. This setup relies on the fping program to rapidly
ping several hosts at one time, and on my system, you have to be root to
run fping. You can change that if you like, but I didn't see any reason
for a non-root user to be pinging anyone else.
Copy the setup files ekgadmins and ekghosts to /etc, and change them to
monitor the hosts you want with the notification system you want. I use
qmail for my MTA, which makes it easy to send an IM to my cellphone if
any host starts misbehaving.
Move the ekg script to wherever root's cron scripts live on your system,
and use an entry like this in root's crontab file:
#+--------------------------- Minute (0-59)
#| +----------------------- Hour (0-23)
#| | +----------------- Day (1-31)
#| | | +------------- Month (1-12)
#| | | | +--------- Day of week (0-6, 0=Sunday)
#| | | | | +---- Command to be run
#| | | | | |
#v v v v v v
#=====================================================================
* * * * * /usr/local/cron/ekg > /dev/null 2>&1
* * * * * /usr/local/cron/ekg-local > /dev/null 2>&1
Comments welcome.
Name Last modified Size Description
Parent Directory 08-Jun-2009 14:17 -
ishostup.tar 07-Jun-2009 22:18 34k
Check system availability via cron