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

Methods inherited from SplunkOutput

#write

Constructor Details

#initialize ⇒ SplunkHecOutput

Returns a new instance of SplunkHecOutput.



121
122
123
124
125
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 121

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

Instance Method Details

#configure(conf) ⇒ Object



127
128
129
130
131
132
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 127

def configure(conf)
  super

  check_metric_configs
  pick_custom_format_method
end

#format(tag, time, record) ⇒ Object



158
159
160
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 158

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

#multi_workers_ready? ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 162

def multi_workers_ready?
  true
end

#shutdown ⇒ Object



153
154
155
156
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 153

def shutdown
  super
  @conn.shutdown
end

#start ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/fluent/plugin/out_splunk_hec.rb', line 134

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.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