logstash-codec-thrift 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee6ee6cc8ec8d720b7910442c5ed7dc8a440742c
4
+ data.tar.gz: b02e5490937476c9eb152c2fcd78b0e6c7b8c89d
5
+ SHA512:
6
+ metadata.gz: 6a418f2bf9254f31b4160305dfec168c3689135f1b300183524623f99743ea7c343669306f8d0fa4f24307f4686314bfb7a8f28fb53bf1e886b786f610bac434
7
+ data.tar.gz: 22e46011821616d46eea3de80bb7165dcd454bf58ddcc2ec47f09de3b0a3974ca056b31ccad8d27826d439193fc46cb051f92f2b5e261e1db37c4dc4385ed32b
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Logstash Codec Thrift
2
+
3
+ ## Install
4
+
5
+ $ ./bin/plugin install logstash-codec-thrift
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ input {
11
+ zeromq {
12
+ codec => thrift {
13
+ classname => "example_thrift_class"
14
+ file => "/path/to/your/thrift/gen/ruby/example_thrift_class_types.rb"
15
+ protocol_factory => "JsonProtocolFactory" # optional, defalut: BinaryProtocolFactory
16
+ }
17
+ }
18
+ }
19
+ ```
20
+
21
+ ## Install dependencies
22
+
23
+ Install jruby:
24
+
25
+ $ brew install jruby
26
+
27
+ Install jruby bundler:
28
+
29
+ $ jruby -S gem install bundler
30
+
31
+ Install plugin dependencies:
32
+
33
+ $ jruby -S bundler install
34
+
35
+ ## Build & Install
36
+
37
+ Build Gem:
38
+
39
+ $ gem build logstash-codec-thrift.gemspec
40
+
41
+ Install Gem:
42
+
43
+ $ ./bin/plugin install /your/local/plugin/logstash-codec-thrift.gem
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,32 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.2)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+
9
+ class ThriftEvent
10
+ include ::Thrift::Struct, ::Thrift::Struct_Union
11
+ TIMESTAMP = 1
12
+ VERSION = 2
13
+ HOST = 3
14
+ MESSAGE = 4
15
+
16
+ FIELDS = {
17
+ TIMESTAMP => {:type => ::Thrift::Types::STRING, :name => 'timestamp'},
18
+ VERSION => {:type => ::Thrift::Types::STRING, :name => 'version'},
19
+ HOST => {:type => ::Thrift::Types::STRING, :name => 'host', :optional => true},
20
+ MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message', :optional => true}
21
+ }
22
+
23
+ def struct_fields; FIELDS; end
24
+
25
+ def validate
26
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field timestamp is unset!') unless @timestamp
27
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field version is unset!') unless @version
28
+ end
29
+
30
+ ::Thrift::Struct.generate_accessors self
31
+ end
32
+
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+ require "logger"
3
+ require "logstash/codecs/base"
4
+ require "logstash/namespace"
5
+ require "logstash/timestamp"
6
+ require "thrift"
7
+ require "logstash/codecs/thrift-event"
8
+
9
+ # Read serialized Thrift records as Logstash events
10
+ #
11
+ # This plugin is used to serialize Logstash events as
12
+ # Thrift objects, as well as deserializing Thrift objects into
13
+ # Logstash events.
14
+ #
15
+ # ==== Encoding
16
+ #
17
+ # This codec is for serializing individual Logstash events as Thrift.
18
+ #
19
+ #
20
+ # ==== Decoding
21
+ #
22
+ # This codec is for deserializing individual Thrift serialized objects as Logstash events.
23
+ #
24
+ #
25
+ # ==== Usage
26
+ # Example usage with 0mq input.
27
+ #
28
+ # [source,ruby]
29
+ # ----------------------------------
30
+ # input {
31
+ # zeromq {
32
+ # codec => thrift {
33
+ # classname => "example_class"
34
+ # file => "~/example_class.rb"
35
+ # protocol_factory => "JsonProtocolFactory"
36
+ # }
37
+ # }
38
+ # }
39
+ # filter {
40
+ # ...
41
+ # }
42
+ # output {
43
+ # ...
44
+ # }
45
+ # ----------------------------------
46
+ class LogStash::Codecs::Thrift < LogStash::Codecs::Base
47
+
48
+ config_name "thrift"
49
+
50
+ # class name to serialize/deserialize against
51
+ config :classname, :validate => :string, :required => true
52
+
53
+ # file defining @classname
54
+ config :file, :validate => :string, :required => true
55
+
56
+ # protocol factory to use for serialization/deserialization
57
+ #
58
+ # see http://www.rubydoc.info/gems/thrift/latest/Thrift/Serializer for more info
59
+ config :protocol_factory, :validate => :string, :required => false, :default => "BinaryProtocolFactory"
60
+
61
+ public
62
+ def register
63
+ @logger.info("Initializing logstash thrift codec for class: " + @classname)
64
+ require @file
65
+ @clazz = Object.const_get(@classname.capitalize)
66
+ @protocolFactory = Thrift.const_get(@protocol_factory)
67
+ @logger.info("Done initializing logstash thrift codec!")
68
+ end
69
+
70
+ public
71
+ def decode(data)
72
+ deserializer = Thrift::Deserializer.new(@protocolFactory.new)
73
+ yield LogStash::Event.new(as_hash(deserializer.deserialize(@clazz.new, data)))
74
+ end
75
+
76
+ public
77
+ def encode(event)
78
+ serializer = Thrift::Serializer.new(@protocolFactory.new)
79
+ thriftEvent = ThriftEvent.new
80
+ thriftEvent.timestamp = event["@timestamp"].to_s
81
+ thriftEvent.version = event["@version"]
82
+ thriftEvent.host = event["host"]
83
+ thriftEvent.message = event["message"]
84
+ @on_event.call(event, serializer.serialize(thriftEvent))
85
+ end
86
+
87
+ private
88
+ def as_hash(obj)
89
+ hash = {}
90
+ obj.instance_variables.each { |var|
91
+ key = var.to_s.delete("@")
92
+ value = obj.instance_variable_get(var)
93
+ if value.is_a?(Array)
94
+ hash[key] = []
95
+ value.each do |elem|
96
+ if elem.is_a?(Array) || elem.is_a?(Object)
97
+ hash[key].push(as_hash(elem))
98
+ else
99
+ hash[key].push(elem)
100
+ end
101
+ end
102
+ else
103
+ hash[key] = value
104
+ end
105
+ }
106
+ hash
107
+ end
108
+
109
+ end
@@ -0,0 +1,6 @@
1
+ struct event {
2
+ 1: required string timestamp, #timestamp as iso8601
3
+ 2: required string version,
4
+ 3: optional string host,
5
+ 4: optional string message
6
+ }
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-thrift'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "This example input streams a string at a definable interval."
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 = ["Active Agent AG"]
9
+ s.email = 'dev@active-agent.com'
10
+ s.homepage = "http://active-agent.com"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 2.0.0'
24
+ s.add_runtime_dependency 'thrift'
25
+
26
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.15'
27
+
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-thrift
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Active Agent AG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: thrift
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.15
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.15
61
+ description: This gem is a logstash plugin required to be installed on top of the
62
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
63
+ a stand-alone program
64
+ email: dev@active-agent.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - lib/logstash/codecs/thrift-event.rb
74
+ - lib/logstash/codecs/thrift.rb
75
+ - lib/thrift/event.thrift
76
+ - logstash-codec-thrift.gemspec
77
+ homepage: http://active-agent.com
78
+ licenses:
79
+ - Apache License (2.0)
80
+ metadata:
81
+ logstash_plugin: 'true'
82
+ logstash_group: codec
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: This example input streams a string at a definable interval.
103
+ test_files: []