fluent-plugin-grep 0.0.1

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: 8bc4b1bc5d03ba51926b8d8dbc5039c0a45696c3
4
+ data.tar.gz: 4e6e77f9ef105730ee530720773ee98cc54f7e1c
5
+ SHA512:
6
+ metadata.gz: a9e7fdf029afe36c65abd1016c85ffbaa31701f0b1ba4e678c63e7e986fa79766b21c391c30120936d9f8120689e0ea81f52e749a459da11c48ab50402adb11e
7
+ data.tar.gz: 17984c87fc1b8ab48b4b7b334fa328c9ad6e702035188843b44d2bb2687ba3dd0765fdb28a9b5a437b150d3b911ca099e6d6fb19a51bcc495eb5dc08eadda449
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: i4DJCtdksuIwhBck1tukIjzKoMCxWIIvQ
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ coverage
12
+ .yardoc
data/.rdebugrc ADDED
@@ -0,0 +1,4 @@
1
+ set autolist
2
+ set autoeval
3
+ set autoreload
4
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'simplecov', git: 'https://github.com/colszowka/simplecov.git'
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Naotoshi SEO
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # fluent-plugin-grep [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-grep.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-grep) [![Dependency Status](https://gemnasium.com/sonots/fluent-plugin-grep.png)](https://gemnasium.com/sonots/fluent-plugin-grep) [![Coverage Status](https://coveralls.io/repos/sonots/fluent-plugin-grep/badge.png?branch=master)](https://coveralls.io/r/sonots/fluent-plugin-grep)
2
+
3
+ Fluentd plugin to grep messages.
4
+
5
+ ## Configuration
6
+
7
+ Assume inputs from another plugin are as belows:
8
+
9
+ syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:11.124202 INFO GET /ping"}
10
+ syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:13.232645 WARN POST /auth"}
11
+ syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"}
12
+ syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:43.632145 WARN POST /login"}
13
+
14
+ An example of grep configuration:
15
+
16
+ <match syslog.**>
17
+ type grep
18
+ input_key message
19
+ regexp WARN
20
+ exclude favicon.ico
21
+ add_tag_prefix grep
22
+ </source>
23
+
24
+ Then, output bocomes as belows:
25
+
26
+ grep.syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:13.232645 WARN POST /auth"}
27
+ grep.syslog.host1: {"foo":"bar","message":"2013/01/13T07:02:43.632145 WARN POST /login"}
28
+
29
+ ## ChangeLog
30
+
31
+ See [CHANGELOG.md](CHANGELOG.md) for details.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new [Pull Request](../../pull/new/master)
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2013 Naotoshi SEO. See [LICENSE](LICENSE) for details.
44
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+ task :default => :spec
10
+
11
+ desc 'Open an irb session preloaded with the gem library'
12
+ task :console do
13
+ sh 'irb -rubygems -I lib'
14
+ end
15
+ task :c => :console
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-grep"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Naotoshi SEO"]
8
+ s.email = ["sonots@gmail.com"]
9
+ s.homepage = "https://github.com/sonots/fluent-plugin-grep"
10
+ s.summary = "fluentd plugin to grep messages"
11
+ s.description = s.summary
12
+
13
+ s.rubyforge_project = "fluent-plugin-grep"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "fluentd"
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "pry"
24
+ s.add_development_dependency 'coveralls'
25
+ end
@@ -0,0 +1,30 @@
1
+ class Fluent::GrepOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('grep', self)
3
+
4
+ config_param :input_key, :string
5
+ config_param :regexp, :string, :default => nil
6
+ config_param :exclude, :string, :default => nil
7
+ config_param :tag, :string, :default => nil
8
+ config_param :add_tag_prefix, :string, :default => 'grep'
9
+
10
+ def configure(conf)
11
+ super
12
+
13
+ @input_key = @input_key.to_s
14
+ @regexp = Regexp.compile(@regexp) if @regexp
15
+ @exclude = Regexp.compile(@exclude) if @exclude
16
+ end
17
+
18
+ def emit(tag, es, chain)
19
+ emit_tag = @tag ? @tag : "#{@add_tag_prefix}.#{tag}"
20
+
21
+ es.each do |time,record|
22
+ value = record[@input_key]
23
+ next if @regexp and !@regexp.match(value)
24
+ next if @exclude and @exclude.match(value)
25
+ Fluent::Engine.emit(emit_tag, time, record)
26
+ end
27
+
28
+ chain.next
29
+ end
30
+ end
@@ -0,0 +1,122 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe Fluent::GrepOutput do
5
+ before { Fluent::Test.setup }
6
+ CONFIG = %[
7
+ input_key message
8
+ ]
9
+ let(:tag) { 'syslog.host1' }
10
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::GrepOutput, tag).configure(config) }
11
+
12
+ describe 'test configure' do
13
+ describe 'bad configuration' do
14
+ context "lack of requirements" do
15
+ let(:config) { '' }
16
+ it { expect { driver }.to raise_error(Fluent::ConfigError) }
17
+ end
18
+ end
19
+
20
+ describe 'good configuration' do
21
+ subject { driver.instance }
22
+
23
+ context "check default" do
24
+ let(:config) { CONFIG }
25
+ its(:input_key) { should == "message" }
26
+ its(:regexp) { should be_nil }
27
+ its(:exclude) { should be_nil }
28
+ its(:tag) { should be_nil }
29
+ its(:add_tag_prefix) { should == 'grep' }
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'test emit' do
35
+ let(:time) { Time.now.to_i }
36
+ let(:messages) do
37
+ [
38
+ "2013/01/13T07:02:11.124202 INFO GET /ping",
39
+ "2013/01/13T07:02:13.232645 WARN POST /auth",
40
+ "2013/01/13T07:02:21.542145 WARN GET /favicon.ico",
41
+ "2013/01/13T07:02:43.632145 WARN POST /login",
42
+ ]
43
+ end
44
+ let(:emit) do
45
+ driver.run { messages.each {|message| driver.emit({'foo'=>'bar', 'message' => message}, time) } }
46
+ end
47
+
48
+ context 'default' do
49
+ let(:config) { CONFIG }
50
+ before do
51
+ Fluent::Engine.stub(:now).and_return(time)
52
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
53
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
54
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"})
55
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
56
+ end
57
+ it { emit }
58
+ end
59
+
60
+ context 'regexp' do
61
+ let(:config) do
62
+ CONFIG + %[
63
+ regexp WARN
64
+ ]
65
+ end
66
+ before do
67
+ Fluent::Engine.stub(:now).and_return(time)
68
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
69
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"})
70
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
71
+ end
72
+ it { emit }
73
+ end
74
+
75
+ context 'exclude' do
76
+ let(:config) do
77
+ CONFIG + %[
78
+ exclude favicon
79
+ ]
80
+ end
81
+ before do
82
+ Fluent::Engine.stub(:now).and_return(time)
83
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
84
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
85
+ Fluent::Engine.should_receive(:emit).with("grep.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
86
+ end
87
+ it { emit }
88
+ end
89
+
90
+ context 'tag' do
91
+ let(:config) do
92
+ CONFIG + %[
93
+ regexp ping
94
+ tag foo
95
+ ]
96
+ end
97
+ before do
98
+ Fluent::Engine.stub(:now).and_return(time)
99
+ Fluent::Engine.should_receive(:emit).with("foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
100
+ end
101
+ it { emit }
102
+ end
103
+
104
+ context 'add_tag_prefix' do
105
+ let(:config) do
106
+ CONFIG + %[
107
+ regexp ping
108
+ add_tag_prefix foo
109
+ ]
110
+ end
111
+ before do
112
+ Fluent::Engine.stub(:now).and_return(time)
113
+ Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
114
+ end
115
+ it { emit }
116
+ end
117
+ end
118
+
119
+ end
120
+
121
+
122
+
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup(:default, :test)
5
+ Bundler.require(:default, :test)
6
+
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+
10
+ require 'fluent/test'
11
+ require 'rspec'
12
+ require 'pry'
13
+
14
+ $TESTING=true
15
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
16
+ require 'fluent/plugin/out_grep'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-grep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi SEO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-02 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: coveralls
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
+ description: fluentd plugin to grep messages
84
+ email:
85
+ - sonots@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .coveralls.yml
91
+ - .gitignore
92
+ - .rdebugrc
93
+ - .rspec
94
+ - .travis.yml
95
+ - CHANGELOG.md
96
+ - Gemfile
97
+ - LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - fluent-plugin-grep.gemspec
101
+ - lib/fluent/plugin/out_grep.rb
102
+ - spec/out_grep_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/sonots/fluent-plugin-grep
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project: fluent-plugin-grep
123
+ rubygems_version: 2.0.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: fluentd plugin to grep messages
127
+ test_files:
128
+ - spec/out_grep_spec.rb
129
+ - spec/spec_helper.rb