Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: milestone-2013…
Fetching contributors…

Cannot retrieve contributors at this time

executable file 56 lines (50 sloc) 1.343 kb
#!/usr/bin/env ruby
require File.expand_path(File.dirname(__FILE__) + '/shared')
require 'uri'
require 'net/http'
require 'net/https'
def check(web_app)
begin
response = http_get(web_app['url'], web_app['username'], web_app['password'])
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, SocketError, Timeout::Error => e
notify_down(web_app, e)
response = nil
end
if response && !response.body.include?(web_app['substring'])
notify_down(web_app)
end
rescue => e
STDERR.puts "An exception occurred while checking for #{web_app['url']}"
raise e
end
def notify_down(web_app, exception = nil)
domain = URI.parse(web_app['url']).host
message = "A web application is down!\n"
if exception
message << "Exception: #{exception}\n"
end
message << "URL: #{web_app['url']}\n"
email(config(:from), config(:to),
sprintf("#{config(:subject)}", domain),
message)
end
def http_get(url, username = nil, password = nil)
headers = {}
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.start do
req = Net::HTTP::Get.new(uri.path, headers)
req.basic_auth(username, password) if username
http.request(req)
end
end
def start
config(:web_apps).each do |web_app|
check(web_app)
end
end
start
Jump to Line
Something went wrong with that request. Please try again.