Skip to content

Instantly share code, notes, and snippets.

@coreymartella
Created January 21, 2011 15:15
Show Gist options
  • Save coreymartella/789811 to your computer and use it in GitHub Desktop.
Save coreymartella/789811 to your computer and use it in GitHub Desktop.
El Cheapo Internet Monitor
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