Class: Stackify::AgentHTTPSender
- Inherits:
-
AgentBaseSender
- Object
- Worker
- AgentBaseSender
- Stackify::AgentHTTPSender
- Defined in:
- lib/stackify/agent_http_sender.rb
Constant Summary collapse
- HEADERS =
{ 'Content-Type' => 'application/x-protobuf' }
Instance Attribute Summary
Attributes inherited from Worker
Instance Method Summary collapse
-
#send_request(log_group) ⇒ Object
send_request() This function will post an http request return Object Return an object message.
Methods inherited from AgentBaseSender
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 38 39 |
# File 'lib/stackify/agent_http_sender.rb', line 18 def send_request log_group begin # Convert data into binary and send it to agent = Stackify::LogGroup.encode(log_group) 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 = 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 |