-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathevent_transform_common.rb
52 lines (46 loc) · 1.54 KB
/
event_transform_common.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# encoding: utf-8
module LogStash module Inputs class Beats
# Base Transform class, expose the plugin decorate method,
# apply the tags and make sure we copy the beat hostname into `host`
# for backward compatibility.
class EventTransformCommon
def initialize(input)
@input = input
@logger = input.logger
end
# Copies the beat.hostname field into the host field unless
# the host field is already defined
def copy_beat_hostname(event)
host = event.get("[beat][hostname]")
if host && event.get("host").nil?
event.set("host", host)
end
end
# This break the `#decorate` method visibility of the plugin base
# class, the method is protected and we cannot access it, but well ruby
# can let you do all the wrong thing.
#
# I think the correct behavior would be to allow the plugin to return a
# `Decorator` object that we can pass to other objects, since only the
# plugin know the data used to decorate. This would allow a more component
# based workflow.
def decorate(event)
@input.send(:decorate, event)
end
def codec_name
@codec_name ||= if @input.codec.respond_to?(:base_codec)
@input.codec.base_codec.class.config_name
else
@input.codec.class.config_name
end
end
def transform(event)
copy_beat_hostname(event)
decorate(event)
event
end
def include_codec_tag?
@input.include_codec_tag
end
end
end; end; end