you are here: codestackercodes [RSS] → tag monitor [RSS]

simple http monitor based on keyword

http://leonardofaria.net/2015/07/10/uptime-monitoring-tools/

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
Displaying 1 Code