logstash-codec-transit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/README.md +25 -0
- data/Rakefile +7 -0
- data/lib/logstash/codecs/transit.rb +51 -0
- data/logstash-codec-transit.gemspec +27 -0
- data/spec/codecs/transit_spec.rb +63 -0
- data/spec/test-codec.conf +15 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce040e485956a2c8925d9b88eb5756b7de0a4857
|
4
|
+
data.tar.gz: 2dd9f9b78f0b041a18bd6346c1d5d31353600b45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30230d37f665cf9e64e148980a3143683c921545aa3ba0a5d307b5df1f13bfd5a71e795cf0a4fe972ddf48e689db1611384a5715b7ade41be1890f4ec7104aa2
|
7
|
+
data.tar.gz: f0dff14b3816e425cac503a00a62df7d855ebc6b37964ac30a01efadb451f3455ece87cf1a6d235aaa594adea3fe1e7c3e23c695f1738869612d4e4f7e04bccd
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7.21
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Agents' Mutual <http://www.agentsmutual.co.uk>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Logstash Transit Plugin
|
2
|
+
|
3
|
+
A codec for logstash that encodes and decodes messages being sent using the [transit](http://github.com/cognitect/transit-format) format.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
`$LOGSTASH_HOME/bin/plugin install transit`
|
8
|
+
|
9
|
+
## Configure
|
10
|
+
|
11
|
+
The transport parameter can be either `json` (default) or `msgpack`. There is
|
12
|
+
also an option to base64 encode/decode the messages (defaults to `false`).
|
13
|
+
|
14
|
+
|
15
|
+
### Example configuration
|
16
|
+
```
|
17
|
+
input {
|
18
|
+
stdin {
|
19
|
+
codec => transit {
|
20
|
+
transport => json
|
21
|
+
base64 => false
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/codecs/base"
|
3
|
+
require "logstash/timestamp"
|
4
|
+
require "logstash/util"
|
5
|
+
|
6
|
+
class LogStash::Codecs::Transit < LogStash::Codecs::Base
|
7
|
+
config_name "transit"
|
8
|
+
|
9
|
+
# Underlying transport to be used. Valid values are 'json' or 'msgpack'
|
10
|
+
config :transport, :validate => :string, :default => 'json'
|
11
|
+
# Whether messages are base64 encoded or not
|
12
|
+
config :base64, :validate => :boolean, :default => false
|
13
|
+
|
14
|
+
public
|
15
|
+
def register
|
16
|
+
require "transit"
|
17
|
+
require "base64" if @base64
|
18
|
+
end
|
19
|
+
|
20
|
+
public
|
21
|
+
def decode(data)
|
22
|
+
begin
|
23
|
+
data = Base64.decode64(data) if @base64
|
24
|
+
io = StringIO.new data
|
25
|
+
reader = Transit::Reader.new(@transport.to_sym, io)
|
26
|
+
event = LogStash::Event.new(reader.read)
|
27
|
+
event["tags"] ||= []
|
28
|
+
rescue => e
|
29
|
+
@logger.warn("Trouble parsing transit input, falling back to plain text",
|
30
|
+
:input => data, :exception => e)
|
31
|
+
event = LogStash::Event.new("") unless event
|
32
|
+
event["message"] = data
|
33
|
+
event["tags"] ||= []
|
34
|
+
event["tags"] << "_transitparsefailure"
|
35
|
+
end
|
36
|
+
yield event
|
37
|
+
end
|
38
|
+
|
39
|
+
public
|
40
|
+
def encode(event)
|
41
|
+
data = LogStash::Util.normalize(event.to_hash)
|
42
|
+
io = StringIO.new
|
43
|
+
writer = Transit::Writer.new(@transport.to_sym, io)
|
44
|
+
writer.write(data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601))
|
45
|
+
|
46
|
+
encoded = io.string
|
47
|
+
encoded = Base64.encode64(encoded) if @base64
|
48
|
+
@on_event.call(event, encoded)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-transit'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "Encode and decode transit formatted data"
|
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 transit. This gem is not a stand-alone program"
|
8
|
+
s.authors = ["Elastic"]
|
9
|
+
s.email = 'info@elastic.co'
|
10
|
+
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
|
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 "transit-ruby"
|
25
|
+
|
26
|
+
s.add_development_dependency 'logstash-devutils'
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/codecs/transit"
|
4
|
+
require "logstash/event"
|
5
|
+
require "insist"
|
6
|
+
|
7
|
+
describe LogStash::Codecs::Transit do
|
8
|
+
def codec_test
|
9
|
+
data = {"foo" => "bar", "baz" => {"bah" => ["a","b","c"]}, "date" => DateTime.new(2015,2,3)}
|
10
|
+
event = LogStash::Event.new(data)
|
11
|
+
encoded = nil
|
12
|
+
subject.on_event do |e, d|
|
13
|
+
encoded = d
|
14
|
+
got_event = true
|
15
|
+
end
|
16
|
+
subject.encode(event)
|
17
|
+
insist { got_event }
|
18
|
+
|
19
|
+
subject.decode(encoded) do |event|
|
20
|
+
insist { event.is_a? LogStash::Event }
|
21
|
+
insist { event["foo"] } == data["foo"]
|
22
|
+
insist { event["baz"] } == data["baz"]
|
23
|
+
insist { event["bah"] } == data["bah"]
|
24
|
+
insist { event["date"] } == data["date"]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "msgpack" do
|
29
|
+
subject do
|
30
|
+
LogStash::Codecs::Transit.new("transport" => "msgpack")
|
31
|
+
end
|
32
|
+
|
33
|
+
context "encode + decode" do
|
34
|
+
it "should return an event from transit data" do
|
35
|
+
codec_test
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "json" do
|
41
|
+
subject do
|
42
|
+
LogStash::Codecs::Transit.new("transport" => "json")
|
43
|
+
end
|
44
|
+
|
45
|
+
context "encode + decode" do
|
46
|
+
it "should return an event from transit data" do
|
47
|
+
codec_test
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "base64 msgpack" do
|
53
|
+
subject do
|
54
|
+
LogStash::Codecs::Transit.new("transport" => "msgpack", "base64" => true)
|
55
|
+
end
|
56
|
+
|
57
|
+
context "encode + decode" do
|
58
|
+
it "should return an event from transit data" do
|
59
|
+
codec_test
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-codec-transit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - '>='
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 1.4.0
|
19
|
+
- - <
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
name: logstash-core
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
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
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
name: transit-ruby
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
name: logstash-devutils
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
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 transit. This gem is not a stand-alone program
|
62
|
+
email: info@elastic.co
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- .gitignore
|
68
|
+
- .ruby-version
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/logstash/codecs/transit.rb
|
74
|
+
- logstash-codec-transit.gemspec
|
75
|
+
- spec/codecs/transit_spec.rb
|
76
|
+
- spec/test-codec.conf
|
77
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
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.8
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Encode and decode transit formatted data
|
103
|
+
test_files:
|
104
|
+
- spec/codecs/transit_spec.rb
|
105
|
+
- spec/test-codec.conf
|