<NME> agent.rb
<BEF> ADDFILE
<MSG> - Add LogStash::Net::MessageClientConnectionReset
- Add LogStash::Net::NoSocket
- Add special 'signal' socketpair that is always used in select() as a reader
  so that we can, from sendmsg(), notify select() that we should end and loop
  again
- MessageSocketMux#connect now returns true if the connection succeeded. An
  exception is thrown otherwise.
- Only include writers who have populated output streams.
- If we had a client receiver (via #connect(..)) before, but it went away,
  assume the connection was destroyed/reset by some other means and that this is
  an error to be handled by the client.
- Don't immediately add a socket to the @writers list when it's created.
- If _sendmsg has a socket that is nil, raise NoSocket. If _sendmsg is called
  with a nil socket, and @receiver (created through #connect(...)) is also nil,
  this is an error and we throw NoSocket.
- Delete @receiver if it is a socket that is being removed.
- Delete socket from @writers once we flush it's data out the socket.
- Raise MessageClientConnectionReset on EOF/IOError or ECONNRESET
- indexer: Sync index every 60 seconds
- Add alpha version of Agent. It watches /var/log/messages.

Tested:
  - Both the agent and indexer server are capable of recovering from disconnections.
  - searcher test code (sandbox/searchclient.rb) works while Agent is feeding
    the indexer


<DFF> @@ -0,0 +1,92 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'lib/net/client'
+require 'lib/net/messages/indexevent'
+require 'socket'
+
+
+class Agent < LogStash::Net::MessageClient
+  def initialize(host, port)
+    super()
+    @hostname = Socket.gethostname
+    @host = host
+    @port = port
+    @watcher = nil
+    start_log_watcher
+  end # def initialize
+
+  def start_log_watcher
+    Thread.new do
+      IO.popen("tail -0f /var/log/messages", "r") do |fd|
+        fd.each do |line|
+          puts "Found line: #{line}"
+          line.chomp!
+          index(line)
+        end
+      end
+    end
+  end # def start_log_watcher
+
+  def index(string)
+    ier = LogStash::Net::Messages::IndexEventRequest.new
+    ier.log_type = "linux-syslog"
+    ier.log_data = string
+    ier.metadata["source_host"] = @hostname
+
+    sent = false
+    while !sent
+      begin
+        puts "Trying to send: #{ier.inspect}"
+        sendmsg(ier)
+        sent = true
+      rescue LogStash::Net::NoSocket
+        # No client connection available, wait.
+        puts "No client connection available to send on, sleeping..."
+        sleep 1
+      end
+    end
+  end # def index
+
+  def IndexEventResponseHandler(msg)
+    if msg.success?
+    end
+  end # def IndexEventResponseHandler
+
+  def run
+    loop do
+      puts @done
+      done = false
+      while !done
+        begin
+          done = connect(@host, @port); 
+        rescue Errno::ECONNREFUSED => e
+          puts "Connection to #{@host}:#{@port} failed: #{e}"
+          puts "Sleeping for retry."
+          sleep 1
+        end
+      end
+      puts "Connection OK"
+
+      begin
+        loop do
+          sendrecv(nil)
+        end
+      rescue LogStash::Net::MessageClientConnectionReset
+        puts "Connection died, retrying..."
+      end
+    end
+  end # def run
+
+end
+
+
+if $0 == __FILE__
+  if ARGV.length == 0
+    puts "Usage: #{$0} host:port"
+    exit 1
+  end
+  host, port = ARGV[0].split(":")
+  agent = Agent.new(host, port)
+  agent.run
+end

- Add LogStash::Net::MessageClientConnectionReset - Add LogStash::Net::NoSocket - Add special 'signal' socketpair that is always used in select() as a reader   so that we can, from sendmsg(), notify select() that we should end and loop   again - MessageSocketMux#connect now returns true if the connection succeeded. An   exception is thrown otherwise. - Only include writers who have populated output streams. - If we had a client receiver (via #connect(..)) before, but it went away,   assume the connection was destroyed/reset by some other means and that this is   an error to be handled by the client. - Don't immediately add a socket to the @writers list when it's created. - If _sendmsg has a socket that is nil, raise NoSocket. If _sendmsg is called   with a nil socket, and @receiver (created through #connect(...)) is also nil,   this is an error and we throw NoSocket. - Delete @receiver if it is a socket that is being removed. - Delete socket from @writers once we flush it's data out the socket. - Raise MessageClientConnectionReset on EOF/IOError or ECONNRESET - indexer: Sync index every 60 seconds - Add alpha version of Agent. It watches /var/log/messages.