Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/smtp'
- require 'rubygems'
- require 'tlsmail' # gem install tlsmail
- hosts = ['abc.com', 'defg.com']
- mail_auth = {
- :server => 'xxxx',
- :port => 25,
- :username => 'xxxx',
- :password => 'xxxx'
- }
- ping_cmd = '/sbin/ping'
- recips = ['notify@this_email.com']
- for host in hosts
- `#{ping_cmd} -c 1 #{host}` =~ /time=([0-9\.]+)/
- if $1
- File.open("pinger-#{host}", 'a') {|f| f.write "#{Time.now}: #{$1} ms\n"}
- else
- File.open("pinger-#{host}", 'a') {|f| f.write "#{Time.now}: Unreachable\n"}
- headers = ['From: pinger <pinger@xxx.com>',
- "Subject: [pinger] #{host} is unreachable"]
- message = "#{host} unreachable, yikes."
- Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
- Net::SMTP.start(mail_auth[:server], mail_auth[:port], '', mail_auth[:username], mail_auth[:password], :login) do |smtp|
- smtp.send_message "#{headers.join("\n")}\n\n#{message}", 'pinger@xxx.com', recips
- end
- end
- end
Add Comment
Please, Sign In to add comment