Module: Fluent::GridDBAuth
- Included in:
- Plugin::GriddbOutput
- Defined in:
- lib/fluent/plugin/griddb_auth.rb
Instance Method Summary collapse
-
#create_request(record) ⇒ Object
Create new request.
-
#format_url ⇒ Object
Get URL to API.
-
#send_request(req, uri) ⇒ Object
Send request.
-
#set_body(req, record) ⇒ Object
Set type for request body.
Instance Method Details
#create_request(record) ⇒ Object
Create new request
48 49 50 51 52 53 54 55 |
# File 'lib/fluent/plugin/griddb_auth.rb', line 48 def create_request(record) url = format_url() uri = URI.parse(URI.encode(url)) req = Net::HTTP::Put.new(uri.request_uri) req.basic_auth(@username, @password) set_body(req, record) return req, uri end |
#format_url ⇒ Object
Get URL to API
80 81 82 83 84 85 86 |
# File 'lib/fluent/plugin/griddb_auth.rb', line 80 def format_url() if $real_container.nil? || $real_container.empty? @host + "/griddb/v2/" + @cluster + "/dbs/" + @database + "/containers/" + @container + "/rows" else @host + "/griddb/v2/" + @cluster + "/dbs/" + @database + "/containers/" + $real_container + "/rows" end end |
#send_request(req, uri) ⇒ Object
Send request
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fluent/plugin/griddb_auth.rb', line 58 def send_request(req, uri) res = nil begin @last_request_time = Time.now.to_f res = Net::HTTP.start(uri.host, uri.port) {|http| http.request(req) } rescue => e log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.}'" raise e if @raise_on_error else unless res and res.is_a?(Net::HTTPSuccess) res_summary = if res "#{res.code} #{res.} #{res.body}" else "res=nil" end log.warn "failed to #{req.method} #{uri} (#{res_summary})" end end end |
#set_body(req, record) ⇒ Object
Set type for request body
42 43 44 45 |
# File 'lib/fluent/plugin/griddb_auth.rb', line 42 def set_body(req, record) req.body = Yajl.dump(record) req['Content-Type'] = 'application/json' end |