Class: LogStash::Inputs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/inputs/base.rb

Direct Known Subclasses

Amqp, Beanstalk, File, Internal, Redis, Stdin, Stomp, Syslog, Tcp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, type, config = {}, &block) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/logstash/inputs/base.rb', line 10

def initialize(url, type, config={}, &block)
  @logger = LogStash::Logger.new(STDERR)
  @url = url
  @url = URI.parse(url) if url.is_a? String
  @config = config
  @callback = block
  @type = type
  @tags = []

  @urlopts = {}
  if @url.query
    @urlopts = CGI.parse(@url.query)
    @urlopts.each do |k, v|
      @urlopts[k] = v.last if v.is_a?(Array)
    end
  end
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/logstash/inputs/base.rb', line 7

def logger
  @logger
end

Instance Method Details

#receive(event) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/logstash/inputs/base.rb', line 39

def receive(event)
  @logger.debug(["Got event", { :url => @url, :event => event }])
  # Only override the type if it doesn't have one
  event.type = @type if !event.type 
  event.tags |= @tags # set union
  @callback.call(event)
end

#registerObject



29
30
31
# File 'lib/logstash/inputs/base.rb', line 29

def register
  raise "#{self.class}#register must be overidden"
end

#tag(newtag) ⇒ Object



34
35
36
# File 'lib/logstash/inputs/base.rb', line 34

def tag(newtag)
  @tags << newtag
end