From dff1f98662289589ca6227bffa885f90b5773e62 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 14 Nov 2012 16:05:03 +0000 Subject: Updated each test to use the timeout period specified in the JSON hash. Update the trivial test to set such a thing too. --- lib/custodian/protocol-tests/dns.rb | 1 + lib/custodian/protocol-tests/ftp.rb | 3 ++- lib/custodian/protocol-tests/http.rb | 16 ++++++++-------- lib/custodian/protocol-tests/https.rb | 11 ++++++----- lib/custodian/protocol-tests/jabber.rb | 4 +++- lib/custodian/protocol-tests/ldap.rb | 3 ++- lib/custodian/protocol-tests/ping.rb | 1 + lib/custodian/protocol-tests/rsync.rb | 4 +++- lib/custodian/protocol-tests/smtp.rb | 4 +++- lib/custodian/protocol-tests/ssh.rb | 3 ++- 10 files changed, 31 insertions(+), 19 deletions(-) (limited to 'lib/custodian/protocol-tests') diff --git a/lib/custodian/protocol-tests/dns.rb b/lib/custodian/protocol-tests/dns.rb index 905abc8..4efabd3 100755 --- a/lib/custodian/protocol-tests/dns.rb +++ b/lib/custodian/protocol-tests/dns.rb @@ -173,6 +173,7 @@ if __FILE__ == $0 then "target_host" => "a.ns.bytemark.co.uk", "test_type" => "dns", "verbose" => 1, + "timeout" => 4, "test_alert" => "DNS failure", "resolve_name" => "support.bytemark.co.uk", "resolve_type" => "MX", diff --git a/lib/custodian/protocol-tests/ftp.rb b/lib/custodian/protocol-tests/ftp.rb index c528c84..a11abaf 100755 --- a/lib/custodian/protocol-tests/ftp.rb +++ b/lib/custodian/protocol-tests/ftp.rb @@ -74,7 +74,7 @@ class FTPTest puts "FTP testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout( @test_data["timeout"] ) do begin socket = TCPSocket.new( host, port ) @@ -130,6 +130,7 @@ if __FILE__ == $0 then "test_type" => "ftp", "test_port" => 21, "verbose" => 1, + "timeout" => 4, "test_alert" => "The FTP server no worky", } diff --git a/lib/custodian/protocol-tests/http.rb b/lib/custodian/protocol-tests/http.rb index e1e0ad0..445b192 100755 --- a/lib/custodian/protocol-tests/http.rb +++ b/lib/custodian/protocol-tests/http.rb @@ -67,7 +67,7 @@ class HTTPTest # Do the fetch, if this success then we'll have the # @status + @text setup # - if ( getURL (@test_data["target_host"] ) ) + if ( getURL(@test_data["target_host"], @test_data["timeout"] ) ) # # Do we need to test for a HTTP status code? @@ -112,13 +112,13 @@ class HTTPTest # Retrieve a HTTP page from the web. # # NOTE: This came from sentinel. - def getURL (uri_str) + def getURL (uri_str, timeout) 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 = 3 - http.read_timeout = 3 + http.open_timeout = timeout + http.read_timeout = timeout if (url.scheme == "https") http.use_ssl = true @@ -145,7 +145,7 @@ class HTTPTest then newURL = response['location'].match(/^http/)? response['Location']:uri_str+response['Location'] - return( getURL(newURL) ) + return( getURL(newURL, timeout) ) else @status = response.code.to_i @body = response.body @@ -184,12 +184,12 @@ if __FILE__ == $0 then # Sample data. # test = { - "target_host" => "http://www.steve.org.uk/", + "target_host" => "http://collector2.sh.bytemark.co.uk/", "test_type" => "http", "verbose" => 1, + "timeout" => 3, "test_port" => 80, - "test_alert" => "Steve's website is unavailable", - "http_text" => "Steve Kemp", + "test_alert" => "Collector is unavailable", "http_status" => "200" } diff --git a/lib/custodian/protocol-tests/https.rb b/lib/custodian/protocol-tests/https.rb index 8db4da5..ec2597b 100755 --- a/lib/custodian/protocol-tests/https.rb +++ b/lib/custodian/protocol-tests/https.rb @@ -68,7 +68,7 @@ class HTTPSTest # Do the fetch, if this success then we'll have the # @status + @text setup # - if ( getURL (@test_data["target_host"] ) ) + if ( getURL(@test_data["target_host"], @test_data["timeout"] ) ) # # Do we need to test for a HTTP status code? @@ -115,13 +115,13 @@ class HTTPSTest # Retrieve a HTTP page from the web. # # NOTE: This came from sentinel. - def getURL (uri_str) + def getURL (uri_str, timeout) 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 = 3 - http.read_timeout = 3 + http.open_timeout = timeout + http.read_timeout = timeout if (url.scheme == "https") http.use_ssl = true @@ -148,7 +148,7 @@ class HTTPSTest then newURL = response['location'].match(/^http/)? response['Location']:uri_str+response['Location'] - return( getURL(newURL) ) + return( getURL(newURL, timeout) ) else @status = response.code.to_i @body = response.body @@ -190,6 +190,7 @@ if __FILE__ == $0 then "target_host" => "http://www.steve.org.uk/", "test_type" => "http", "verbose" => 1, + "timeout" => 5, "test_port" => 80, "test_alert" => "Steve's website is unavailable", "http_text" => "Steve Kemp", diff --git a/lib/custodian/protocol-tests/jabber.rb b/lib/custodian/protocol-tests/jabber.rb index 1769eb8..489b82a 100755 --- a/lib/custodian/protocol-tests/jabber.rb +++ b/lib/custodian/protocol-tests/jabber.rb @@ -75,7 +75,7 @@ class JABBERTest puts "Jabber testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout(@test_data["timeout"]) do begin socket = TCPSocket.new( host, port ) @@ -130,6 +130,8 @@ if __FILE__ == $0 then test = { "target_host" => "chat.bytemark.co.uk", "test_type" => "jabber", + "test_port" => "5222", + "timeout" => 4, "verbose" => 1, "test_alert" => "Chat is down?", } diff --git a/lib/custodian/protocol-tests/ldap.rb b/lib/custodian/protocol-tests/ldap.rb index cec146b..5c94dd8 100755 --- a/lib/custodian/protocol-tests/ldap.rb +++ b/lib/custodian/protocol-tests/ldap.rb @@ -74,7 +74,7 @@ class LDAPTest puts "LDAP testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout(@test_data["timeout"]) do begin socket = TCPSocket.new( host, port ) @@ -122,6 +122,7 @@ if __FILE__ == $0 then "test_type" => "ldap", "test_port" => 389, "verbose" => 1, + "timeout" => 5, "test_alert" => "LDAP is down?", } diff --git a/lib/custodian/protocol-tests/ping.rb b/lib/custodian/protocol-tests/ping.rb index 7f1ffbd..fed72d4 100755 --- a/lib/custodian/protocol-tests/ping.rb +++ b/lib/custodian/protocol-tests/ping.rb @@ -108,6 +108,7 @@ if __FILE__ == $0 then "target_host" => "upload.ns.bytemark.co.uk", "test_type" => "ping", "verbose" => 1, + "timeout" => 5, "test_alert" => "Pingly faily", } diff --git a/lib/custodian/protocol-tests/rsync.rb b/lib/custodian/protocol-tests/rsync.rb index d5382bd..ab2ed9b 100755 --- a/lib/custodian/protocol-tests/rsync.rb +++ b/lib/custodian/protocol-tests/rsync.rb @@ -74,7 +74,7 @@ class RSYNCTest puts "rsync testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout(@test_data["timeout"]) do begin socket = TCPSocket.new( host, port ) @@ -129,7 +129,9 @@ if __FILE__ == $0 then test = { "target_host" => "upload.ns.bytemark.co.uk", "test_type" => "rsync", + "test_port" => "873", "verbose" => 1, + "timeout" => 5, "test_alert" => "DNS upload service failure", } diff --git a/lib/custodian/protocol-tests/smtp.rb b/lib/custodian/protocol-tests/smtp.rb index 8ed19e8..340821c 100755 --- a/lib/custodian/protocol-tests/smtp.rb +++ b/lib/custodian/protocol-tests/smtp.rb @@ -74,7 +74,7 @@ class SMTPTest puts "SMTP testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout(@test_data["timeout"]) do begin socket = TCPSocket.new( host, port ) @@ -129,7 +129,9 @@ if __FILE__ == $0 then test = { "target_host" => "mail.steve.org.uk", "test_type" => "smtp", + "test_port" => "25", "verbose" => 1, + "timeout" => 5, "test_alert" => "SMTP failure", } diff --git a/lib/custodian/protocol-tests/ssh.rb b/lib/custodian/protocol-tests/ssh.rb index b563aad..870be32 100755 --- a/lib/custodian/protocol-tests/ssh.rb +++ b/lib/custodian/protocol-tests/ssh.rb @@ -73,7 +73,7 @@ class SSHTest puts "ssh testing host #{host}:#{port}" if ( @test_data['verbose'] ) begin - timeout(3) do + timeout(@test_data["timeout"]) do begin socket = TCPSocket.new( host, port ) @@ -130,6 +130,7 @@ if __FILE__ == $0 then "test_type" => "ssh", "test_port" => 2222, "verbose" => 1, + "timeout" => 5, "test_alert" => "Steve's host isn't running SSH?", } -- cgit v1.2.1