summaryrefslogtreecommitdiff
path: root/lib/custodian/protocol-tests
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-14 22:31:54 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-14 22:31:54 +0000
commit907b1b5d35a9121bc2c2d2e94270ca8a698df1cf (patch)
tree01b4565d5fbbfb133fc39d645dfd4211501a2f97 /lib/custodian/protocol-tests
parentf055de793c6bac81bf014a7fd6cb0994c5991ebc (diff)
Added external curl-using HTTP fetch, to actually work.
Diffstat (limited to 'lib/custodian/protocol-tests')
-rwxr-xr-xlib/custodian/protocol-tests/http.rb102
1 files changed, 18 insertions, 84 deletions
diff --git a/lib/custodian/protocol-tests/http.rb b/lib/custodian/protocol-tests/http.rb
index 34fc472..3a0d1bd 100755
--- a/lib/custodian/protocol-tests/http.rb
+++ b/lib/custodian/protocol-tests/http.rb
@@ -1,9 +1,7 @@
#!/usr/bin/ruby1.8
-require 'net/http'
-require 'net/https'
-require 'uri'
+require 'custodian/webfetch'
class HTTPTest
@@ -13,13 +11,6 @@ class HTTPTest
#
attr_reader :test_data
- #
- # The HTTP status, the HTTP response body, and the error text
- # we return on failure.
- #
- attr_reader :status, :body, :error
-
-
#
# Save the data away.
@@ -63,20 +54,26 @@ class HTTPTest
#
@error = nil
+
+ #
+ # Run the fetch.
+ #
+ obj = WebFetch.new( @test_data["target_host"], @test_data["timeout"].to_i )
+
#
- # Do the fetch, if this success then we'll have the
- # @status + @text setup
+ # If we succeeded in the fetch
#
- if ( getURL(@test_data["target_host"], @test_data["timeout"].to_i ) )
+ if ( obj.fetch() )
#
# Do we need to test for a HTTP status code?
#
if ( @test_data["http_status"] )
- puts "Testing for HTTP status code: #{@test_data['http_status']}" if ( @test_data['verbose'] )
- if ( @status != @test_data['http_status'].to_i)
- @error = "#{@error} status code was #{@status} not #{@test_data['http_status']}"
+ puts "Testing for HTTP status code: #{@test_data['http_status']}" if ( @test_data['verbose'] )
+
+ if ( obj.status().to_i != @test_data['http_status'].to_i)
+ @error = "#{@error} <p>The HTTP status-code was '#{obj.status}' not '#{@test_data['http_status']}'.</p>"
end
end
@@ -86,8 +83,8 @@ class HTTPTest
if ( @test_data['http_text'] )
puts "Testing for text in the response: '#{@test_data['http_text']}'" if ( @test_data['verbose'] )
- if (! @body.match(/#{@test_data['http_text']}/i) )
- @error = "#{@error} The response did not contain our expected text '#{test_data['http_text']}'"
+ if (! obj.content.match(/#{@test_data['http_text']}/i) )
+ @error = "#{@error}<p>The response did not contain our expected text '#{test_data['http_text']}</p>'"
end
end
@@ -96,6 +93,7 @@ class HTTPTest
return false
end
+ @error = obj.error()
return false
end
@@ -108,71 +106,6 @@ class HTTPTest
end
- #
- # Retrieve a HTTP page from the web.
- #
- # NOTE: This came from sentinel.
- def getURL (uri_str, timeout)
-
- timeout( timeout ) do
- begin
- uri_str = 'http://' + uri_str unless uri_str.match(/^http/)
- url = URI.parse(uri_str)
- http = Net::HTTP.new(url.host, url.port)
- http.open_timeout = timeout
- http.read_timeout = timeout
-
- if (url.scheme == "https")
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- end
-
- response = nil
-
- #
- # Ensure we have a trailing "/"
- #
- if ( url.path.empty? )
- url.path = "/"
- end
-
- if nil == url.query
- response = http.start { http.get(url.path) }
- else
- response = http.start { http.get("#{url.path}?#{url.query}") }
- end
-
- case response
- when Net::HTTPRedirection
- then
- newURL = response['location'].match(/^http/)?
- response['Location']:uri_str+response['Location']
- return( getURL(newURL, timeout) )
- else
- @status = response.code.to_i
- @body = response.body
- end
-
- return true
- rescue Errno::EHOSTUNREACH => ex
- @error = "no route to host"
- return false
- rescue Timeout::Error => ex
- @error = "time out reached"
- return false
- rescue Errno::ECONNREFUSED => ex
- @error = "Connection refused"
- return false
- rescue Timeout::Error => e
- @error = "TIMEOUT: #{e}"
- return false
- rescue => ex
- @error = ex
- return false
- end
- end
- end
-
end
@@ -192,7 +125,8 @@ if __FILE__ == $0 then
"timeout" => 3,
"test_port" => 80,
"test_alert" => "Collector is unavailable",
- "http_status" => "200"
+ "http_status" => "200",
+ "http_text" => "Bytemark Monitor"
}