downtime
Current version: 0.1, released 20 July 2006
If you find this script useful, you may make a small donation to help support further development. Thanks!
downtime is a bash shell script that monitors one or more remote servers and logs times they are inaccessible (down). It is designed for use by someone with a home/office Linux machine who wants to track the status of remote servers.
The script is run via cron at your chosen interval (e.g., every two minutes) and writes to a log file of your choice. Only periods of inaccessibility are logged (no news is good news).
downtime also monitors your local Internet connection, so as not to incorrectly report server downtime when your Internet connection fails. Periods of Internet-connection failure are also written to the log.
The script is run via cron at your chosen interval (e.g., every two minutes) and writes to a log file of your choice. Only periods of inaccessibility are logged (no news is good news).
downtime also monitors your local Internet connection, so as not to incorrectly report server downtime when your Internet connection fails. Periods of Internet-connection failure are also written to the log.
Sample logging (IPs are disguised):
If your local Linux machine is running a web server, you can of course place the log in a web-accessible location and view it with a web browser. Or 'include' it in a dynamic PHP or .shtml page.
Wed Jul 19 08:40:01 NDT 2006: Downtime monitoring initiated
Wed Jul 19 14:14:03 NDT 2006: xxx.yy.3.67 is down
Wed Jul 19 14:22:02 NDT 2006: xxx.yy.3.67 is up [was down 8 mins]
Wed Jul 19 20:32:02 NDT 2006: Internet down
Wed Jul 19 20:34:01 NDT 2006: Internet up [was down 2 mins]
Thu Jul 20 05:20:03 NDT 2006: xxx.yy.199.36 is down
Thu Jul 20 05:38:01 NDT 2006: xxx.yy.199.36 is up [was down 18 mins]
If your local Linux machine is running a web server, you can of course place the log in a web-accessible location and view it with a web browser. Or 'include' it in a dynamic PHP or .shtml page.
Installing fping
downtime uses a small (and very handy) utility called fping, which must be installed first. You can quickly install fping on your local machine like this:
[root@server]# cd /usr/src
[root@server]# wget http://fping.sourceforge.net/download/fping.tar.gz
[root@server]# tar -xzf fping.tar.gz
[root@server]# cd fping-x.xx
[root@server]# ./configure
[root@server]# make
[root@server]# make install
Configuring downtime
There are four settings at the top of the downtime script that you must adjust prior to use:
IPlist is a space-separated list of IPs to be monitored. Check that each IP normally responds to pings.
intnetIP is an IP to be monitored for your Internet connection. Select an IP on your ISP's network close to you. You can do a traceroute out to any Internet location, and select the first IP you see outside your LAN. Check that it responds to pings. This IP will only be checked when an IP in the 'IPlist' fails to respond, to confirm that the failure is not due to lack of Internet connectivity.
logfile is of course the logfile :) You can put it wherever you want and name it whatever you want.
fpbin is the location of fping, you probably will not need to change this.
All the IPs you configure, in 'IPlist' and 'intnetIP', must respond to pings! You cannot use this script to monitor any system that is blocking ping (ICMP).
# List of IPs to be monitored (separate IPs with a space):
IPlist="172.20.45.12 172.21.29.134"
#
# An IP to confirm that local Internet connection is OK:
intnetIP=aaa.bb.cc.ddd
#
# Full path & name for the logfile
logfile=/PATH/TO/downtime.log
#
# Full path to fping binary:
fpbin=/usr/local/sbin/fping
IPlist is a space-separated list of IPs to be monitored. Check that each IP normally responds to pings.
intnetIP is an IP to be monitored for your Internet connection. Select an IP on your ISP's network close to you. You can do a traceroute out to any Internet location, and select the first IP you see outside your LAN. Check that it responds to pings. This IP will only be checked when an IP in the 'IPlist' fails to respond, to confirm that the failure is not due to lack of Internet connectivity.
logfile is of course the logfile :) You can put it wherever you want and name it whatever you want.
fpbin is the location of fping, you probably will not need to change this.
All the IPs you configure, in 'IPlist' and 'intnetIP', must respond to pings! You cannot use this script to monitor any system that is blocking ping (ICMP).
Setting the cronjob
First set correct ownership and permissions on the file so it is executable only by root:
Then schedule a job in root's crontab using "crontab -e". To monitor your servers every two minutes you'd have something like:
[root@server]# chown root downtime.sh
[root@server]# chmod 700 downtime.sh
Then schedule a job in root's crontab using "crontab -e". To monitor your servers every two minutes you'd have something like:
*/2 * * * * /PATH/TO/downtime.sh
Download
Here is the script as a plain text file: downtime.txt. Save it as downtime.sh (or whatever you want).
Terms & Conditions
You are free to use, modify and redistribute this script. If you improve on it I'd appreciate hearing about it!
Liability:
The author assumes no liability for damage or loss that might be associated with the use of this script.
Liability:
The author assumes no liability for damage or loss that might be associated with the use of this script.
Bug reports & feedback
-- Doug Robbins