fluent-plugin-out_apache_log_format 0.0.6

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: 7e782ff8eb1ff4b9753bfdbbd7384bfc7d256250
4
+ data.tar.gz: 39937cbd2ab2bff12f3e2007bc18a01127863571
5
+ SHA512:
6
+ metadata.gz: 5ec770ff0b24714859ac98673a8113758a731d1b8bb5e4ad09611b125a11998f2e6826069250f0cfa43e41eb9034bdf6ee7a0dc0d7dd98f49025d1f5143594ef
7
+ data.tar.gz: d9baca596404636e31e3ff8595196b206423c446fbd310fd243d6063830ff8c2c2769e20e7c513d8bf7671ca5f4a29d85e9b7ca5aa971cdae40c774568a0b867
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-fluent-plugin-out_apache_log_format.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 jorge moratilla
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,76 @@
1
+ # Fluentd output plugin from custom log format to Apache Common Combined Log Format.
2
+
3
+ This is a quick and dirty try on creating an output filter for Fluentd (http://fluentd.org).
4
+
5
+ This plugin doesn't work alone. You need to install and configure the fluentd data collector.
6
+
7
+
8
+ ## Installation
9
+
10
+ First, create an empty bundle project:
11
+
12
+ $ bundle init
13
+
14
+ Add these lines to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'fluentd'
18
+ gem 'fluent-plugin-out_apache_log_format'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install fluent-plugin-out_apache_log_format
28
+
29
+ ## Usage
30
+
31
+ This is an output plugin for Fluentd. You need a fluentd config file to make it works.
32
+
33
+ ```
34
+ # fluent conversor: from our custom log format to apache common combined log format
35
+ <source>
36
+ @type tail
37
+ format /\A(?<logid>(\d+) <(\d+)>(\d+)) (?<timestamp>\S+) app (?<host>\S+) - - \[REQUEST\] request_id='(?<request_id>.*?)' action='(?<action>.*?)' format='(?<format>.*?)' method='(?<method>.*?)' path='(?<path>.*?)' user_agent='(?<user_agent>.*?)' ip='(?<proxy_ip>.*?)' xff_ip='(?<ip_chain>.*?)' referer='(?<referer>.*?)' scheme='(?<scheme>.*?)' status='(?<status>.*?)' measuretime='(?<measuretime>.*?)'\z/
38
+ path inputfile
39
+ pos_file inputfile.pos
40
+ tag get_remote_host
41
+ </source>
42
+
43
+ # This filter helps to get the real source ip address from the connection.
44
+ <filter get_remote_host>
45
+ @type record_transformer
46
+ enable_ruby true
47
+ <record>
48
+ ip ${ip_chain.split(',')[0]}
49
+ </record>
50
+ </filter>
51
+
52
+ # This output config will send everything to stdout
53
+ <match *>
54
+ @type alf
55
+ </match>
56
+
57
+ ```
58
+
59
+ Now you can execute the following command:
60
+
61
+
62
+ $ fluentd -c fluentd.conf
63
+
64
+
65
+
66
+ And send logs to the inputfile with:
67
+
68
+
69
+ $ cat logfile >> inputfile
70
+
71
+ They will be filtered, parsed and converted to Apache Log Format.
72
+
73
+ If you want to generate a file, then append a tee command to the fluentd command, like:
74
+
75
+ $ fluentd -qqc fluentd.conf | tee outputfile
76
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-out_apache_log_format"
8
+ spec.version = '0.0.6'
9
+ spec.authors = ["jorge moratilla"]
10
+ spec.email = ["jorge@moratilla.com"]
11
+ spec.summary = %q{This output filter generates Combined Common Log Format entries}
12
+ spec.description = %q{This output filter generates Combined Common Log Format entries}
13
+ spec.homepage = "https://bitbucket.org/jmoratilla/fluent-plugin-out_apache_log_format"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "fluentd"
24
+
25
+ end
@@ -0,0 +1,58 @@
1
+ require 'fluent/output'
2
+
3
+ module Fluent
4
+ class ApacheLogFormat < Output
5
+ # First, register the plugin. NAME is the name of this plugin
6
+ # and identifies the plugin in the configuration file.
7
+ Fluent::Plugin.register_output('alf', self)
8
+
9
+ # TODO: Add params to allow different field names for the log
10
+ # "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D"
11
+ # config_param :host, :string
12
+ # config_param :time, :string
13
+ # config_param :method, :string
14
+ # config_param :path, :string
15
+ # config_param :status, :string
16
+ # config_param :size, :integer, :default => 0
17
+ # config_param :referer, :string, :default => ''
18
+ # config_param :user_agent, :string, :default => ''
19
+ # config_param :response_time, :integer, :default => ''
20
+
21
+ def configure(conf)
22
+ super
23
+ end
24
+
25
+ def initialize
26
+ super
27
+ end
28
+
29
+ def start
30
+ super
31
+ end
32
+
33
+ def shutdown
34
+ super
35
+ end
36
+
37
+ # This method is called when an event reaches Fluentd.
38
+ # 'es' is a Fluent::EventStream object that includes multiple events.
39
+ # You can use 'es.each {|time,record| ... }' to retrieve events.
40
+ # 'chain' is an object that manages transactions. Call 'chain.next' at
41
+ # appropriate points and rollback if it raises an exception.
42
+ #
43
+ # NOTE! This method is called by Fluentd's main thread so you should not write slow routine here. It causes Fluentd's performance degression.
44
+ def emit(tag, es, chain)
45
+ chain.next
46
+ es.each {|time,record|
47
+ puts output_record(record)
48
+ }
49
+
50
+ end
51
+
52
+ private
53
+
54
+ def output_record(record)
55
+ "#{record['ip']} - - [#{DateTime.parse(record['timestamp']).strftime("%d/%b/%Y:%H:%M:%S %z")}] \"#{record['method']} #{record['path'].empty? ? '/' : record['path']}\" #{record['status']} 1024 \"#{record['referer']}\" \"#{record['user_agent']}\" #{record['measuretime']}"
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-out_apache_log_format
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - jorge moratilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
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
+ description: This output filter generates Combined Common Log Format entries
56
+ email:
57
+ - jorge@moratilla.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/.name"
64
+ - ".idea/misc.xml"
65
+ - ".idea/modules.xml"
66
+ - ".idea/out_apache_log_format.iml"
67
+ - ".idea/vcs.xml"
68
+ - ".idea/workspace.xml"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - fluent-plugin-out_apache_log_format.gemspec
74
+ - lib/fluent/plugin/out_alf.rb
75
+ homepage: https://bitbucket.org/jmoratilla/fluent-plugin-out_apache_log_format
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: This output filter generates Combined Common Log Format entries
99
+ test_files: []