Created
June 20, 2012 16:08
-
-
Save kenoir/2960698 to your computer and use it in GitHub Desktop.
Quick script to grep the logs from the BBC logging service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ruby-debug' | |
# An HTTPS client that can read the Forge PEMs | |
module Forge | |
module Http | |
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
require 'openssl' | |
class Client | |
# Build an http client set up to talk to forge services | |
# url - e.g. "https://api.stage.bbc.co.uk/my/service/" | |
# cert - e.g. "/path/to/you/cert.pem" | |
# proxy_host - e.g. www-cache.reith.bbc.co.uk (NOTE: no scheme!) | |
def self.build(url, cert, proxy_host = nil, proxy_port = nil) | |
uri = ( url.instance_of?(String) ? URI.parse(url) : url ) | |
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port) | |
http.use_ssl = (uri.scheme == 'https') | |
if http.use_ssl? | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
File.open(cert) do |cert_file| | |
key_data = cert_file.read | |
http.cert = OpenSSL::X509::Certificate.new(key_data) | |
http.key = OpenSSL::PKey::RSA.new(key_data, nil) | |
end | |
end | |
http | |
end | |
end | |
end | |
end | |
def forge_client | |
Forge::Http::Client.build(@base_url,@cert_location,@proxyhost,@proxyport) | |
end | |
def server_list | |
file = File.open("server_list.txt", "rb") | |
contents = file.read | |
contents.split | |
end | |
@base_url = '' | |
@cert_location = '' | |
@proxyhost = '' | |
@proxyport = '80' | |
@magic_words = /GET \/labuk\/experiments\/compete HTTP\/1.1" 404/ | |
puts "Beginning:" | |
server_list.each { |server| | |
response = forge_client.request_get("/tail/download/live/device-#{server}-log/httpd/access_log") | |
puts "Checking: #{server}" | |
if response.body =~ @magic_words | |
puts "BOOM: #{server}" | |
abort | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment