class SumologicConnection
Constants
- COMPRESS_DEFLATE
- COMPRESS_GZIP
Attributes
http[R]
Public Class Methods
new(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies, sumo_client, compress_enabled, compress_encoding)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 15 def initialize(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies, sumo_client, compress_enabled, compress_encoding) @endpoint = endpoint @sumo_client = sumo_client create_http_client(verify_ssl, connect_timeout, proxy_uri, disable_cookies) @compress = compress_enabled @compress_encoding = (compress_encoding ||= COMPRESS_GZIP).downcase unless [COMPRESS_DEFLATE, COMPRESS_GZIP].include? @compress_encoding raise "Invalid compression encoding #{@compress_encoding} must be gzip or deflate" end end
Public Instance Methods
compress(content)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 81 def compress(content) if @compress if @compress_encoding == COMPRESS_GZIP result = gzip(content) result.bytes.to_a.pack("c*") else Zlib::Deflate.deflate(content) end else content end end
create_http_client(verify_ssl, connect_timeout, proxy_uri, disable_cookies)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 72 def create_http_client(verify_ssl, connect_timeout, proxy_uri, disable_cookies) @http = HTTPClient.new(proxy_uri) @http.ssl_config.verify_mode = ssl_options(verify_ssl) @http.connect_timeout = connect_timeout if disable_cookies @http.cookie_manager = nil end end
gzip(content)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 94 def gzip(content) stream = StringIO.new("w") stream.set_encoding("ASCII") gz = Zlib::GzipWriter.new(stream) gz.mtime=1 # Ensure that for same content there is same output gz.write(content) gz.close stream.string.bytes.to_a.pack("c*") end
publish(raw_data, source_host=nil, source_category=nil, source_name=nil, data_type, metric_data_type, collected_fields, dimensions)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 27 def publish(raw_data, source_host=nil, source_category=nil, source_name=nil, data_type, metric_data_type, collected_fields, dimensions) response = http.post(@endpoint, compress(raw_data), request_headers(source_host, source_category, source_name, data_type, metric_data_type, collected_fields, dimensions)) unless response.ok? raise RuntimeError, "Failed to send data to HTTP Source. #{response.code} - #{response.body}" end end
request_headers(source_host, source_category, source_name, data_type, metric_data_format, collected_fields, dimensions)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 34 def request_headers(source_host, source_category, source_name, data_type, metric_data_format, collected_fields, dimensions) headers = { 'X-Sumo-Name' => source_name, 'X-Sumo-Category' => source_category, 'X-Sumo-Host' => source_host, 'X-Sumo-Client' => @sumo_client, } if @compress headers['Content-Encoding'] = @compress_encoding end if data_type == 'metrics' case metric_data_format when 'graphite' headers['Content-Type'] = 'application/vnd.sumologic.graphite' when 'carbon2' headers['Content-Type'] = 'application/vnd.sumologic.carbon2' when 'prometheus' headers['Content-Type'] = 'application/vnd.sumologic.prometheus' else raise RuntimeError, "Invalid #{metric_data_format}, must be graphite or carbon2 or prometheus" end unless dimensions.nil? headers['X-Sumo-Dimensions'] = dimensions end end unless collected_fields.nil? headers['X-Sumo-Fields'] = collected_fields end return headers end
ssl_options(verify_ssl)
click to toggle source
# File lib/fluent/plugin/out_sumologic.rb, line 68 def ssl_options(verify_ssl) verify_ssl==true ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE end