Class: RequestLogAnalyzer::FileFormat::Rails3::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/request_log_analyzer/file_format/rails3.rb

Constant Summary collapse

MONTHS =

Used to handle conversion of abbrev. month name to a digit

%w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

Instance Attribute Summary

Attributes inherited from Request

#attributes, #file_format, #lines

Instance Method Summary collapse

Methods inherited from Request

#<<, #add_line_hash, #add_parsed_line, #completed?, create, #empty?, #every, #first, #first_lineno, #has_line_type?, #initialize, #last_lineno, #timestamp, #validate

Methods included from Request::Converters

#convert_decimal, #convert_duration, #convert_epoch, #convert_eval, #convert_float, #convert_int, #convert_integer, #convert_nillable_string, #convert_path, #convert_string, #convert_sym, #convert_symbol, #convert_traffic, #convert_value

Constructor Details

This class inherits a constructor from RequestLogAnalyzer::Request

Instance Method Details

#convert_timestamp(value, _definition) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/request_log_analyzer/file_format/rails3.rb', line 112

def convert_timestamp(value, _definition)
  # the time value can be in 2 formats:
  # - 2010-10-26 02:27:15 +0000 (ruby 1.9.2)
  # - Thu Oct 25 16:15:18 -0800 2010
  if value =~ /^#{CommonRegularExpressions::TIMESTAMP_PARTS['Y']}/
    value.gsub!(/\W/, '')
    value[0..13].to_i
  else
    value.gsub!(/\W/, '')
    time_as_str = value[-4..-1] # year
    # convert the month to a 2-digit representation
    month = MONTHS.index(value[3..5]) + 1
    month < 10 ? time_as_str << "0#{month}" : time_as_str << month.to_s

    time_as_str << value[6..13] # day of month + time
    time_as_str.to_i
  end
end

#sanitize_parameters(parameter_string) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/request_log_analyzer/file_format/rails3.rb', line 132

def sanitize_parameters(parameter_string)
  parameter_string.force_encoding("UTF-8")
    .gsub(/#</, '"')
    .gsub(/>, \"/, '", "')
    .gsub(/>>}/, '\""}') # #< ... >>}
    .gsub(/>>, \"/, '\"", "') # #< ... >>, "
    .gsub(/", @/, '\", @') # #< ... @content_type="image/jpeg", @ ... >>
    .gsub(/="/, '=\"') # #< ... filename="IMG_2228.JPG" Content-Type: image/jpeg", ... >>
    .gsub(/=\\", "/, '=", "') # redo "...hSMjag0w=\\",
    .gsub(/=\\"}/, '="}') # redo "...hSMjag0w=\\"}
    .gsub(/\\0/, '')
end