Sha256: 61be90deb9b5d090076d3d4ab7209587342d047375881a71d2f9ccf88aa2ea56

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

# encoding: utf-8
require "logstash/inputs/base"
require "logstash/namespace"
require "stud/interval"
require "socket" # for Socket.gethostname

# Generate a repeating message.
#
# This plugin is intented only as an example.

class LogStash::Inputs::Example < LogStash::Inputs::Base
  config_name "example"

  # If undefined, Logstash will complain, even if codec is unused.
  default :codec, "plain"

  # The message string to use in the event.
  config :message, :validate => :string, :default => "Hello World!"

  # Set how frequently messages should be sent.
  #
  # The default, `1`, means send a message every second.
  config :interval, :validate => :number, :default => 1

  public
  def register
    @host = Socket.gethostname
  end # def register

  def run(queue)
    # we can abort the loop if stop? becomes true
    while !stop?
      event = LogStash::Event.new("message" => @message, "host" => @host)
      decorate(event)
      queue << event
      # because the sleep interval can be big, when shutdown happens
      # we want to be able to abort the sleep
      # Stud.stoppable_sleep will frequently evaluate the given block
      # and abort the sleep(@interval) if the return value is true
      Stud.stoppable_sleep(@interval) { stop? }
    end # loop
  end # def run

  def stop
    # nothing to do in this case so it is not necessary to define stop
    # examples of common "stop" tasks:
    #  * close sockets (unblocking blocking reads/accepts)
    #  * cleanup temporary files
    #  * terminate spawned threads
  end
end # class LogStash::Inputs::Example

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
logstash-input-attunity-metrics-1.0.1 lib/logstash/inputs/example.rb
logstash-input-attunity-metrics-1.0.0 lib/logstash/inputs/example.rb
logstash-input-example-2.0.7 lib/logstash/inputs/example.rb
logstash-input-example-2.0.5 lib/logstash/inputs/example.rb
logstash-input-thisisonlyatest-2.0.2 lib/logstash/inputs/example.rb
logstash-input-thisisonlyatest-1.0.3 lib/logstash/inputs/example.rb
logstash-input-thisisonlyatest-2.0.0 lib/logstash/inputs/example.rb
logstash-input-example-2.0.3 lib/logstash/inputs/example.rb
logstash-input-example-2.0.2 lib/logstash/inputs/example.rb