From 5540026038c8e5639c62c6ebd2115a3be4d11200 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Thu, 19 Mar 2020 17:41:11 +0900 Subject: [PATCH 1/3] Use v1 plugin API Signed-off-by: Masahiro Nakagawa --- lib/fluent/plugin/out_splunk_hec.rb | 23 ++++++++++++++--------- lib/fluent/plugin/out_splunk_tcp.rb | 20 ++++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/fluent/plugin/out_splunk_hec.rb b/lib/fluent/plugin/out_splunk_hec.rb index cb6ef36..1875d7c 100644 --- a/lib/fluent/plugin/out_splunk_hec.rb +++ b/lib/fluent/plugin/out_splunk_hec.rb @@ -1,14 +1,17 @@ -require 'fluent/output' +require 'fluent/plugin/output' require 'httpclient' require 'json' +require 'yajl' require 'securerandom' # http://dev.splunk.com/view/event-collector/SP-CAAAE6P -module Fluent - class SplunkHECOutput < ObjectBufferedOutput +module Fluent::Plugin + class SplunkHECOutput < Output Fluent::Plugin.register_output('splunk_hec', self) + helpers :compat_parameters + config_param :host, :string config_param :port, :integer config_param :token, :string @@ -52,6 +55,8 @@ class SplunkHECOutput < ObjectBufferedOutput config_param :client_key_pass, :string, default: nil def configure(conf) + compat_parameters_convert(conf, :buffer) + super if @channel && @auto_generate_channel @@ -60,10 +65,10 @@ def configure(conf) @channel = SecureRandom.uuid if @auto_generate_channel - raise ConfigError, "'channel' parameter is required when 'use_ack' is true" if @use_ack && !@channel - raise ConfigError, "'ack_interval' parameter must be a non negative integer" if @use_ack && @ack_interval < 0 - raise ConfigError, "'event_key' parameter is required when 'raw' is true" if @raw && !@event_key - raise ConfigError, "'channel' parameter is required when 'raw' is true" if @raw && !@channel + raise Fluent::ConfigError, "'channel' parameter is required when 'use_ack' is true" if @use_ack && !@channel + raise Fluent::ConfigError, "'ack_interval' parameter must be a non negative integer" if @use_ack && @ack_interval < 0 + raise Fluent::ConfigError, "'event_key' parameter is required when 'raw' is true" if @raw && !@event_key + raise Fluent::ConfigError, "'channel' parameter is required when 'raw' is true" if @raw && !@channel @default_sourcetype = @sourcetype if @sourcetype && !@default_sourcetype @@ -90,7 +95,7 @@ def shutdown super end - def write_objects(_tag, chunk) + def write(chunk) return if chunk.empty? payload = '' @@ -119,7 +124,7 @@ def setup_client def format_event(time, record) msg = {'event' => record} if @use_fluentd_time - msg['time'] = time.respond_to?('to_f') ? time.to_f : time + msg['time'] = time.to_f end # metadata diff --git a/lib/fluent/plugin/out_splunk_tcp.rb b/lib/fluent/plugin/out_splunk_tcp.rb index c0e1873..45b5f06 100644 --- a/lib/fluent/plugin/out_splunk_tcp.rb +++ b/lib/fluent/plugin/out_splunk_tcp.rb @@ -1,5 +1,5 @@ -require 'fluent/output' -require 'fluent/formatter' +require 'fluent/plugin/output' +require 'fluent/time' require 'fluent/config/error' require 'socket' require 'openssl' @@ -7,10 +7,12 @@ # http://dev.splunk.com/view/event-collector/SP-CAAAE6P -module Fluent - class SplunkTCPOutput < ObjectBufferedOutput +module Fluent::Plugin + class SplunkTCPOutput < Output Fluent::Plugin.register_output('splunk_tcp', self) + helpers :compat_parameters + config_param :host, :string config_param :port, :integer @@ -43,11 +45,13 @@ def implement?(feature) end def configure(conf) + compat_parameters_convert(conf, :buffer) + super case @time_format when 'unixtime' - @time_formatter = lambda {|time| time } + @time_formatter = lambda {|time| time.to_i } else @timef = Fluent::TimeFormatter.new(@time_format, @localtime) @time_formatter = lambda {|time| @timef.format(time) } @@ -68,11 +72,11 @@ def configure(conf) end when 'raw' unless @event_key - raise ConfigError, "'event_key' option is required for format 'raw'" + raise Fluent::ConfigError, "'event_key' option is required for format 'raw'" end @formatter = lambda {|_time, record| record[@event_key] || '' } else - raise ConfigError, "invalid 'format' option: #{@format}" + raise Fluent::ConfigError, "invalid 'format' option: #{@format}" end end @@ -88,7 +92,7 @@ def shutdown super end - def write_objects(_tag, chunk) + def write(chunk) return if chunk.empty? payload = '' From 4d49b649f8c25e32b304134d79d6c9574c1daba0 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Thu, 19 Mar 2020 17:43:28 +0900 Subject: [PATCH 2/3] Update README Signed-off-by: Masahiro Nakagawa --- README.hec.md | 4 +++- README.tcp.md | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.hec.md b/README.hec.md index 29fc363..031cd30 100644 --- a/README.hec.md +++ b/README.hec.md @@ -57,7 +57,9 @@ ca_file /path/to/ca.pem # buffered output parameter - flush_interval 10s + + flush_interval 10s + ``` diff --git a/README.tcp.md b/README.tcp.md index b2b0ecd..bef70f6 100644 --- a/README.tcp.md +++ b/README.tcp.md @@ -46,7 +46,9 @@ ca_file /path/to/ca.pem # buffered output parameter - flush_interval 10s + + flush_interval 10s + ``` @@ -70,7 +72,9 @@ This example shows json format. ca_file /path/to/ca.pem # flush - flush_interval 10s + + flush_interval 10s + ``` From 0fa0cf3d240c7235969dd6b2357756403721be65 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Thu, 19 Mar 2020 17:44:32 +0900 Subject: [PATCH 3/3] Update fluentd version dependency Signed-off-by: Masahiro Nakagawa --- fluent-plugin-splunk-enterprise.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-splunk-enterprise.gemspec b/fluent-plugin-splunk-enterprise.gemspec index c2b0c6b..d09a4a7 100644 --- a/fluent-plugin-splunk-enterprise.gemspec +++ b/fluent-plugin-splunk-enterprise.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'fluentd', [">= 0.12.0"] + spec.add_dependency 'fluentd', [">= 1"] spec.add_dependency 'json' spec.add_dependency 'httpclient'