Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.93 KB | None | 0 0
  1. main.rb
  2. ```
  3. require './send_mail'
  4. require 'httparty'
  5. require 'pony'
  6.  
  7.  
  8.  
  9. class Monitoring
  10.  
  11.  STATUS_CODE = 400
  12.  Minute = 60
  13.  
  14.  puts 'What website are we monitoring? (example: https://www.pokupon.ua)'
  15.  tracking_website = gets.chomp.to_s
  16.  response = HTTParty.get(tracking_website)
  17.  
  18.  loop do
  19.    if response.code == STATUS_CODE
  20.      puts "resource #{tracking_website} is OK!"
  21.      sleep Minute
  22.    else
  23.      begin
  24.        sending_errors_mail(response)
  25.        sleep Minute
  26.      rescue
  27.        puts 'Failed to send email, please check settings in method send_mail_error'
  28.        break
  29.      end
  30.    end
  31.  end
  32. end
  33.  
  34. ```
  35. --------------------------------------------------------------------------------------------------------------------------------
  36. send_mail.rb
  37.  
  38. require './main'
  39. require 'pony'
  40.  
  41.  
  42. class Send
  43.   My_mail = "examp@gmail.com"
  44.  
  45.   def sending_errors_mail(response)
  46.     Pony.mail({
  47.       :subject => "The site status",
  48.       :body => "The site response code - #{response.code}, response status - #{response.message}",
  49.       :to => 'pocupon@i.ua',
  50.       :from => My_mail,
  51.       via: :smtp,
  52.       via_options: {
  53.         address: 'smtp.gmail.com',
  54.         port: '587',
  55.         enable_starttls_auto: true,
  56.         user_name: my_mail,
  57.         password: "pass",
  58.         authentication: :plain,
  59.       }
  60.     })
  61.   end
  62. end
  63. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. и это выдаёт 2 ошибки
  65.  
  66. What website are we monitoring? (example: https://www.pokupon.ua)
  67. https://www.pokupon.ua
  68. Failed to send email, please check settings in method send_mail_error
  69. main.rb:9: warning: already initialized constant Monitoring::STATUS_CODE
  70. /home/siro/testovoe/pokupon/main.rb:9: warning: previous definition of STATUS_CODE was here
  71. main.rb:10: warning: already initialized constant Monitoring::Minute
  72. /home/siro/testovoe/pokupon/main.rb:10: warning: previous definition of Minute was here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement