fluent-plugin-json-in-json-sp 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 378b86e5f5a83f5fad9818e3ea871c7beef70b77
4
+ data.tar.gz: 896287801c15bf5d2d19a6e399e0419199662071
5
+ SHA512:
6
+ metadata.gz: 61f243e534244e1de7c5780b4d6313440c93c3dbedbbbac23c593cfd77a2a6519d3c7bb767a8c7825061df149c47949ef2b1493752399f6b6a646d4ec59d8cdd
7
+ data.tar.gz: c8a7d91f8da919ebe2a0ac5ec5362643f2ac1f2ce5db1c8727dbb2f8fb9392b01f50511a7f50099cf011ec7c06120c54600f2212e23474f080e95ac8254b46f6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-json-in-json.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # fluent-plugon-json-in-json
2
+
3
+ :boom:**Important**:boom: This project is deprecated and no longer maintained. If you'd like to take it over, please contact me.
4
+
5
+ This fluentd parser plugin parses JSON log lines with nested JSON strings. For
6
+ example, given a docker log of ``{"log": "{\"foo\": \"bar\"}"}``, the log record
7
+ will be parsed into ``{:log => { :foo => "bar" }}``.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'fluent-plugin-json-in-json'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fluent-plugin-json-in-json
22
+
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ <source>
28
+ type tail
29
+ path /var/lib/docker/containers/*/*-json.log
30
+ pos_file /var/log/fluentd-docker.pos
31
+ time_format %Y-%m-%dT%H:%M:%S
32
+ tag docker.*
33
+ format json_in_json
34
+ read_from_head true
35
+ </source>
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "fluent-plugin-json-in-json-sp"
4
+ spec.version = "0.2.1"
5
+ spec.authors = ["Ryan Dyer"]
6
+ spec.email = ["ryan.dyer@sailpoint.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/ryan-dyer-sp/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_runtime_dependency "fluentd", '>= 0.14.0'
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1,69 @@
1
+ require 'yajl'
2
+ require 'fluent/plugin/parser'
3
+
4
+ module Fluent::Plugin
5
+ class TextParser
6
+ class JSONInJSONParser < Parser
7
+ Fluent::Plugin.register_parser('json_in_json', self)
8
+
9
+ config_param :time_key, :string, :default => 'time'
10
+ config_param :time_format, :string, :default => nil
11
+
12
+ def configure(conf)
13
+ super
14
+
15
+ unless @time_format.nil?
16
+ @time_parser = Fluent::TimeParser.new(@time_format)
17
+ @mutex = Mutex.new
18
+ end
19
+ end
20
+
21
+ def parse(text)
22
+ record = Yajl.load(text)
23
+
24
+ value = @keep_time_key ? record[@time_key] : record.delete(@time_key)
25
+ if value
26
+ if @time_format
27
+ time = @mutex.synchronize { @time_parser.parse(value) }
28
+ else
29
+ begin
30
+ time = value.to_i
31
+ rescue => e
32
+ raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
33
+ end
34
+ end
35
+ else
36
+ if @estimate_current_event
37
+ time = Fluent::Engine.now
38
+ else
39
+ time = nil
40
+ end
41
+ end
42
+
43
+ values = Hash.new
44
+ record.each do |k, v|
45
+ if v[0] == '{'
46
+ deserialized = Yajl.load(v)
47
+ if deserialized.is_a?(Hash)
48
+ values.merge!(deserialized)
49
+ record.delete k
50
+ end
51
+ end
52
+ end
53
+ record.merge!(values)
54
+
55
+ if block_given?
56
+ yield time, record
57
+ else
58
+ return time, record
59
+ end
60
+ rescue Yajl::ParseError
61
+ if block_given?
62
+ yield nil, nil
63
+ else
64
+ return nil, nil
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-json-in-json-sp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Dyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-02 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: fluentd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.14.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Parser plugin that parses JSON attributes with JSON strings in them
70
+ email:
71
+ - ryan.dyer@sailpoint.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - fluent-plugin-json-in-json-sp.gemspec
81
+ - lib/fluent/plugin/parser_json_in_json.rb
82
+ homepage: https://github.com/ryan-dyer-sp/fluent-plugin-json-in-json
83
+ licenses:
84
+ - BSD
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Parser plugin that parses JSON attributes with JSON strings in them
106
+ test_files: []