Module: RequestLogAnalyzer::Request::Converters
- Included in:
- RequestLogAnalyzer::Request
- Defined in:
- lib/request_log_analyzer/request.rb
Instance Method Summary (collapse)
- - (Object) convert_decimal(value, capture_definition)
-
- (Object) convert_duration(value, capture_definition)
Convert duration fields to float, and make sure the values are in seconds.
-
- (Object) convert_epoch(value, capture_definition)
Convert an epoch to an integer.
-
- (Object) convert_eval(value, capture_definition)
Converts :eval field, which should evaluate to a hash.
- - (Object) convert_float(value, capture_definition)
- - (Object) convert_int(value, capture_definition)
- - (Object) convert_integer(value, capture_definition)
- - (Object) convert_nillable_string(value, definition)
-
- (Object) convert_path(value, definition)
This function can be overridden to rewrite the path for better categorization in the reports.
- - (Object) convert_string(value, capture_definition)
- - (Object) convert_sym(value, capture_definition)
- - (Object) convert_symbol(value, capture_definition)
-
- (Object) convert_timestamp(value, capture_definition)
Slow default method to parse timestamps.
-
- (Object) convert_traffic(value, capture_definition)
Converts traffic fields to (whole) bytes based on the given unit.
-
- (Object) convert_value(value, capture_definition)
Default converter function, which converts the parsed strings to a native Ruby type using the type indication in the line definition.
-
- (Object) sanitize_parameters(parameter_string)
Removes certain string sequences which would be problematic for eval.
Instance Method Details
- (Object) convert_decimal(value, capture_definition)
25 |
# File 'lib/request_log_analyzer/request.rb', line 25 def convert_decimal(value, capture_definition); value.to_f; end |
- (Object) convert_duration(value, capture_definition)
Convert duration fields to float, and make sure the values are in seconds.
74 75 76 77 78 79 80 81 |
# File 'lib/request_log_analyzer/request.rb', line 74 def convert_duration(value, capture_definition) case capture_definition[:unit] when nil, :sec, :s then value.to_f when :microsec, :musec then value.to_f / 1000000.0 when :msec, :millisec then value.to_f / 1000.0 else raise "Unknown duration unit" end end |
- (Object) convert_epoch(value, capture_definition)
Convert an epoch to an integer
84 85 86 |
# File 'lib/request_log_analyzer/request.rb', line 84 def convert_epoch(value, capture_definition) Time.at(value.to_i).strftime('%Y%m%d%H%M%S').to_i end |
- (Object) convert_eval(value, capture_definition)
Converts :eval field, which should evaluate to a hash.
39 40 41 42 43 44 |
# File 'lib/request_log_analyzer/request.rb', line 39 def convert_eval(value, capture_definition) eval(sanitize_parameters(value)).inject({}) { |h, (k, v)| h[k.to_sym] = v; h} # Wide range of errors possible with wild eval. ATM we choose to crash on this. rescue SyntaxError nil end |
- (Object) convert_float(value, capture_definition)
24 |
# File 'lib/request_log_analyzer/request.rb', line 24 def convert_float(value, capture_definition); value.to_f; end |
- (Object) convert_int(value, capture_definition)
26 |
# File 'lib/request_log_analyzer/request.rb', line 26 def convert_int(value, capture_definition); value.to_i; end |
- (Object) convert_integer(value, capture_definition)
27 |
# File 'lib/request_log_analyzer/request.rb', line 27 def convert_integer(value, capture_definition); value.to_i; end |
- (Object) convert_nillable_string(value, definition)
30 |
# File 'lib/request_log_analyzer/request.rb', line 30 def convert_nillable_string(value, definition); value == '-' ? nil : value ; end |
- (Object) convert_path(value, definition)
This function can be overridden to rewrite the path for better categorization in the reports.
34 35 36 |
# File 'lib/request_log_analyzer/request.rb', line 34 def convert_path(value, definition) value end |
- (Object) convert_string(value, capture_definition)
23 |
# File 'lib/request_log_analyzer/request.rb', line 23 def convert_string(value, capture_definition); value; end |
- (Object) convert_sym(value, capture_definition)
28 |
# File 'lib/request_log_analyzer/request.rb', line 28 def convert_sym(value, capture_definition); value.to_sym; end |
- (Object) convert_symbol(value, capture_definition)
29 |
# File 'lib/request_log_analyzer/request.rb', line 29 def convert_symbol(value, capture_definition); value.to_sym; end |
- (Object) convert_timestamp(value, capture_definition)
Slow default method to parse timestamps. Reimplement this function in a file format specific Request class to improve the timestamp parsing speed.
55 56 57 |
# File 'lib/request_log_analyzer/request.rb', line 55 def (value, capture_definition) DateTime.parse(value).strftime('%Y%m%d%H%M%S').to_i end |
- (Object) convert_traffic(value, capture_definition)
Converts traffic fields to (whole) bytes based on the given unit.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/request_log_analyzer/request.rb', line 60 def convert_traffic(value, capture_definition) case capture_definition[:unit] when nil, :b, :B, :byte then value.to_i when :GB, :G, :gigabyte then (value.to_f * 1000_000_000).round when :GiB, :gibibyte then (value.to_f * (2 ** 30)).round when :MB, :M, :megabyte then (value.to_f * 1000_000).round when :MiB, :mebibyte then (value.to_f * (2 ** 20)).round when :KB, :K, :kilobyte, :kB then (value.to_f * 1000).round when :KiB, :kibibyte then (value.to_f * (2 ** 10)).round else raise "Unknown traffic unit" end end |
- (Object) convert_value(value, capture_definition)
Default converter function, which converts the parsed strings to a native Ruby type using the type indication in the line definition. It will use a custom connverter method if one is available.
17 18 19 20 21 |
# File 'lib/request_log_analyzer/request.rb', line 17 def convert_value(value, capture_definition) return capture_definition[:default] if value.nil? custom_converter_method = :convert_#{capture_definition[:type]}" send(custom_converter_method, value, capture_definition) end |
- (Object) sanitize_parameters(parameter_string)
Removes certain string sequences which would be problematic for eval. TODO remove all characters not valid in ruby symbols
48 49 50 |
# File 'lib/request_log_analyzer/request.rb', line 48 def sanitize_parameters(parameter_string) parameter_string.gsub(/#</, '"').gsub(/>,/, '", ').gsub(/\\0/, '') end |