fluent-plugin-json-in-json 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 +17 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/fluent-plugin-json-in-json.gemspec +20 -0
- data/lib/fluent/plugin/parser_json_in_json.rb +46 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22d02005d2dde79e0ef7c01b4db06b6076a06468
|
4
|
+
data.tar.gz: 3f36a2d94fa601d30b4635a0a18b439ce249c6a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b18ba7f61d62fe002539ed24d1c8dd3dc6292306495aabdc86c5e5f50010446b05ac225438e87619f6bd0056e8b3881822d3c3f45d3870aa84ee9f8c6c6ccf27
|
7
|
+
data.tar.gz: ff7cb945fcc1d6e21c2d170b0a9064b19076be387e7df89c3489fb2b3201a24fe12c1c15111e68aac52e99ff9b7b362a3294c5e873a247a4310bac32ad7e3ed5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# fluent-plugon-json-in-json
|
2
|
+
|
3
|
+
This fluentd parser plugin parses JSON log lines with nested JSON strings. For
|
4
|
+
example, given a docker log of ``{"log": "{\"foo\": \"bar\"}"}, the log record
|
5
|
+
will be parsed into ``{:log => { :foo => "bar" }}``.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'fluent-plugin-json-in-json'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-json-in-json
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
<source>
|
26
|
+
type tail
|
27
|
+
path /var/lib/docker/containers/*/*-json.log
|
28
|
+
pos_file /var/log/fluentd-docker.pos
|
29
|
+
time_format %Y-%m-%dT%H:%M:%S
|
30
|
+
tag docker.*
|
31
|
+
format json_in_json
|
32
|
+
read_from_head true
|
33
|
+
</source>
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "fluent-plugin-json-in-json"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["Gavin M. Roy"]
|
6
|
+
spec.email = ["gavinmroy@gmail.com"]
|
7
|
+
spec.description = %q{Parser plugin that parses JSON attributes with JSON strings in them}
|
8
|
+
spec.summary = %q{Parser plugin that parses JSON attributes with JSON strings in them}
|
9
|
+
spec.homepage = "https://github.com/gmr/fluent-plugin-json-in-json"
|
10
|
+
spec.license = "BSD"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "yajl-ruby", "~> 1.0"
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class TextParser
|
5
|
+
class JSONInJSONParser < JSONParser
|
6
|
+
def parse(text)
|
7
|
+
record = Yajl.load(text)
|
8
|
+
|
9
|
+
record.each do |key, value|
|
10
|
+
record[key] = Yajl.load(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
value = @keep_time_key ? record[@time_key] : record.delete(@time_key)
|
14
|
+
if value
|
15
|
+
if @time_format
|
16
|
+
time = @mutex.synchronize { @time_parser.parse(value) }
|
17
|
+
else
|
18
|
+
begin
|
19
|
+
time = value.to_i
|
20
|
+
rescue => e
|
21
|
+
raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
if @estimate_current_event
|
26
|
+
time = Engine.now
|
27
|
+
else
|
28
|
+
time = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if block_given?
|
33
|
+
yield time, record
|
34
|
+
else
|
35
|
+
return time, record
|
36
|
+
end
|
37
|
+
rescue Yajl::ParseError
|
38
|
+
if block_given?
|
39
|
+
yield nil, nil
|
40
|
+
else
|
41
|
+
return nil, nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-json-in-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gavin M. Roy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yajl-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Parser plugin that parses JSON attributes with JSON strings in them
|
56
|
+
email:
|
57
|
+
- gavinmroy@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- fluent-plugin-json-in-json.gemspec
|
67
|
+
- lib/fluent/plugin/parser_json_in_json.rb
|
68
|
+
homepage: https://github.com/gmr/fluent-plugin-json-in-json
|
69
|
+
licenses:
|
70
|
+
- BSD
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.4.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Parser plugin that parses JSON attributes with JSON strings in them
|
92
|
+
test_files: []
|