diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-12 21:00:16 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-12 21:00:16 +0000 | 
| commit | 6334b9cdfc47bd85b2ce236572e08406324d25cd (patch) | |
| tree | bd0bd3cc279d8377efde2affc8dc223bfb858ca2 /worker/tests | |
  Initial dump of code.
Diffstat (limited to 'worker/tests')
| -rw-r--r-- | worker/tests/README | 15 | ||||
| -rw-r--r-- | worker/tests/ftp.rb | 51 | ||||
| -rw-r--r-- | worker/tests/http.rb | 20 | ||||
| -rw-r--r-- | worker/tests/https.rb | 20 | ||||
| -rw-r--r-- | worker/tests/jabber.rb | 51 | ||||
| -rw-r--r-- | worker/tests/ldap.rb | 41 | ||||
| -rwxr-xr-x | worker/tests/ping.rb | 36 | ||||
| -rw-r--r-- | worker/tests/rsync.rb | 48 | ||||
| -rw-r--r-- | worker/tests/smtp.rb | 52 | ||||
| -rwxr-xr-x | worker/tests/ssh.rb | 50 | 
10 files changed, 384 insertions, 0 deletions
diff --git a/worker/tests/README b/worker/tests/README new file mode 100644 index 0000000..f40031b --- /dev/null +++ b/worker/tests/README @@ -0,0 +1,15 @@ + +  This directory contains the protocol-tests. + +  For the protocol "XXX" we must have: + +        - The file called XXX.rb + +        - The definition of the single method XXX_test + +  The test will make use of "target_host", and "test_port" (other keys may be optionally + used) and will return the single result: + +        false:  The test failed. + +        true:  The test succeeded.
\ No newline at end of file diff --git a/worker/tests/ftp.rb b/worker/tests/ftp.rb new file mode 100644 index 0000000..cd0e754 --- /dev/null +++ b/worker/tests/ftp.rb @@ -0,0 +1,51 @@ +require 'timeout' + + +# +# Run an FTP test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def ftp_test ( params ) + +  # +  #  Get the hostname & port to test against. +  # +  host = params['target_host'] +  port = params['test_port'] + +  puts "FTP testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.puts( "QUIT") + +        banner = socket.gets(nil) +        banner = banner[0,20] + +        socket.close() + +        if ( banner =~ /^220/ ) +          puts "FTP alive: #{banner}" +          return true +        end +      rescue +        puts "FTP exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e +    puts "TIMEOUT: #{e}" +    return false +  end + +  return false +end diff --git a/worker/tests/http.rb b/worker/tests/http.rb new file mode 100644 index 0000000..56163c8 --- /dev/null +++ b/worker/tests/http.rb @@ -0,0 +1,20 @@ + +# +# Run a HTTP test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def http_test( params ) + +  # +  # Get the URL to fetch. +  # +  host = params['target_host'] + +  puts "HTTP FAILED - TODO - IMPLEMENT" +  return false +end diff --git a/worker/tests/https.rb b/worker/tests/https.rb new file mode 100644 index 0000000..b905d79 --- /dev/null +++ b/worker/tests/https.rb @@ -0,0 +1,20 @@ + +# +# Run a HTTPS test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def https_test( params ) + +  # +  # Get the URL to poll. +  # +  host = params['target_host'] + +  puts "HTTPS FAILED - TODO - IMPLEMENT" +  return false +end diff --git a/worker/tests/jabber.rb b/worker/tests/jabber.rb new file mode 100644 index 0000000..5caeb5b --- /dev/null +++ b/worker/tests/jabber.rb @@ -0,0 +1,51 @@ +require 'timeout' + + +# +# Run a Jabber test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def jabber_test ( params ) + +  # +  #  Get the hostname & port to test against. +  # +  host = params['target_host'] +  port = 5222 + +  puts "Jabber testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.puts( "QUIT") + +        banner = socket.gets(nil) +        banner = banner[0,20] + +        socket.close() + +        if ( banner =~ /xml version/i ) +          puts "Jabber alive: #{banner}" +          return true +        end +      rescue +        puts "Jabber exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e +    puts "TIMEOUT: #{e}" +    return false +  end + +  return false +end diff --git a/worker/tests/ldap.rb b/worker/tests/ldap.rb new file mode 100644 index 0000000..4570f66 --- /dev/null +++ b/worker/tests/ldap.rb @@ -0,0 +1,41 @@ +require 'timeout' + + +# +# Run an LDAP test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def ldap_test ( params ) + +  # +  #  Get the hostname & port to test against. +  # +  host = params['target_host'] +  port = params['test_port'] + +  puts "LDAP testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.close() +        return true +      rescue +        puts "LDAP exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e +    puts "TIMEOUT: #{e}" +    return false +  end +  return false +end diff --git a/worker/tests/ping.rb b/worker/tests/ping.rb new file mode 100755 index 0000000..72769a6 --- /dev/null +++ b/worker/tests/ping.rb @@ -0,0 +1,36 @@ + +# +# Run a PING test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def ping_test( params ) + +  # +  # Find the binary +  # +  binary = nil +  binary = "./util/multi-ping"  if ( File.exists?( "./util/multi-ping" ) ) +  binary = "../util/multi-ping" if ( File.exists?( "../util/multi-ping" ) ) + +  if ( binary.nil? ) +    puts "Failed to find 'multi-ping'" +    exit 1 +  end + +  # +  # Is it IPv6 or IPv4a +  # +  host = params['target_host'] +  if ( system( "#{binary} #{host}" ) == true ) +    puts "PING OK" +    return  true +  else +    puts "PING FAILED" +    return false +  end +end diff --git a/worker/tests/rsync.rb b/worker/tests/rsync.rb new file mode 100644 index 0000000..2c781d8 --- /dev/null +++ b/worker/tests/rsync.rb @@ -0,0 +1,48 @@ +require 'timeout' + + +# +# Run an rsync test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def rsync_test ( params ) + +  # +  #  Get the hostname +  # +  host = params['target_host'] +  port = 873 + +  puts "rsync testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.puts( "QUIT") +        banner = socket.gets(nil) +        socket.close() + +        banner = banner[0,20] +        if ( banner =~ /rsyncd/i ) +          puts "rsync alive: #{banner}" +          return true +        end +      rescue +        puts "Exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e +    puts "TIMEOUT: #{e}" +    return false +  end +  return false +end diff --git a/worker/tests/smtp.rb b/worker/tests/smtp.rb new file mode 100644 index 0000000..66da545 --- /dev/null +++ b/worker/tests/smtp.rb @@ -0,0 +1,52 @@ +require 'timeout' + + +# +# Run an SMTP test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def smtp_test ( params ) + +  # +  #  Get the hostname & port to test against. +  # +  host = params['target_host'] +  port = 25 + +  puts "SMTP testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.puts( "QUIT\n\n") + +        banner = socket.gets(nil) +        banner = banner[0,20] + +        socket.close() + +        if ( banner =~ /SMTP/i ) +          puts "SMTP alive: #{banner}" +          return true +        end +      rescue +        puts "SMTP exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e + +    puts "SMTP TIMEOUT: #{e}" +    return false +  end +  puts "SMTP Misc Failure" +  return false +end diff --git a/worker/tests/ssh.rb b/worker/tests/ssh.rb new file mode 100755 index 0000000..4264c8e --- /dev/null +++ b/worker/tests/ssh.rb @@ -0,0 +1,50 @@ +require 'timeout' + + +# +# Run an SSH test. +# +# +# Return value +#   TRUE:  The host is up +# +#  FALSE:  The host is not up +# +def ssh_test ( params ) + +  # +  #  Get the hostname & port to test against. +  # +  host = params['target_host'] +  port = params['test_port'] + +  puts "SSH testing host #{host}:#{port}" + + +  begin +    timeout(3) do + +      begin +        socket = TCPSocket.new( host, port ) +        socket.puts( "QUIT") + +        banner = socket.gets(nil) +        banner = banner[0,20] +        socket.close() + +        if ( banner =~ /ssh/i ) +          puts "SSH alive: #{banner}" +          return true +        end +      rescue +        puts "SSH exception on host #{host}:#{port} - #{$!}" +        return false +      end +    end +  rescue Timeout::Error => e +    puts "TIMEOUT: #{e}" +    return false +  end + +  return false +end  | 
