logstash-codec-protobuf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -4
- data/CONTRIBUTORS +3 -8
- data/LICENSE +1 -1
- data/NOTICE.TXT +1 -2
- data/README.md +7 -7
- data/lib/logstash/codecs/protobuf.rb +45 -73
- data/logstash-codec-protobuf.gemspec +3 -2
- data/spec/codecs/protobuf_spec.rb +4 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92231ace59a2a8218764c99dab51abb5636db440
|
4
|
+
data.tar.gz: d8129bf3a5bf757f42bb3c2e95ae8d74455531b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7379eeb8a33c4dd722a01e55bd67f5daeb37ba7ad323ebd41707b359f27a585ca5dcaaf720ecb74d6746c50230fda17249ef849ff3f01489714dbd9c286769
|
7
|
+
data.tar.gz: d2175a9b628f60128295e9e4871d895ba8cb65d33202af0a3c66ac63c0aa4540a173b3b7c508f28de8db3d950f4b72604e308d5138530a79393144244c5188a1
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTORS
CHANGED
@@ -2,14 +2,9 @@ The following is a list of people who have contributed ideas, code, bug
|
|
2
2
|
reports, or in general have helped logstash along its way.
|
3
3
|
|
4
4
|
Contributors:
|
5
|
-
*
|
6
|
-
*
|
7
|
-
|
8
|
-
* Kurt Hurtado (kurtado)
|
9
|
-
* Nick Ethier (nickethier)
|
10
|
-
* Pier-Hugues Pellerin (ph)
|
11
|
-
* Richard Pijnenburg (electrical)
|
12
|
-
* Tal Levy (talevy)
|
5
|
+
* Inga Feick (ingafeick)
|
6
|
+
* Nicolai Schulten (krakenfuss)
|
7
|
+
|
13
8
|
|
14
9
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
15
10
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/LICENSE
CHANGED
data/NOTICE.TXT
CHANGED
data/README.md
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
This is a codec plugin for [Logstash](https://github.com/elastic/logstash) to parse protobuf messages.
|
4
4
|
|
5
|
-
# Prerequisites
|
5
|
+
# Prerequisites and Installation
|
6
6
|
|
7
7
|
* prepare your ruby versions of the protobuf definitions, for example using the ruby-protoc compiler from https://github.com/codekitchen/ruby-protocol-buffers
|
8
|
-
* download the logstash-codec-protobuf
|
8
|
+
* download the [gem file](https://rubygems.org/gems/logstash-codec-protobuf) to your computer.
|
9
9
|
* Install the plugin. From within your logstash directory, do
|
10
10
|
bin/plugin install /path/to/logstash-codec-protobuf-$VERSION.gem
|
11
11
|
* use the codec in your logstash config file. See details below.
|
12
12
|
|
13
|
-
|
13
|
+
## Usage
|
14
14
|
|
15
15
|
Use this as a codec in any logstash input. Just provide the name of the class that your incoming objects will be encoded in, and specify the path to the compiled definition.
|
16
16
|
Here's an example for a kafka input:
|
@@ -46,20 +46,20 @@ Set the class name to the parent class:
|
|
46
46
|
|
47
47
|
class_name => "Foods::Dairy::Cheese"
|
48
48
|
|
49
|
-
|
49
|
+
## Configuration
|
50
50
|
|
51
51
|
include_path (required): an array of strings with filenames or directory names where logstash can find your protobuf definitions. Please provide absolute paths. For directories it will only try to import files ending on .rb
|
52
52
|
|
53
53
|
class_name (required): the name of the protobuf class that is to be decoded.
|
54
54
|
|
55
55
|
|
56
|
-
|
56
|
+
## Troubleshooting
|
57
57
|
|
58
|
-
|
58
|
+
### "uninitialized constant SOME_CLASS_NAME"
|
59
59
|
|
60
60
|
If you include more than one definition class, consider the order of inclusion. This is especially relevant if you include whole directories. A definition might refer to another definition that is not loaded yet. In this case, please specify the files in the include_path variable in reverse order of reference. See 'Example with referenced definitions' above.
|
61
61
|
|
62
62
|
|
63
|
-
#
|
63
|
+
# #Roadmap
|
64
64
|
|
65
65
|
Currently the plugin supports the decode functionality only. Maybe we'll add the encoding part also.
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'logstash/codecs/base'
|
3
|
+
require 'logstash/util/charset'
|
4
4
|
require 'protocol_buffers' # https://github.com/codekitchen/ruby-protocol-buffers
|
5
5
|
|
6
6
|
class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
|
7
|
-
config_name
|
7
|
+
config_name 'protobuf'
|
8
8
|
|
9
9
|
# Required: list of strings containing directories or files with protobuf definitions
|
10
10
|
config :include_path, :validate => :array, :required => true
|
@@ -12,100 +12,72 @@ class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
|
|
12
12
|
# Name of the class to decode
|
13
13
|
config :class_name, :validate => :string, :required => true
|
14
14
|
|
15
|
-
# remove 'set_fields' field
|
16
|
-
config :remove_set_fields, :validate => :boolean, :default => true # TODO add documentation
|
17
|
-
|
18
15
|
|
19
|
-
public
|
20
16
|
def register
|
21
|
-
|
22
|
-
@obj = create_object_from_name(
|
23
|
-
|
17
|
+
include_path.each { |path| require_pb_path(path) }
|
18
|
+
@obj = create_object_from_name(class_name)
|
19
|
+
@logger.debug("Protobuf files successfully loaded.")
|
24
20
|
end
|
25
21
|
|
22
|
+
def decode(data)
|
23
|
+
decoded = @obj.parse(data.to_s)
|
24
|
+
results = extract_vars(decoded)
|
25
|
+
yield LogStash::Event.new(results) if block_given?
|
26
|
+
end # def decode
|
27
|
+
|
28
|
+
def encode(event)
|
29
|
+
raise 'Encodeør function not implemented yet for protobuf codec. Sorry!'
|
30
|
+
# @on_event.call(event, event.to_s)
|
31
|
+
# TODO integrate
|
32
|
+
end # def encode
|
33
|
+
|
34
|
+
|
26
35
|
|
27
36
|
private
|
28
37
|
def create_object_from_name(name)
|
29
38
|
begin
|
30
|
-
|
31
|
-
return c
|
32
|
-
|
39
|
+
@logger.debug("Creating instance of " + name)
|
40
|
+
return name.split('::').inject(Object) { |n,c| n.const_get c }
|
41
|
+
end
|
33
42
|
end
|
34
43
|
|
35
|
-
private
|
36
|
-
def debug(message)
|
37
|
-
begin
|
38
|
-
if @debug
|
39
|
-
@logger.debug(message)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
44
|
|
44
|
-
private
|
45
45
|
def require_pb_path(dir_or_file)
|
46
|
-
f = dir_or_file.end_with? (
|
46
|
+
f = dir_or_file.end_with? ('.rb')
|
47
47
|
begin
|
48
48
|
if f
|
49
|
+
@logger.debug("Including protobuf file: " + dir_or_file)
|
49
50
|
require dir_or_file
|
50
51
|
else
|
51
|
-
Dir[ dir_or_file +
|
52
|
+
Dir[ dir_or_file + '/*.rb'].each { |file|
|
53
|
+
@logger.debug("Including protobuf path: " + dir_or_file + "/" + file)
|
52
54
|
require file
|
53
55
|
}
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
decoded_object.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
tmp = []
|
75
|
-
value.each do | nested |
|
76
|
-
tmp.push(nested)
|
77
|
-
end
|
78
|
-
result_hash[key] = tmp
|
60
|
+
|
61
|
+
def extract_vars(decoded_object)
|
62
|
+
return {} if decoded_object.nil?
|
63
|
+
results = {}
|
64
|
+
decoded_object.instance_variables.each do |key|
|
65
|
+
formatted_key = key.to_s.gsub('@', '')
|
66
|
+
next if (formatted_key == :set_fields || formatted_key == "set_fields")
|
67
|
+
instance_var = decoded_object.instance_variable_get(key)
|
68
|
+
|
69
|
+
results[formatted_key] =
|
70
|
+
if instance_var.is_a?(::ProtocolBuffers::Message)
|
71
|
+
extract_vars(instance_var)
|
72
|
+
elsif instance_var.is_a?(::Hash)
|
73
|
+
instance_var.inject([]) { |h, (k, v)| h[k.to_s] = extract_vars(v); h }
|
74
|
+
elsif instance_var.is_a?(Enumerable) # is a list
|
75
|
+
instance_var.inject([]) { |h, v| h.push(extract_vars(v)); h }
|
79
76
|
else
|
80
|
-
|
77
|
+
instance_var
|
81
78
|
end
|
82
|
-
|
83
|
-
|
84
|
-
return result_hash.except("set_fields") # todo try to do this before the object is handed to this method
|
85
|
-
else
|
86
|
-
return result_hash
|
87
|
-
end
|
88
|
-
end
|
79
|
+
end
|
80
|
+
results
|
89
81
|
end
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
public
|
96
|
-
def decode(data)
|
97
|
-
decoded = @obj.parse(data.to_s)
|
98
|
-
results = extract_variables(decoded)
|
99
|
-
event = LogStash::Event.new(results)
|
100
|
-
yield event
|
101
|
-
|
102
|
-
end # def decode
|
103
|
-
|
104
|
-
public
|
105
|
-
def encode(event)
|
106
|
-
raise "Encoder function not implemented yet for protobuf codec. Sorry!"
|
107
|
-
# @on_event.call(event, event.to_s)
|
108
|
-
# TODO integrate
|
109
|
-
end # def encode
|
110
|
-
|
111
83
|
end # class LogStash::Codecs::Protobuf
|
@@ -1,11 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-protobuf'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.1'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This codec may be used to decode (via inputs) and encode (via outputs) protobuf messages"
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
8
|
-
s.authors = ["
|
8
|
+
s.authors = ["Inga Feick"]
|
9
|
+
s.email = 'inga.feick@trivago.com'
|
9
10
|
s.require_paths = ["lib"]
|
10
11
|
|
11
12
|
# Files
|
@@ -17,14 +17,12 @@ describe LogStash::Codecs::Protobuf do
|
|
17
17
|
|
18
18
|
data = {:colour => 'rainbow', :horn_length => 18, :last_seen => 1420081471}
|
19
19
|
unicorn = Animal::Unicorn.new(data)
|
20
|
-
|
20
|
+
|
21
21
|
plugin.decode(unicorn.serialize_to_string) do |event|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
insist { event["last_seen"] } == data[:last_seen]
|
22
|
+
|
23
|
+
expect(event["colour"] ).to eq(data[:colour] )
|
24
|
+
expect(event["horn_length"] ).to eq(data[:horn_length] )
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
|
-
|
30
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Inga Feick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
prerelease: false
|
60
60
|
type: :development
|
61
61
|
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
62
|
-
email:
|
62
|
+
email: inga.feick@trivago.com
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
65
65
|
extra_rdoc_files: []
|