fluent-plugin-input-gelf-kolyunya 0.3.5

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
+ SHA256:
3
+ metadata.gz: 3e742ccc949eb7dadb0511e4bb1afbea5757800509307ed47e0dced716dfea69
4
+ data.tar.gz: a19bc72cad3db42f188585b2e8682e9e247edbc89d9aa778506346edad33506e
5
+ SHA512:
6
+ metadata.gz: e64084398d3e13a423a98c4ca2d3740be41c9d6924992f07ea7b1cf8477a81f5cacc8b5266b5d1174b0b2655cebcbd3027d6b6773a5de651fb655cd88fb36a63
7
+ data.tar.gz: 5e0cb2986c964441832d932e0cb02fdb05f5caff3392d6c1ef63e898767c6175f41a5c9f970a865eecac5583806d9018fce1ac47171ca197aec461c346ce53d5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ ~*
2
+ #*
3
+ *~
4
+ [._]*.s[a-w][a-z]
5
+ .DS_Store
6
+
7
+ *.gem
8
+ .bundle
9
+ Gemfile.lock
10
+ vendor
11
+ .ruby-version
12
+ *.iml
data/.travis.yml ADDED
@@ -0,0 +1,33 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+
10
+ gemfile:
11
+ - Gemfile
12
+
13
+ branches:
14
+ only:
15
+ - master
16
+ # Tagged commits
17
+ - /^v\d+\.\d+(\.\d+)?(-\S*)?$/
18
+
19
+ script: bundle exec rake test
20
+
21
+ jobs:
22
+ include:
23
+ - stage: gem release
24
+ rvm: 2.3
25
+ script: echo "Deploying to rubygems.org ..."
26
+ deploy:
27
+ provider: rubygems
28
+ api_key:
29
+ secure: R06ICCYHjZ+bk+CocD+eZROiTsfDnmUlugdSIqND0f9Z+Vi8ALOZmIEhlpBvloRaOLU0pz3d9juj74vHMJ1boJN6Qgn+CtAGSDzesxm6vcd/AP87mEzAaJvvHRme7bNLy7gt1RvrmVzDjyOe2fF8kcVAz19bEArJ1rqBXeLiLY+fOPenCsWRNrOt2+yOH5qRgdFs+n2NQ6oQrDEq18uZJVQ74WnSyKGylIhPfXj+TcgMrDGJtxqWYmL+DeuzOVk73REMHiw+9ljvhjVIdMxiU/oXge9y7Ua7q6OlkJgmChaWrs06bHiwhJHz6yh+OXebVFbxHTsPdsw4w+Uv9/MB961zgR58yLVi6AJr5xosM8l92S/OJeG9paO43xuQGeX+mch7m/827VbeM8aLtRGXjNILC3BW+l9O++Yg0eF6YC4c6NobNOX4ZpfGNopDsoyYI19Yj9SoKvoqw3WtAZsX2T5CrAdG1PHLKNDwyCbuiYjlNKAAHy5ZCB7X63JrDAKgwUQSnYEPEGNVzisnNfyqVxQnvTDZLwgzWcYxTBCjXoO09+qsbB9lpgecT45UI80VgW70nokEzilmyXARG+eBGKhz2iJli+mrdZbpfzws/PD/Hr5dubgn8mNX5/e6DRMoTr9xQOGrvdXhET+ygiTEWg1VMzfcZ2WpeJTveV9h2BQ=
30
+ gem: fluent-plugin-input-gelf
31
+ on:
32
+ tags: true
33
+ repo: MerlinDMC/fluent-plugin-input-gelf
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Daniel Malon
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # fluent-plugin-input-gelf
2
+
3
+ [![Build Status](https://travis-ci.org/MerlinDMC/fluent-plugin-input-gelf.svg?branch=master)](https://travis-ci.org/MerlinDMC/fluent-plugin-input-gelf)
4
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-input-gelf.svg)](http://badge.fury.io/rb/fluent-plugin-input-gelf)
5
+
6
+ ## Overview
7
+
8
+ A GELF compatible input for [Fluentd](http://www.fluentd.org/).
9
+
10
+ ### Configuration
11
+
12
+ Accept GELF encoded messages over UDP
13
+
14
+ ```
15
+ <source>
16
+ type gelf
17
+ tag example.gelf
18
+ bind 127.0.0.1
19
+ port 12201
20
+ </source>
21
+
22
+ <match example.gelf>
23
+ type stdout
24
+ </match>
25
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/plugin/test_*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:build]
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-input-gelf-kolyunya"
6
+ gem.description = "Fork A GELF input plugin for fluentd"
7
+ gem.license = "MIT"
8
+ gem.homepage = "https://github.com/koxx009/fluent-plugin-input-gelf-kolyunya"
9
+ gem.summary = gem.description
10
+ gem.version = "0.3.5"
11
+ gem.authors = ["Nikolay Ostroushko"]
12
+ gem.email = "n.ostroushko@mts.ai"
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.required_ruby_version = '>= 2.7.0'
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
20
+ gem.add_runtime_dependency "gelfd2", ">= 0.3.0"
21
+
22
+ gem.add_development_dependency "bundler"
23
+ gem.add_development_dependency "rake"
24
+ gem.add_development_dependency "test-unit"
25
+ gem.add_development_dependency "gelf", ">= 2.0.0"
26
+ end
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+ require 'time'
3
+
4
+ require 'cool.io'
5
+ require 'yajl'
6
+
7
+ require 'gelfd2'
8
+
9
+ require 'fluent/input'
10
+ require 'fluent/plugin/socket_util'
11
+
12
+ module Fluent
13
+ class UdpHandler < SocketUtil::UdpHandler
14
+ def initialize(io, log, body_size_limit, callback)
15
+ super
16
+ end
17
+ def on_readable
18
+ msg, addr = @io.recvfrom_nonblock(@body_size_limit)
19
+ @callback.call(msg, addr)
20
+ rescue => e
21
+ @log.error "unexpected error", error: e, error_class: e.class
22
+ end
23
+ end
24
+
25
+ class GelfInput < Fluent::Plugin::Input
26
+ Fluent::Plugin.register_input('gelf', self)
27
+
28
+ helpers :server, :parser, :compat_parameters
29
+
30
+ DEFAULT_PARSER = 'json'.freeze
31
+
32
+ def initialize
33
+ super
34
+ end
35
+
36
+ desc "The value is the tag assigned to the generated events."
37
+ config_param :tag, :string
38
+ desc 'The port to listen to.'
39
+ config_param :port, :integer, default: 12201
40
+ desc 'The bind address to listen to.'
41
+ config_param :bind, :string, default: '0.0.0.0'
42
+ desc 'The transport protocol used to receive logs.(udp, tcp)'
43
+ config_param :protocol_type, :enum, list: [:udp, :tcp], default: :udp
44
+ desc 'Strip leading underscore'
45
+ config_param :strip_leading_underscore, :bool, default: true
46
+
47
+ config_section :parse do
48
+ config_set_default :@type, DEFAULT_PARSER
49
+ end
50
+
51
+ def configure(conf)
52
+ compat_parameters_convert(conf, :parser)
53
+ super
54
+
55
+ @parser = parser_create
56
+ end
57
+
58
+ def start
59
+ super
60
+
61
+ listen
62
+ end
63
+
64
+ def shutdown
65
+ super
66
+ end
67
+
68
+ def receive_data(data, addr)
69
+ begin
70
+ msg = Gelfd2::Parser.parse(data)
71
+ rescue => e
72
+ log.warn 'Gelfd failed to parse a message', error: e.to_s
73
+ log.warn_backtrace
74
+ end
75
+
76
+ # Gelfd parser will return nil if it received and parsed a non-final chunk
77
+ return if msg.nil?
78
+
79
+ @parser.parse(msg) { |time, record|
80
+ unless time && record
81
+ log.warn "pattern not match: #{msg.inspect}"
82
+ return
83
+ end
84
+
85
+ # Use the recorded event time if available
86
+ time = Fluent::EventTime.from_time(Time.at(record.delete('timestamp').to_f) ) if record.key?('timestamp')
87
+
88
+ # Postprocess recorded event
89
+ strip_leading_underscore_(record) if @strip_leading_underscore
90
+
91
+ emit(time, record)
92
+ }
93
+ rescue => e
94
+ log.error data.dump, error: e.to_s
95
+ log.error_backtrace
96
+ end
97
+
98
+ def listen
99
+ log.info "listening gelf socket on #{@bind}:#{@port} with #{@protocol_type}"
100
+ if @protocol_type == :tcp
101
+ server_create(:in_tcp_server, @port, bind: @bind) do |data, conn|
102
+ receive_data(data, conn)
103
+ end
104
+ else
105
+ server_create(:in_udp_server, @port, proto: :udp, bind: @bind, max_bytes: 8192) do |data, sock|
106
+ receive_data(data, sock)
107
+ end
108
+ end
109
+ end
110
+
111
+ def emit(time, record)
112
+ router.emit(@tag, time, record)
113
+ rescue => e
114
+ log.error 'gelf failed to emit', error: e.to_s, error_class: e.class.to_s, tag: @tag, record: Yajl.dump(record)
115
+ end
116
+
117
+ private
118
+
119
+ def strip_leading_underscore_(record)
120
+ record.keys.each { |k|
121
+ next unless k[0,1] == '_'
122
+ record[k[1..-1]] = record.delete(k)
123
+ }
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,115 @@
1
+ require_relative '../test_helper'
2
+ require 'gelf'
3
+
4
+ class GelfInputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ PORT = 12345
10
+ BASE_CONFIG = %[
11
+ port #{PORT}
12
+ protocol_type udp
13
+ tag gelf
14
+ ]
15
+ CONFIG = BASE_CONFIG + %!
16
+ bind 127.0.0.1
17
+ !
18
+ IPv6_CONFIG = BASE_CONFIG + %!
19
+ bind ::1
20
+ !
21
+
22
+ def create_driver(conf)
23
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::GelfInput).configure(conf)
24
+ end
25
+
26
+ def test_configure
27
+ configs = {'127.0.0.1' => CONFIG}
28
+ configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
29
+
30
+ configs.each_pair { |k, v|
31
+ d = create_driver(v)
32
+ assert_equal PORT, d.instance.port
33
+ assert_equal k, d.instance.bind
34
+ assert_equal 'json', d.instance.parser_configs.first["@type"]
35
+ }
36
+ end
37
+
38
+ def test_parse
39
+ configs = {'127.0.0.1' => CONFIG}
40
+ # gelf-rb currently does not support IPv6 over UDP
41
+ # configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
42
+
43
+ configs.each_pair { |k, v|
44
+ d = create_driver(v)
45
+
46
+ tests = [
47
+ {:short_message => 'short message', :full_message => 'full message'},
48
+ {:short_message => 'short message', :full_message => 'full message', :timestamp => 12345678.12345}
49
+ ]
50
+
51
+ d.run(expect_emits: 2) do
52
+ n = GELF::Notifier.new(k, PORT)
53
+
54
+ tests.each { |test|
55
+ n.notify!(test)
56
+ }
57
+ end
58
+
59
+ emits = d.events
60
+ assert_equal tests.length, emits.length, 'missing emitted events'
61
+ emits.each_index { |i|
62
+ assert_equal 'gelf', emits[i][0]
63
+ assert_equal tests[i][:timestamp].to_f, emits[i][1] unless tests[i][:timestamp].nil?
64
+ assert_equal tests[i][:short_message], emits[i][2]['short_message']
65
+ assert_equal tests[i][:full_message], emits[i][2]['full_message']
66
+ }
67
+ }
68
+ end
69
+
70
+ def test_strip_leading_underscore
71
+ configs = {'127.0.0.1' => CONFIG}
72
+ # gelf-rb currently does not support IPv6 over UDP
73
+ # configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
74
+
75
+ configs.each_pair { |k, v|
76
+ d = create_driver(v)
77
+
78
+ tests = [
79
+ {:given =>
80
+ {
81
+ :timestamp => 12345,
82
+ :short_message => 'short message',
83
+ :full_message => 'full message',
84
+ '_custom_field' => 12345
85
+ },
86
+ :expected =>
87
+ {
88
+ 'short_message' => 'short message',
89
+ 'full_message' => 'full message',
90
+ 'custom_field' => 12345
91
+ }
92
+ }
93
+ ]
94
+
95
+ d.run(expect_emits: 1) do
96
+ n = GELF::Notifier.new(k, PORT)
97
+
98
+ tests.each { |test|
99
+ n.notify!(test[:given])
100
+ }
101
+ end
102
+
103
+ emits = d.events
104
+ assert_equal tests.length, emits.length, 'missing emitted events'
105
+ emits.each_index { |i|
106
+ assert_equal 'gelf', emits[i][0]
107
+ assert_equal tests[i][:timestamp].to_f, emits[i][1] unless tests[i][:timestamp].nil?
108
+ assert_block "expectation not met: #{tests[i][:expected]}" do
109
+ emits[i][2].merge(tests[i][:expected]) == emits[i][2]
110
+ end
111
+ }
112
+ }
113
+ end
114
+
115
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+
15
+ require 'fluent/test'
16
+ require 'fluent/test/driver/input'
17
+ require 'fluent/plugin/in_gelf'
18
+
19
+ def unused_port
20
+ s = TCPServer.open(0)
21
+ port = s.addr[1]
22
+ s.close
23
+ port
24
+ end
25
+
26
+ def ipv6_enabled?
27
+ require 'socket'
28
+
29
+ begin
30
+ TCPServer.open("::1", 0)
31
+ true
32
+ rescue
33
+ false
34
+ end
35
+ end
36
+
37
+ class Test::Unit::TestCase
38
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-input-gelf-kolyunya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Ostroushko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-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.14.10
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.14.10
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: gelfd2
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.3.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: gelf
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.0.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.0.0
103
+ description: Fork A GELF input plugin for fluentd
104
+ email: n.ostroushko@mts.ai
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - fluent-plugin-input-gelf.gemspec
116
+ - lib/fluent/plugin/in_gelf.rb
117
+ - test/plugin/test_in_gelf.rb
118
+ - test/test_helper.rb
119
+ homepage: https://github.com/koxx009/fluent-plugin-input-gelf-kolyunya
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.7.0
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.1.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Fork A GELF input plugin for fluentd
142
+ test_files: []