class Loggie::Logentries::Search

Main entry point to query a specific log source

Constants

BASE_URI
QUERY_PATH

Attributes

extract[R]
request[R]

Public Class Methods

new(query: nil, from: nil, to: nil, log_files: nil, block: nil) click to toggle source

@param [String] query: to perform @param [DateTime] from: query from date @param [DateTime] to: query to date @param [Array] log_files: list of log id files to search. default ENV

# File lib/loggie/logentries/search.rb, line 15
def initialize(query: nil, from: nil, to: nil, log_files: nil, block: nil)
  @query, @from, @to = query, from, to
  @log_files = log_files || Loggie.configuration.log_files
  @extract = Extract.new
  @request = Request.new(retry_mechanism: Retry.new(block: block))
end

Public Instance Methods

call(query: nil, from: nil, to: nil, log_files: nil) click to toggle source
# File lib/loggie/logentries/search.rb, line 22
def call(query: nil, from: nil, to: nil, log_files: nil)
  options = parsed_post_params(query || @query, from || @from, to || @to, log_files || @log_files)
  logger.debug "#{self.class} options:#{options}, url:#{url}"

  extract.call(request.call(url, method: :post, options: options))
end

Private Instance Methods

convert(time) click to toggle source
# File lib/loggie/logentries/search.rb, line 51
def convert(time)
  (time.to_f * 1000).floor
end
parsed_post_params(query, from, to, log_keys) click to toggle source

docs.logentries.com/docs/post-query

# File lib/loggie/logentries/search.rb, line 38
def parsed_post_params(query, from, to, log_keys)
  {
    logs: log_keys,
    leql: {
      during: {
        from: convert(from),
        to: convert(to)
      },
      statement: "where(#{query})"
    }
  }
end
url() click to toggle source
# File lib/loggie/logentries/search.rb, line 33
def url
  [BASE_URI, QUERY_PATH].join('/')
end