Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gem 'mechanize', '2.7.2'
require 'mechanize'
require 'pony'
def sendmail(to, subject, body)
Pony.mail({
:to => to,
:via => :smtp,
:subject => subject,
:body => body,
:charset => 'UTF-8',
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
})
end
mechanize = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
page = mechanize.get('https://www.yourwebsite.com/mytesturl')
content = ""
if page.body.include?('refused')
content = 'Error: Connection Refused'
end
if content
puts content
sendmail("email@domain.com", "Monitor", content)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment