fluent-plugin-gelf-best 1.3.4 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a52f6ee827886a2037e01355541bc387a6bc057a9f1970801fe29c259fa0ac7e
4
- data.tar.gz: e7e605395d0d741227ecbb8baa94fdfc091374c1a7e8ad3329581b211b74939d
3
+ metadata.gz: f9741e4441ef5a4215766b19e56e248eaf3ed9cb5607b9972aaefee1a1c9ac0a
4
+ data.tar.gz: 1682a0cd4f716e8d693051c16256ecb6b68573ecf5ec5e718898f53a4cf3a63c
5
5
  SHA512:
6
- metadata.gz: 5afa18f1abaac29f41fbf61989e91c9dc59411567793d8f7f61aa1e6e8fce55fa4345f980338fea9ef54c9d07b2d4b74b12c8441e936d4c8331ba3daa9fde4b5
7
- data.tar.gz: 5b7737f5468e6dfe9c9704473af10848d57b993d4cbd7699e6bdd8692f59e877fc5b3d6edf4161531ab6b3e4bf8484a098cd8b3ae647e0c963f92f5abbd14ede
6
+ metadata.gz: 84aea4e3127272dfdcc7350160c244dee9a5eac9ecf8b500ae128dd6949373bb11b11fdc4dced1f3cc1497d26e5f8481867fd02eaaef50da344bdcd9d3dfca62
7
+ data.tar.gz: 1e489983a1df878009a64e2e07ef2b1163e5a3f45d57a340ebd3987977fb53800a32a5c9ea9a7248fe0fc396cffbdabd68faa93c0f40de184322b7c64a708322
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Fluentd GELF output and formatter plugins
2
+
3
+ [![CI](https://github.com/bmichalkiewicz/fluent-plugin-gelf-best/actions/workflows/ci.yml/badge.svg)](https://github.com/bmichalkiewicz/fluent-plugin-gelf-best/actions/workflows/ci.yml)
4
+
2
5
  This is a fork of the fluent-plugin-gelf-hs (https://github.com/hotschedules/fluent-plugin-gelf-hs), which is no longer maintained.
3
6
 
4
7
  ## Overview
@@ -23,10 +26,12 @@ For more info, review [Fluentd's official documentation](https://docs.fluentd.or
23
26
  ## Output plugin configuration
24
27
  ```
25
28
  <match **>
26
- type gelf
29
+ @type gelf
27
30
  host <remote GELF host>
28
31
  port <remote GELF port>
29
32
  protocol <tcp or udp (default)>
33
+ udp_transport_type <LAN or WAN (default)>
34
+ max_bytes <maximum field size in bytes (32000 default)>
30
35
  tls <true or false (default)>
31
36
  tls_options <{} (default)> for options see https://github.com/graylog-labs/gelf-rb/blob/72916932b789f7a6768c3cdd6ab69a3c942dbcef/lib/gelf/transport/tcp_tls.rb#L7-L12
32
37
  [ fluent buffered output plugin configuration ]
@@ -36,12 +41,37 @@ For more info, review [Fluentd's official documentation](https://docs.fluentd.or
36
41
  ## Formatter plugin configuration
37
42
  ```
38
43
  <match **>
39
- type file (any type that that takes a format argument)
40
- format gelf
44
+ @type file (any type that takes a format section)
45
+ <format>
46
+ @type gelf
47
+ </format>
41
48
  [ fluent file output plugin configuration ]
42
49
  </match>
43
50
  ```
44
51
 
52
+ ## Development
53
+
54
+ Install [Task](https://taskfile.dev) and run:
55
+
56
+ ```
57
+ task deps # install dependencies
58
+ task test # run the test suite
59
+ task build # build the gem
60
+ ```
61
+
62
+ ## Release
63
+
64
+ Bump the `VERSION` file, commit, then tag the release and push the tag:
65
+
66
+ ```
67
+ git tag v$(cat VERSION)
68
+ git push origin v$(cat VERSION)
69
+ ```
70
+
71
+ The `Release` GitHub Actions workflow verifies the tag against `VERSION`, runs the tests,
72
+ builds the gem, pushes it to RubyGems (requires the `RUBYGEMS_API_KEY` repository secret)
73
+ and creates a GitHub release.
74
+
45
75
  ## License
46
76
 
47
77
  fluent-plugin-gelf-best is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
@@ -1,16 +1,13 @@
1
1
  require "fluent/plugin/formatter"
2
2
  require "fluent/plugin/gelf_plugin_util"
3
- require "yajl"
3
+ require 'oj'
4
4
 
5
5
  module Fluent
6
- module TextFormatter
7
- class GelfFormatter < Formatter
6
+ module Plugin
7
+ class GelfFormatter < Fluent::Plugin::Formatter
8
+ Fluent::Plugin.register_formatter('gelf', self)
8
9
 
9
- unless method_defined?(:log)
10
- define_method('log') { $log }
11
- end
12
-
13
- Plugin.register_formatter("gelf", self)
10
+ define_method('log') { $log } unless method_defined?(:log)
14
11
 
15
12
  include Fluent::GelfPluginUtil
16
13
 
@@ -18,32 +15,24 @@ module Fluent
18
15
  config_param :add_msec_time, :bool, :default => false
19
16
  config_param :max_bytes, :integer, :default => 32000
20
17
 
21
- def configure(conf)
22
- super(conf)
23
- end
24
-
25
18
  def format(tag, time, record)
26
-
27
- begin
28
-
29
- gelfentry = make_gelfentry(
30
- tag,time,record,
31
- {
32
- :use_record_host => @use_record_host,
33
- :add_msec_time => @add_msec_time,
34
- :max_bytes => @max_bytes
35
- }
36
- )
37
-
38
- Yajl::Encoder.encode(make_gelfentry)
39
-
40
- rescue Exception => e
41
- log.error sprintf(
42
- 'Error trying to serialize %s: %s',
43
- record.to_s.force_encoding('UTF-8'),
44
- e.message.to_s.force_encoding('UTF-8')
45
- )
46
- end
19
+ gelfentry = make_gelfentry(
20
+ tag, time, record,
21
+ {
22
+ :use_record_host => @use_record_host,
23
+ :add_msec_time => @add_msec_time,
24
+ :max_bytes => @max_bytes
25
+ }
26
+ )
27
+
28
+ Oj.dump(gelfentry, mode: :compat)
29
+ rescue StandardError => e
30
+ log.error sprintf(
31
+ 'Error trying to serialize %s: %s',
32
+ record.to_s.force_encoding('UTF-8'),
33
+ e.message.to_s.force_encoding('UTF-8')
34
+ )
35
+ ''
47
36
  end
48
37
  end
49
38
  end
@@ -15,10 +15,10 @@ module Fluent
15
15
  }.freeze
16
16
 
17
17
  def make_gelfentry(tag, time, record, conf = {})
18
- gelfentry = {'_fluentd_tag' => tag, 'timestamp' => calculate_timestamp(time)}
18
+ gelfentry = {'_fluentd_tag' => tag, 'timestamp' => time}
19
19
 
20
20
  record.each_pair do |k, v|
21
- gelfentry.merge!(process_record_entry(k, v, conf, gelfentry))
21
+ gelfentry.merge!(process_record_entry(k, v, time, conf))
22
22
  end
23
23
 
24
24
  ensure_short_message(gelfentry)
@@ -27,27 +27,22 @@ module Fluent
27
27
 
28
28
  private
29
29
 
30
- def calculate_timestamp(time)
31
- if defined?(Fluent::EventTime) && time.is_a?(Fluent::EventTime)
32
- time.sec + (time.nsec.to_f / 1_000_000_000).round(3)
33
- else
34
- time
30
+ def process_record_entry(k, v, time, conf)
31
+ # Truncate values longer than max_bytes; scrub so a multibyte
32
+ # character cut in half does not produce invalid UTF-8
33
+ if conf[:max_bytes] && v.respond_to?(:bytesize) && v.bytesize > conf[:max_bytes]
34
+ v = "#{v.byteslice(0, conf[:max_bytes] - 3).scrub('')}..."
35
35
  end
36
- end
37
-
38
- def process_record_entry(k, v, conf, gelfentry)
39
- # Truncate values longer than max_bytes
40
- v = (v.respond_to?(:bytesize) && v.bytesize > conf[:max_bytes]) ? "#{v.byteslice(0, conf[:max_bytes] - 3)}..." : v
41
36
 
42
37
  case k
43
38
  when 'host', 'hostname'
44
- return {'host' => (conf[:use_record_host] ? v : gelfentry['_host'] = v)}
39
+ conf[:use_record_host] ? {'host' => v} : {'_host' => v}
45
40
  when 'timestamp', 'time'
46
41
  { 'timestamp' => parse_timestamp(v) }
47
42
  when 'level'
48
43
  {'level' => LEVEL_MAP[v.to_s.downcase[0]] || (v.to_s.length >= 2 && v.to_s.downcase[1] != "r" ? GELF::UNKNOWN : v)}
49
44
  when 'msec'
50
- conf[:add_msec_time] ? {'timestamp' => "#{time.to_s}.#{v}".to_f} : {'_msec' => v}
45
+ conf[:add_msec_time] ? {'timestamp' => "#{time.to_i}.#{v}".to_f} : {'_msec' => v}
51
46
  when 'short_message', 'version', 'full_message', 'facility', 'file', 'line'
52
47
  {k => v}
53
48
  else
@@ -77,7 +72,8 @@ module Fluent
77
72
  end
78
73
  end
79
74
 
80
- gelfentry['short_message'] = '(no message)' unless gelfentry['short_message']
75
+ # reached only when short_message is missing or blank and no fallback matched
76
+ gelfentry['short_message'] = '(no message)'
81
77
  end
82
78
  end
83
79
  end
@@ -14,6 +14,7 @@ module Fluent
14
14
  config_param :host, :string, :default => nil
15
15
  config_param :port, :integer, :default => 12201
16
16
  config_param :protocol, :string, :default => 'udp'
17
+ config_param :udp_transport_type, :string, :default => 'WAN'
17
18
  config_param :tls, :bool, :default => false
18
19
  config_param :tls_options, :hash, :default => {}
19
20
 
@@ -45,11 +46,20 @@ module Fluent
45
46
  # a destination hostname or IP address must be provided
46
47
  raise Fluent::ConfigError.new("'host' parameter (hostname or address of Graylog2 server) is required") unless conf.has_key?('host')
47
48
 
49
+ # validate udp_transport_type if protocol is udp
50
+ if @protocol == 'udp'
51
+ unless %w[WAN LAN].include?(@udp_transport_type)
52
+ raise Fluent::ConfigError.new("'udp_transport_type' parameter should be either 'WAN' or 'LAN'")
53
+ end
54
+ end
55
+
48
56
  # choose protocol to pass to gelf-rb Notifier constructor
49
- # (@protocol is used instead of conf['protocol'] to leverage config_param default)
50
- if @protocol == 'udp' then @proto = GELF::Protocol::UDP
51
- elsif @protocol == 'tcp' then @proto = GELF::Protocol::TCP
52
- else raise Fluent::ConfigError.new("'protocol' parameter should be either 'udp' (default) or 'tcp'")
57
+ if @protocol == 'udp'
58
+ @proto = GELF::Protocol::UDP
59
+ elsif @protocol == 'tcp'
60
+ @proto = GELF::Protocol::TCP
61
+ else
62
+ raise Fluent::ConfigError.new("'protocol' parameter should be either 'udp' (default) or 'tcp'")
53
63
  end
54
64
  end
55
65
 
@@ -64,7 +74,7 @@ module Fluent
64
74
  options[:tls] = @tls_options
65
75
  end
66
76
 
67
- @conn = GELF::Notifier.new(@host, @port, 'WAN', options)
77
+ @conn = GELF::Notifier.new(@host, @port, @udp_transport_type, options)
68
78
 
69
79
  # Errors are not coming from Ruby so we use direct mapping
70
80
  @conn.level_mapping = 'direct'
@@ -72,10 +82,6 @@ module Fluent
72
82
  @conn.collect_file_and_line = false
73
83
  end
74
84
 
75
- def shutdown
76
- super
77
- end
78
-
79
85
  def format(tag, time, record)
80
86
  if defined? Fluent::EventTime and time.is_a? Fluent::EventTime then
81
87
  timestamp = time.to_i + (time.nsec.to_f/1000000000).round(3)
@@ -92,12 +98,14 @@ module Fluent
92
98
  :max_bytes => @max_bytes
93
99
  }
94
100
  ).to_msgpack
95
- rescue Exception => e
101
+ rescue StandardError => e
96
102
  log.error sprintf(
97
103
  'Error trying to serialize %s: %s',
98
104
  record.to_s.force_encoding('UTF-8'),
99
105
  e.message.to_s.force_encoding('UTF-8')
100
106
  )
107
+ # skip the record instead of corrupting the chunk with nil
108
+ ''
101
109
  end
102
110
  end
103
111
 
@@ -105,7 +113,7 @@ module Fluent
105
113
  chunk.msgpack_each do |data|
106
114
  begin
107
115
  @conn.notify!(data)
108
- rescue Exception => e
116
+ rescue StandardError => e
109
117
  log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id
110
118
  raise e
111
119
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-gelf-best
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Yamauchi
8
8
  - Eric Searcy
9
- - Bartosz Michaliewicz
9
+ - Bartosz Michalkiewicz
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-08-27 00:00:00.000000000 Z
13
+ date: 2026-11-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -18,28 +18,42 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0
21
+ version: 1.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 1.0.0
28
+ version: 1.8.0
29
29
  - !ruby/object:Gem::Dependency
30
- name: gelf
30
+ name: gelf_redux
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.1.0
35
+ version: 4.1.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 3.1.0
42
+ version: 4.1.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: oj
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: test-unit
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -68,27 +82,26 @@ dependencies:
68
82
  - - ">="
69
83
  - !ruby/object:Gem::Version
70
84
  version: '0'
71
- description:
85
+ description: Fluentd output and formatter plugins for sending events to Graylog2 using
86
+ the GELF protocol (UDP/TCP, optional TLS).
72
87
  email:
73
88
  - bartosz.michalkiewicz@outlook.com
74
89
  executables: []
75
90
  extensions: []
76
91
  extra_rdoc_files: []
77
92
  files:
78
- - ".gitignore"
79
- - Gemfile
80
93
  - LICENSE
81
94
  - README.md
82
- - Rakefile
83
- - fluent-plugin-gelf-best.gemspec
84
- - lib/fluent-plugin-gelf-best/version.rb
85
95
  - lib/fluent/plugin/formatter_gelf.rb
86
96
  - lib/fluent/plugin/gelf_plugin_util.rb
87
97
  - lib/fluent/plugin/out_gelf.rb
88
98
  homepage: https://github.com/bmichalkiewicz/fluent-plugin-gelf-best
89
99
  licenses:
90
100
  - Apache-2.0
91
- metadata: {}
101
+ metadata:
102
+ homepage_uri: https://github.com/bmichalkiewicz/fluent-plugin-gelf-best
103
+ source_code_uri: https://github.com/bmichalkiewicz/fluent-plugin-gelf-best
104
+ bug_tracker_uri: https://github.com/bmichalkiewicz/fluent-plugin-gelf-best/issues
92
105
  post_install_message:
93
106
  rdoc_options: []
94
107
  require_paths:
@@ -97,15 +110,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
110
  requirements:
98
111
  - - ">="
99
112
  - !ruby/object:Gem::Version
100
- version: '0'
113
+ version: '2.7'
101
114
  required_rubygems_version: !ruby/object:Gem::Requirement
102
115
  requirements:
103
116
  - - ">="
104
117
  - !ruby/object:Gem::Version
105
118
  version: '0'
106
119
  requirements: []
107
- rubygems_version: 3.4.20
120
+ rubygems_version: 3.5.22
108
121
  signing_key:
109
122
  specification_version: 4
110
- summary: Sends Fluentd events Graylog2 by GELF
123
+ summary: Sends Fluentd events to Graylog2 by GELF
111
124
  test_files: []
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- **.gem
2
- **.gem.sha*
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new(:test) do |test|
5
- test.libs << 'test'
6
- test.pattern = 'test/**/test_*.rb'
7
- test.verbose = true
8
- test.warning = false
9
- end
10
-
11
- task :default => :test
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'fluent-plugin-gelf-best/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "fluent-plugin-gelf-best"
8
- spec.version = FluentPluginGelfBest::VERSION
9
- spec.authors = ["Alex Yamauchi", "Eric Searcy", "Bartosz Michaliewicz"]
10
- spec.licenses = ["Apache-2.0"]
11
- spec.email = ["bartosz.michalkiewicz@outlook.com"]
12
-
13
- spec.summary = "Sends Fluentd events Graylog2 by GELF"
14
- spec.homepage = "https://github.com/bmichalkiewicz/fluent-plugin-gelf-best"
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_runtime_dependency "fluentd", ">=1.0.0"
21
- spec.add_runtime_dependency "gelf", ">= 3.1.0"
22
- spec.add_development_dependency "test-unit"
23
- spec.add_development_dependency "rake"
24
- end
@@ -1,3 +0,0 @@
1
- module FluentPluginGelfBest
2
- VERSION = "1.3.4"
3
- end