Class: Fluent::HttpsJsonOutput
- Inherits:
-
TimeSlicedOutput
- Object
- TimeSlicedOutput
- Fluent::HttpsJsonOutput
- Defined in:
- lib/fluent/plugin/out_https_json.rb
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
-
#format(tag, time, record) ⇒ Object
Optionally, you can use to_msgpack to serialize the object.
-
#initialize ⇒ HttpsJsonOutput
constructor
A new instance of HttpsJsonOutput.
-
#shutdown ⇒ Object
This method is called when shutting down.
-
#start ⇒ Object
This method is called when starting.
-
#write(chunk) ⇒ Object
This method is called every flush interval.
Constructor Details
#initialize ⇒ HttpsJsonOutput
Returns a new instance of HttpsJsonOutput.
6 7 8 9 10 11 |
# File 'lib/fluent/plugin/out_https_json.rb', line 6 def initialize require 'net/http' require 'net/https' require 'uri' super end |
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting. ‘conf’ is a Hash that includes configuration parameters. If the configuration is invalid, raise Fluent::ConfigError.
16 17 18 19 20 21 22 23 |
# File 'lib/fluent/plugin/out_https_json.rb', line 16 def configure(conf) super @uri = URI.parse(conf['endpoint']) @http = Net::HTTP.new(@uri.host,@uri.port) @https = Net::HTTP.new(@uri.host,@uri.port) @https.use_ssl = true @use_https = conf['use_https'] == 'true' end |
#format(tag, time, record) ⇒ Object
Optionally, you can use to_msgpack to serialize the object.
38 39 40 |
# File 'lib/fluent/plugin/out_https_json.rb', line 38 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
This method is called when shutting down. Shutdown the thread and close sockets or files here.
33 34 35 |
# File 'lib/fluent/plugin/out_https_json.rb', line 33 def shutdown super end |
#start ⇒ Object
This method is called when starting. Open sockets or files here.
27 28 29 |
# File 'lib/fluent/plugin/out_https_json.rb', line 27 def start super end |
#write(chunk) ⇒ Object
This method is called every flush interval. Write the buffer chunk to files or databases here. ‘chunk’ is a buffer chunk that includes multiple formatted events. You can use ‘data = chunk.read’ to get all events and ‘chunk.open {|io| … }’ to get IO objects.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fluent/plugin/out_https_json.rb', line 47 def write(chunk) events = [] chunk.msgpack_each {|(tag,time,record)| events << {:tag => tag, :time => time, :record => record} } events = events.to_json req = Net::HTTP::Post.new(@uri.path) req.set_form_data({"events" => events}) if @use_https res = @https.request(req) else res = @http.request(req) end end |