diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-21 23:34:23 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-21 23:34:23 +0000 |
commit | 0971310be8093ab53b430ac5a8c7217ba8bf76a9 (patch) | |
tree | 430e54909f8969f26670c7e8873696ae2666bd80 /lib/custodian | |
parent | b7608cc947bcca078644516a288a6bef67f7f09a (diff) |
Serialize and cosntruct neatly
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/protocoltest.rb | 9 | ||||
-rw-r--r-- | lib/custodian/protocoltest/ftp.rb | 19 | ||||
-rw-r--r-- | lib/custodian/protocoltest/jabber.rb | 17 | ||||
-rw-r--r-- | lib/custodian/protocoltest/rsync.rb | 17 | ||||
-rw-r--r-- | lib/custodian/protocoltest/smtp.rb | 18 | ||||
-rw-r--r-- | lib/custodian/protocoltest/ssh.rb | 18 | ||||
-rw-r--r-- | lib/custodian/protocoltest/tcp.rb | 18 |
7 files changed, 85 insertions, 31 deletions
diff --git a/lib/custodian/protocoltest.rb b/lib/custodian/protocoltest.rb index 9a843c2..1a2f796 100644 --- a/lib/custodian/protocoltest.rb +++ b/lib/custodian/protocoltest.rb @@ -30,6 +30,15 @@ class ProtocolTest # # def self.create( line ) + + # + # JSON ? + # + if ( line =~ /^\{(.*)\}$/ ) + obj = JSON.parse( line ); + line = obj["line"] + end + if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ ) test_type = $1.dup test_type.chomp!( "." ) diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb index 1d60e43..89b4a2b 100644 --- a/lib/custodian/protocoltest/ftp.rb +++ b/lib/custodian/protocoltest/ftp.rb @@ -13,6 +13,12 @@ class FTPTest < TCPTest # + # The line from which we were constructed. + # + attr_reader :line + + + # # The host to test against. # attr_reader :host @@ -26,10 +32,17 @@ class FTPTest < TCPTest + # # Constructor # def initialize( line ) + + # + # Save the line + # + @line = line + # # Save the host # @@ -62,11 +75,7 @@ class FTPTest < TCPTest # Convert this class to JSON such that it may be serialized. # def to_json - hash = { - :test_type => 'ftp', - :test_target => @host, - :test_port => @port, - } + hash = { :line => @line } hash.to_json end diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb index 1aef8b5..da400ac 100644 --- a/lib/custodian/protocoltest/jabber.rb +++ b/lib/custodian/protocoltest/jabber.rb @@ -11,6 +11,11 @@ # class JABBERTest < TCPTest + # + # The line from which we were constructed. + # + attr_reader :line + # # The host to test against. @@ -29,6 +34,12 @@ class JABBERTest < TCPTest # Constructor # def initialize( line ) + + # + # Save the line + # + @line = line + # # Save the host # @@ -61,11 +72,7 @@ class JABBERTest < TCPTest # Convert this class to JSON such that it may be serialized. # def to_json - hash = { - :test_type => 'jabber', - :test_target => @host, - :test_port => @port, - } + hash = { :line => @line } hash.to_json end diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb index c35758e..c8a2095 100644 --- a/lib/custodian/protocoltest/rsync.rb +++ b/lib/custodian/protocoltest/rsync.rb @@ -11,6 +11,11 @@ # class RSYNCTest < TCPTest + # + # The line from which we were constructed. + # + attr_reader :line + # # The host to test against. @@ -30,6 +35,12 @@ class RSYNCTest < TCPTest # Constructor # def initialize( line ) + + # + # Save the line. + # + @line = line + # # Save the host # @@ -62,11 +73,7 @@ class RSYNCTest < TCPTest # Convert this class to JSON such that it may be serialized. # def to_json - hash = { - :test_type => 'rsync', - :test_target => @host, - :test_port => @port, - } + hash = { :line => @line } hash.to_json end diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb index dce5ddf..2e1e1e6 100644 --- a/lib/custodian/protocoltest/smtp.rb +++ b/lib/custodian/protocoltest/smtp.rb @@ -13,6 +13,12 @@ class SMTPTest < TCPTest # + # The line from which we were constructed. + # + attr_reader :line + + + # # The host to test against. # attr_reader :host @@ -30,6 +36,12 @@ class SMTPTest < TCPTest # Constructor # def initialize( line ) + + # + # Save the line. + # + @line = line + # # Save the host # @@ -62,11 +74,7 @@ class SMTPTest < TCPTest # Convert this class to JSON such that it may be serialized. # def to_json - hash = { - :test_type => 'smtp', - :test_target => @host, - :test_port => @port, - } + hash = { :line => @line } hash.to_json end diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb index 18f13bc..78e8e67 100644 --- a/lib/custodian/protocoltest/ssh.rb +++ b/lib/custodian/protocoltest/ssh.rb @@ -13,6 +13,12 @@ class SSHTest < TCPTest # + # The line from which we were constructed. + # + attr_reader :line + + + # # The host to test against. # attr_reader :host @@ -31,6 +37,12 @@ class SSHTest < TCPTest # Ensure we received a port to run the test against. # def initialize( line ) + + # + # Save the line + # + @line = line + # # Save the host # @@ -64,11 +76,7 @@ class SSHTest < TCPTest # serialized. # def to_json - hash = { - :test_type => 'ssh', - :test_target => @host, - :test_port => @port - } + hash = { :line => @line } hash.to_json end diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb index 5f29b7f..9806565 100644 --- a/lib/custodian/protocoltest/tcp.rb +++ b/lib/custodian/protocoltest/tcp.rb @@ -17,6 +17,12 @@ class TCPTest < ProtocolTest # + # The input line + # + attr_reader :line + + + # # The host to test against. # attr_reader :host @@ -44,6 +50,11 @@ class TCPTest < ProtocolTest def initialize( line ) # + # Save the line + # + @line = line + + # # Save the host # @host = line.split( /\s+/)[0] @@ -90,12 +101,7 @@ class TCPTest < ProtocolTest # Convert this class to JSON such that it may be serialized. # def to_json - hash = { - :test_type => 'tcp', - :test_target => @host, - :test_port => @port, - :banner => @banner - } + hash = { :line => @line } hash.to_json end |