Skip to content

Instantly share code, notes, and snippets.

@vmadman
Last active December 28, 2015 12:49
Show Gist options
  • Select an option

  • Save vmadman/7503376 to your computer and use it in GitHub Desktop.

Select an option

Save vmadman/7503376 to your computer and use it in GitHub Desktop.

Revisions

  1. vmadman revised this gist Nov 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion logio.rb
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    class LogStash::Outputs::LogIO < LogStash::Outputs::Base

    config_name "logio"
    plugin_status "experimental"
    plugin_status 0

    # log.io server host
    config :host, :validate => :string, :required => true
  2. vmadman revised this gist Nov 16, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions logio.rb
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,10 @@
    # Plugin is fault tolerant. If the plugin is unable to connect to the server,
    # or writes to a broken socket, it will attempt to reconnect indefinitely.
    #
    # This logstash plugin was converted to a gist by Luke Chavers <github.com/vmadman>
    # Source was taken from: https://github.com/msmathers/logstash/blob/develop/log.io/lib/logstash/outputs/logio.rb
    # See also: http://narrativescience.com/blog/announcing-the-new-log-io/
    #
    class LogStash::Outputs::LogIO < LogStash::Outputs::Base

    config_name "logio"
  3. vmadman created this gist Nov 16, 2013.
    57 changes: 57 additions & 0 deletions logio.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    require "logstash/outputs/base"
    require "logstash/namespace"
    require "socket"

    # Log.io Output
    #
    # Sends events to a Log.io server over TCP.
    #
    # Plugin is fault tolerant. If the plugin is unable to connect to the server,
    # or writes to a broken socket, it will attempt to reconnect indefinitely.
    #
    class LogStash::Outputs::LogIO < LogStash::Outputs::Base

    config_name "logio"
    plugin_status "experimental"

    # log.io server host
    config :host, :validate => :string, :required => true

    # log.io server TCP port
    config :port, :validate => :number, :default => 28777

    # log.io TCP message format
    config :format, :default => "+log|%{@source}|%{@source_host}|%{@level}|%{@timestamp}: %{@message}\r\n"

    public
    def register
    connect
    end

    public
    def receive(event)
    return unless output?(event)
    msg = event.sprintf(@format)
    send_log(msg)
    end

    private
    def connect
    begin
    @sock = TCPSocket.open(@host, @port)
    rescue
    sleep(2)
    connect
    end
    end

    private
    def send_log(msg)
    begin
    @sock.puts msg
    rescue
    sleep(2)
    connect
    end
    end
    end