Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.rb
- ===============================================================
- require './send_mail'
- require 'httparty'
- require 'pony'
- class Monitoring
- STATUS_CODE = 400
- Minute = 60
- puts 'What website are we monitoring? (example: https://www.pokupon.ua)'
- tracking_website = gets.chomp.to_s
- response = HTTParty.get(tracking_website)
- loop do
- if response.code == STATUS_CODE
- puts "resource #{tracking_website} is OK!"
- sleep Minute
- else
- begin
- sending_errors_mail(response)
- sleep Minute
- rescue
- puts 'Failed to send email, please check settings in method send_mail_error'
- break
- end
- end
- end
- end
- --------------------------------------------------------------------------------------------------------------------------------
- send_mail.rb
- require './main'
- require 'pony'
- class Send
- My_mail = "examp@gmail.com"
- def sending_errors_mail(response)
- Pony.mail({
- :subject => "The site status",
- :body => "The site response code - #{response.code}, response status - #{response.message}",
- :to => 'pocupon@i.ua',
- :from => My_mail,
- via: :smtp,
- via_options: {
- address: 'smtp.gmail.com',
- port: '587',
- enable_starttls_auto: true,
- user_name: my_mail,
- password: "pass",
- authentication: :plain,
- }
- })
- end
- end
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- и это выдаёт 2 ошибки
- What website are we monitoring? (example: https://www.pokupon.ua)
- https://www.pokupon.ua
- Failed to send email, please check settings in method send_mail_error
- main.rb:9: warning: already initialized constant Monitoring::STATUS_CODE
- /home/siro/testovoe/pokupon/main.rb:9: warning: previous definition of STATUS_CODE was here
- main.rb:10: warning: already initialized constant Monitoring::Minute
- /home/siro/testovoe/pokupon/main.rb:10: warning: previous definition of Minute was here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement