fluent-plugin-filter-jq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a06caa37ed1f78d57f54167e61fa76247d08f70
4
+ data.tar.gz: 3c91f256bf5f1096e75351ef2b289fc111bd22aa
5
+ SHA512:
6
+ metadata.gz: 886908fe06e02e312f687fdc2faa47559e9853d113777ab148324bb6f762e79a145694647e5e9785884f033ddfd6d7902d6a8a41d7e0643f0e78d80618e8ea5f
7
+ data.tar.gz: afeec195dbb3a63e7bf1f8b9a024698d86ea0e382276fc6a7efad868b396b47ace30bf86e8de809cf438e42e6a41b359112d45499660a6008bca5be9d9ba276c
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ fluent.conf
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ install:
6
+ - wget http://ftp.gnu.org/gnu/bison/bison-3.0.2.tar.gz
7
+ - tar xf bison-3.0.2.tar.gz
8
+ - cd bison-3.0.2
9
+ - ./configure
10
+ - make
11
+ - sudo make install
12
+ - cd ..
13
+ - sudo apt-get install flex libonig2 libonig-dev
14
+ - git clone https://github.com/stedolan/jq.git
15
+ - cd jq
16
+ - autoreconf -i
17
+ - ./configure --enable-shared
18
+ - BUNDLE_GEMFILE="$PWD/docs/Gemfile" bundle install
19
+ - BUNDLE_GEMFILE="$PWD/docs/Gemfile" bundle exec make
20
+ - sudo make install
21
+ - sudo ldconfig
22
+ - cd ..
23
+ script:
24
+ - bundle install
25
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-filter-jq.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Genki Sugawara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # fluent-plugin-filter-jq
2
+
3
+ Filter Plugin to create a new record containing the values converted by [jq](http://stedolan.github.io/jq/).
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-filter-jq.svg)](http://badge.fury.io/rb/fluent-plugin-filter-jq)
6
+ [![Build Status](https://travis-ci.org/winebarrel/fluent-plugin-filter-jq.svg?branch=master)](https://travis-ci.org/winebarrel/fluent-plugin-filter-jq)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'fluent-plugin-filter-jq'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install fluent-plugin-filter-jq
23
+
24
+ ## Configuration
25
+
26
+ ```apache
27
+ <filter>
28
+ type record_map
29
+ # see http://stedolan.github.io/jq/manual/
30
+ jq '{foo: .bar}'
31
+ </filter>
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```sh
37
+ $ cat fluent.conf
38
+ <source>
39
+ @type forward
40
+ @id forward_input
41
+ </source>
42
+
43
+ <filter>
44
+ type jq
45
+
46
+ # swap value
47
+ jq '{foo:.zoo,zoo:.foo}'
48
+ </filter>
49
+
50
+ <match **>
51
+ @type stdout
52
+ @id stdout_output
53
+ </match>
54
+
55
+ $ fluentd -c fluent.conf
56
+ ```
57
+
58
+ ```sh
59
+ $ echo '{"foo":"bar", "zoo":"baz"}' | fluent-cat test.data
60
+ #=> 2015-01-01 23:34:45 +0900 test.data: {"zoo":"bar","foo":"baz"}
61
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/filter/jq"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent_plugin_filter_jq/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fluent-plugin-filter-jq'
8
+ spec.version = FluentPluginFilterJq::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sgwr_dts@yahoo.co.jp']
11
+
12
+ spec.summary = %q{Filter Plugin to create a new record containing the values converted by jq.}
13
+ spec.description = %q{Filter Plugin to create a new record containing the values converted by jq.}
14
+ spec.homepage = 'https://github.com/winebarrel/fluent-plugin-filter-jq'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'fluentd', '>= 0.12'
23
+ spec.add_dependency 'ruby-jq'
24
+ spec.add_dependency 'multi_json'
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
29
+ end
@@ -0,0 +1,39 @@
1
+ require 'fluent_plugin_filter_jq/version'
2
+ require 'multi_json'
3
+ require 'jq'
4
+
5
+ module Fluent
6
+ class JqFilter < Filter
7
+ Plugin.register_filter('jq', self)
8
+
9
+ config_param :jq, :string
10
+ config_param :no_hash_root_key, :string, :default => '.'
11
+
12
+ def filter_stream(tag, es)
13
+ result_es = Fluent::MultiEventStream.new
14
+
15
+ es.each do |time, record|
16
+ jq_search(time, record, result_es)
17
+ end
18
+
19
+ result_es
20
+ rescue => e
21
+ log.warn e.message
22
+ log.warn e.backtrace.join(', ')
23
+ end
24
+
25
+ private
26
+
27
+ def jq_search(time, record, result_es)
28
+ json = MultiJson.dump(record)
29
+
30
+ JQ(json).search(@jq) do |value|
31
+ unless value.is_a?(Hash)
32
+ value = {@no_hash_root_key => value}
33
+ end
34
+
35
+ result_es.add(time, value)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module FluentPluginFilterJq
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-filter-jq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-jq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
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
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ description: Filter Plugin to create a new record containing the values converted
98
+ by jq.
99
+ email:
100
+ - sgwr_dts@yahoo.co.jp
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - fluent-plugin-filter-jq.gemspec
115
+ - lib/fluent/plugin/filter_jq.rb
116
+ - lib/fluent_plugin_filter_jq/version.rb
117
+ homepage: https://github.com/winebarrel/fluent-plugin-filter-jq
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Filter Plugin to create a new record containing the values converted by jq.
141
+ test_files: []