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.



130
131
132
133
134
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 130

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

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


136
137
138
139
140
141
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 136

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



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

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

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


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

def multi_workers_ready?
  true
end

#shutdownObject



168
169
170
171
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 168

def shutdown
  super
  @conn.shutdown
end

#startObject



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

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



143
144
145
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 143

def write(chunk)
  super
end