Created
January 21, 2011 15:15
-
-
Save coreymartella/789811 to your computer and use it in GitHub Desktop.
El Cheapo Internet Monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
was_down = false | |
while true | |
t = Time.now.strftime("%l:%M:%S%p") | |
result = `ping -c 1 www.google.com 2>&1` | |
if result !~ /1 packets received/ | |
puts "Check at #{t} -- DOWN!" | |
if was_down | |
#don't repeat the notification if we're still down | |
`say "Internet down!"` | |
` growlnotify -a "Internet Monitor" -m "Internet Down at #{t}" -s -p Emergency ` | |
end | |
was_down = true | |
else | |
puts "Check at #{t} -- ok" | |
if was_down | |
`say "Internet back online"` | |
` growlnotify -a "Internet Monitor" -m "Internet Back Up at #{t}" -s -p Emergency ` | |
end | |
was_down = false | |
end | |
sleep 60 #adjust this to the number of seconds you want checks | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment