fluent-plugin-with-extra-fields-parser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-with-extra-fields-parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 hiraro
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.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # fluent-plugin-with-extra-fields-parser
2
+
3
+
4
+ ## Installation
5
+
6
+ ```
7
+ $ /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-with-extra-fields-parser
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```
13
+ ####
14
+ ## Source descriptions:
15
+ ##
16
+
17
+ ## syslog
18
+ <source>
19
+
20
+ # I want to process the syslog of my yamaha rtx1100...
21
+
22
+ # example output format 1.
23
+ # [INSPECT] PP[01][out][101] TCP xxx.xxx.xx.xxx:xxx > xxx.xx.
24
+ xx.xxx:80 (2016/02/23 10:59:24)
25
+
26
+ # example output format 2.
27
+ # PP[01] Rejected at IN(2000) filter: TCP xx.xxx.xxx.xx:xxx
28
+
29
+ type syslog
30
+ tag raw.rtx1100
31
+ format none
32
+
33
+ </source>
34
+
35
+ ####
36
+ ## Output descriptions:
37
+ ##
38
+
39
+ <match raw.rtx1100.**>
40
+
41
+ # ...so I use tagomoris/fluent-plugin-parser
42
+
43
+ type parser
44
+ key_name message
45
+
46
+ # ...and repeatedly/fluent-plugin-multi-format-parser
47
+
48
+ format multi_format
49
+ remove_prefix raw
50
+ add_prefix parsed
51
+
52
+ <pattern>
53
+
54
+ # ...and this plugin
55
+
56
+ format with_extra_fields
57
+
58
+ base_format /^\[INSPECT\]\s+(?<target>.+)\[(?<direction>.+)\]\[(?<filter_num>\d+)\]\s+(?<proto>.+)\s+(?<src_ip>.+):(?<src_port>.+)\s+>\s+(?<dest_ip>.+):(?<dest_port>.+)\s+\((?<time>.+)\)$/
59
+ time_format '%Y/%m/%d %H:%M:%S'
60
+
61
+ # ...to embed log_type field
62
+
63
+ extra_fields { "log_type": "inspect" }
64
+
65
+ </pattern>
66
+ <pattern>
67
+
68
+ format with_extra_fields
69
+
70
+ base_format /^(?<target>.+)\s+Rejected\s+at\s+(?<direction>.+)\((?<filter_num>\d+)\)\s+filter:\s+(?<proto>.+)\s+(?<src_ip>.+):(?<src_port>.+)\s+>\s+(?<dest_ip>.+):(?<dest_port>.+)$/
71
+
72
+ extra_fields { "log_type": "reject" }
73
+
74
+ </pattern>
75
+ </match>
76
+
77
+
78
+ <match parsed.rtx1100.**>
79
+
80
+ # you'll get log_type here.
81
+ # so, rewrite the tag using the log_type field
82
+ # with fluent/fluent-plugin-rewrite-tag-filter
83
+
84
+ type rewrite_tag_filter
85
+
86
+ rewriterule1 log_type ^inspect$ rtx1100.inspect
87
+ rewriterule2 log_type ^reject$ rtx1100.reject
88
+
89
+ </match>
90
+
91
+ <match rtx1100.inspect.**>
92
+
93
+ # and store into elasticsearch
94
+ # with uken/fluent-plugin-elasticsearch
95
+
96
+ type elasticsearch
97
+ logstash_format true
98
+ logstash_prefix rtx1100-inspect
99
+ include_tag_key true
100
+ tag_key @log_name
101
+ hosts localhost:9200
102
+ buffer_type memory
103
+ num_threads 1
104
+ flush_interval 60
105
+ retry_wait 1.0
106
+ retry_limit 17
107
+
108
+ </match>
109
+
110
+ <match rtx1100.reject.**>
111
+
112
+ type elasticsearch
113
+ logstash_format true
114
+ logstash_prefix rtx1100-reject
115
+ include_tag_key true
116
+ tag_key @log_name
117
+ hosts localhost:9200
118
+ buffer_type memory
119
+ num_threads 1
120
+ flush_interval 60
121
+ retry_wait 1.0
122
+ retry_limit 17
123
+
124
+ </match>
125
+ ```
126
+
127
+
128
+ ## Contributing
129
+
130
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/hiraro/fluent-plugin-with-extra-fields-parser).
131
+
132
+ ## License
133
+
134
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/with/extra/fields/parser"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-with-extra-fields-parser"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["hiraro"]
9
+ spec.email = ["traurig.orz@gmail.com"]
10
+
11
+ spec.summary = %q{Fluentd parser plugin}
12
+ spec.description = %q{Appends extra fields after parse.}
13
+ spec.homepage = "https://github.com/hiraro/fluentd-plugin-with-extra-fields-parser"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "rake"
21
+ spec.add_runtime_dependency "fluentd", "~> 0.12.0"
22
+ spec.add_runtime_dependency "json", ">= 1.4.3"
23
+ end
@@ -0,0 +1,47 @@
1
+ require 'fluent/log'
2
+ require 'json'
3
+
4
+ module Fluent
5
+ class TextParser
6
+ class WithExtraFieldsParser < Parser
7
+ Plugin.register_parser('with_extra_fields', self)
8
+
9
+ config_param :base_format, :string
10
+ config_param :suppress_parse_error_log, :bool, :default => false
11
+
12
+ def initialize
13
+ super
14
+ @parser = nil
15
+ @extra_fields = {}
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+ @parser = Plugin.new_parser(@base_format)
21
+ @parser.configure(conf)
22
+
23
+ JSON.parse(conf["extra_fields"]).each { |k, v|
24
+ @extra_fields[k] = v
25
+ }
26
+ end
27
+
28
+ def parse(text)
29
+ begin
30
+ @parser.parse(text) { |time, record|
31
+ if time && record
32
+ @extra_fields.each { |k, v|
33
+ record[k] = v
34
+ }
35
+ yield time, record
36
+ return
37
+ end
38
+ }
39
+ rescue => e
40
+ $log.warn "parse failed #{e.message}" unless @suppress_parse_error_log
41
+ end
42
+ yield nil, nil
43
+ end
44
+ end
45
+ end
46
+ end
47
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-with-extra-fields-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - hiraro
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.12.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.3
62
+ description: Appends extra fields after parse.
63
+ email:
64
+ - traurig.orz@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - fluent-plugin-with-extra-fields-parser.gemspec
77
+ - lib/fluent/plugin/parser_with_extra_fields.rb
78
+ homepage: https://github.com/hiraro/fluentd-plugin-with-extra-fields-parser
79
+ licenses:
80
+ - MIT
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.23
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Fluentd parser plugin
103
+ test_files: []