Class: Fluent::Plugin::SplunkHecOutput

Inherits:
SplunkOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_splunk_hec.rb

Constant Summary collapse

KEY_FIELDS =
%w[index time host source sourcetype metric_name metric_value].freeze
TAG_PLACEHOLDER =
'${tag}'.freeze
MISSING_FIELD =
Hash.new do |_h, k|
  $log.warn "expected field #{k} but it's missing" if defined?($log)
  MISSING_FIELD
end.freeze

Instance Method Summary collapse

Constructor Details

#initializeSplunkHecOutput

Returns a new instance of SplunkHecOutput.



133
134
135
136
137
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 133

def initialize
  super
  @default_host = Socket.gethostname
  @extra_fields = nil
end

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


139
140
141
142
143
144
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 139

def configure(conf)
  super
  raise Fluent::ConfigError, 'One of `hec_host` or `full_url` is required.' if @hec_host.empty? && @full_url.empty?
  check_metric_configs
  pick_custom_format_method
end

#format(tag, time, record) ⇒ Object



176
177
178
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 176

def format(tag, time, record)
  # this method will be replaced in `configure`
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 180

def multi_workers_ready?
  true
end

#shutdownObject



171
172
173
174
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 171

def shutdown
  @conn.shutdown if not @conn.nil?
  super
end

#startObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 150

def start
  super
  @conn = Net::HTTP::Persistent.new.tap do |c|
    c.verify_mode = @insecure_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
    c.cert = OpenSSL::X509::Certificate.new File.read(@client_cert) if @client_cert
    c.key = OpenSSL::PKey::RSA.new File.read(@client_key) if @client_key
    c.ca_file = @ca_file
    c.ca_path = @ca_path
    c.ciphers = @ssl_ciphers
    c.proxy   = :ENV
    c.min_version = OpenSSL::SSL::TLS1_1_VERSION if @require_ssl_min_version

    c.override_headers['Content-Type'] = 'application/json'
    c.override_headers['User-Agent'] = "fluent-plugin-splunk_hec_out/#{VERSION}"
    c.override_headers['Authorization'] = "Splunk #{@hec_token}"
    c.override_headers['__splunk_app_name'] = "#{@app_name}"
    c.override_headers['__splunk_app_version'] = "#{@app_version}"

  end
end

#write(chunk) ⇒ Object



146
147
148
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 146

def write(chunk)
  super
end