#!/usr/bin/perl # # Ultra-simple perl host uptime checker # Matthew Steven Wed Aug 15 15:54:17 2007 # # Requires: wget, unix system, cron to run, MIME::Lite # # Run in a crontab for checking if a host is up or not # # This will only message once in a 24 hour period as-is to # prevent spamming cellphones. # # Usage: checkuptime.pl [hostname] [notification email] # # Example Crontab entry: # # */5 * * * /path/to/script/checkuptime.pl localhost me@myhost.net # # You'll probably want to add a cron entry to clean up the notify files too # 1 1 1 * * rm -f /tmp/sent* use MIME::Lite; my $host = shift; my $email = shift; my $day = `date +%F`; chomp $day; exit if( -f "/tmp/sent-$host-$email-$day" ); `wget -q --timeout 10s -O /tmp/$$-test $host`; if(-z "/tmp/$$-test"){ if(-e "/tmp/twicefound-$host"){ $msg = MIME::Lite->new( From => $email, To => $email, Subject =>"Unresponsive system $host", Data =>"The monitoring system has found the system webserver of $host to be unresponsive for more than one attempt/10min." ); $msg->send(); unlink("/tmp/twicefound-$host"); `touch "/tmp/sent-$host-$email-$day"`; }else{ `touch /tmp/twicefound-$host` } } unlink("/tmp/$$-test");