lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-1.1.3 vs lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-1.1.4
- old
+ new
@@ -54,13 +54,14 @@
end
# create initial sockets hash and socket based on config param
@end_point = URI.parse(@base_uri)
auth = {
- @api_key.nil? ? 'X-License_key' : 'X-Insert-Key' =>
+ @api_key.nil? ? 'X-License-Key' : 'X-Insert-Key' =>
@api_key.nil? ? @license_key : @api_key
}
+ puts auth
@header = {
'X-Event-Source' => 'logs',
'Content-Encoding' => 'gzip'
}.merge(auth)
.freeze
@@ -107,10 +108,15 @@
next if record.empty?
payload['logs'].push(package_record(record, ts))
end
io = StringIO.new
gzip = Zlib::GzipWriter.new(io)
+
+ # Fluentd can run with a version of Ruby (2.1.0) whose to_json method doesn't support non-ASCII characters.
+ # So we use Yajl, which can handle all Unicode characters. Apparently this library is what Fluentd uses
+ # internally, so it is installed by default with td-agent.
+ # See https://github.com/fluent/fluentd/issues/215
gzip << Yajl.dump([payload])
gzip.close
send_payload(io.string)
end
@@ -122,9 +128,10 @@
def send_payload(payload)
http = Net::HTTP.new(@end_point.host, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ puts @header
request = Net::HTTP::Post.new(@end_point.request_uri, @header)
request.body = payload
handle_response(http.request(request))
end