Sha256: 4d2d0b63ed307faef3ff41ec4c24ee88a42fde197a893409b93726e519c2c9fe

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'net_http_unix'
require 'ostruct'

#
# This class will handle the sending of protobuf message to unix domain socket
#
module Stackify
  class UnixSocketSender < AgentBaseSender

    # send_request() This function will send http request via unix domain socket
    # @msgs {Object} Protobuf message
    # return {Object} Return an object {status, message}
    def send_request log_group
      begin
        # Convert data into binary and send it to unix domain socket
        message = Stackify::LogGroup.encode(log_group)
        client = NetX::HTTPUnix.new('unix://' + Stackify.configuration.unix_socket_path)
        req = Net::HTTP::Post.new(Stackify.configuration.agent_log_url)
        req.set_content_type('application/x-protobuf')
        req.body = message
        response = client.request(req)
        Stackify.internal_log :debug, "[UnixSocketSender] status_code = #{response.code}"
        if response.code.to_i == 200
          Stackify.internal_log :debug, "[UnixSocketSender]: Successfully send message via unix domain socket."
          return OpenStruct.new({status: 200, msg: 'OK'})
        else
          Stackify.internal_log :debug, "[UnixSocketSender] Sending failed."
          return OpenStruct.new({status: 500, msg: 'Not OK'})
        end
      rescue => exception
        Stackify.log_internal_error "[UnixSocketSender] send_logs() Error: #{exception}"
        return OpenStruct.new({status: 500, msg: exception})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stackify-api-ruby-1.2.4 lib/stackify/unix_socket_sender.rb
stackify-api-ruby-1.2.3 lib/stackify/unix_socket_sender.rb