Class: Stackify::AgentHTTPSender

Inherits:
AgentBaseSender show all
Defined in:
lib/stackify/agent_http_sender.rb

Constant Summary collapse

HEADERS =
{
  'Content-Type' => 'application/json'
}

Instance Attribute Summary

Attributes inherited from Worker

#name, #type

Instance Method Summary collapse

Methods inherited from AgentBaseSender

#send_logs

Methods inherited from Worker

#alive?, #async_perform, #backtrace, #id, #initialize, #perform, #shutdown!, #status

Constructor Details

This class inherits a constructor from Stackify::Worker

Instance Method Details

#send_request(log_group) ⇒ Object

send_request() This function will post an http request return Object Return an object message



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stackify/agent_http_sender.rb', line 18

def send_request log_group
  begin
    conn = Faraday.new(proxy: Stackify.configuration.proxy, ssl: { verify: false })
    @response = conn.post do |req|
      req.url URI(Stackify.configuration.http_endpoint + Stackify.configuration.agent_log_url)
      req.headers = HEADERS
      req.body = log_group
    end
    if @response.try(:status) == 200
      Stackify.internal_log :debug, "[AgentHTTPSender]: Successfully send message via http request."
      return OpenStruct.new({status: 200, msg: 'OK'})
    else
      Stackify.internal_log :debug, "[AgentHTTPSender] Sending failed."
      return OpenStruct.new({status: 500, msg: 'Not OK'})
    end
  rescue => exception
    Stackify.log_internal_error "[AgentHTTPSender] send_logs() Error: #{exception}"
    return OpenStruct.new({status: 500, msg: exception})
  end
end