module StickyElephant::LogInterface

Private Instance Methods

connection_hash() click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 21
def connection_hash
  {
    source_ip: remote_address,
    dest_ip: local_address,
    source_port: remote_port,
    dest_port: local_port,
    raw: payload.raw.inspect
  }
end
local_address() click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 43
def local_address
  socket.local_address.ip_address.to_s
end
local_port() click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 47
def local_port
  socket.local_address.ip_port.to_s
end
log(level: , msg: ) click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 6
def log(level: , msg: )
  logger.send(level, remote_address) { string_from(msg) }
end
remote_address() click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 31
def remote_address
  begin
    socket.remote_address.ip_address.to_s
  rescue Errno::EINVAL
    "localhost"
  end
end
remote_port() click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 39
def remote_port
  socket.remote_address.ip_port.to_s
end
report_connection(hash = connection_hash) click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 17
def report_connection(hash = connection_hash)
  logger.event(:connection, JSON.dump(hash))
end
report_query(query) click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 10
def report_query(query)
  json = JSON.dump(
    connection_hash.merge( { query: query } )
  )
  logger.event(:query, json)
end
string_from(byte_array) click to toggle source
# File lib/sticky_elephant/log_interface.rb, line 51
def string_from(byte_array)
  if byte_array.is_a? Array
    byte_array.pack("C*")
  else
    byte_array
  end
end