Skip to content

Instantly share code, notes, and snippets.

@excid3
Created March 16, 2012 16:45
Show Gist options
  • Save excid3/2051045 to your computer and use it in GitHub Desktop.
Save excid3/2051045 to your computer and use it in GitHub Desktop.
Ping All The Things
require 'net/smtp'
SERVERS = ["excid3.com", "hahgay.com"]
GMAIL_USERNAME = ""
GMAIL_PASSWORD = ""
SENDING_EMAIL_ADDR = "barrett.coats@gmail.com"
RECEIVING_EMAIL_ADDR = "barrett.coats@gmail.com"
SERVERS.each do |s|
system "ping -c 5 #{s}"
# Any error code other than 0 means the ping failed, $? is the return value of system command
if $? != 0
# SEND MAIL TO GMAIL
send_email("SHITS IS DOWN AT #{s}")
end
end
def send_email(message, destination_email)
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls
smtp.start('localhost', GMAIL_USERNAME, GMAIL_PASSWORD, 'plain') do |connection|
connection.send_message(message, SENDING_EMAIL_ADDR, RECEIVING_EMAIL_ADDR)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment