Guest User

Untitled

a guest
Jul 18th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. require 'net/smtp'
  2. require 'rubygems'
  3. require 'tlsmail' # gem install tlsmail
  4.  
  5. hosts = ['abc.com', 'defg.com']
  6.  
  7. mail_auth = {
  8. :server => 'xxxx',
  9. :port => 25,
  10. :username => 'xxxx',
  11. :password => 'xxxx'
  12. }
  13.  
  14. ping_cmd = '/sbin/ping'
  15.  
  16. recips = ['notify@this_email.com']
  17.  
  18. for host in hosts
  19. `#{ping_cmd} -c 1 #{host}` =~ /time=([0-9\.]+)/
  20.  
  21. if $1
  22. File.open("pinger-#{host}", 'a') {|f| f.write "#{Time.now}: #{$1} ms\n"}
  23. else
  24. File.open("pinger-#{host}", 'a') {|f| f.write "#{Time.now}: Unreachable\n"}
  25.  
  26. headers = ['From: pinger <pinger@xxx.com>',
  27. "Subject: [pinger] #{host} is unreachable"]
  28.  
  29. message = "#{host} unreachable, yikes."
  30.  
  31. Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
  32. Net::SMTP.start(mail_auth[:server], mail_auth[:port], '', mail_auth[:username], mail_auth[:password], :login) do |smtp|
  33. smtp.send_message "#{headers.join("\n")}\n\n#{message}", 'pinger@xxx.com', recips
  34. end
  35.  
  36. end
  37. end
Add Comment
Please, Sign In to add comment