Created
March 16, 2012 16:45
-
-
Save excid3/2051045 to your computer and use it in GitHub Desktop.
Ping All The Things
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
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