Class: CloudwatchQuery::Parsers::Rails::RequestSubParser

Inherits:
Object
  • Object
show all
Includes:
SubParser
Defined in:
lib/cloudwatch_query/parsers/rails/sub_parsers.rb

Overview

Parses: "Started GET "/path" for 1.2.3.4 at 2026-02-04 18:37:21 +0000"

Constant Summary collapse

REQUEST_REGEX =
/Started\s+(?<http_method>GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+"(?<path>[^"]+)"\s+for\s+(?<ip_address>[\d.]+)\s+at\s+(?<timestamp>.+)$/

Class Method Summary collapse

Methods included from SubParser

included

Class Method Details

.matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/cloudwatch_query/parsers/rails/sub_parsers.rb', line 29

def self.matches?(message)
  message.include?("Started ") &&
    (message.include?(" GET ") || message.include?(" POST ") ||
     message.include?(" PUT ") || message.include?(" PATCH ") ||
     message.include?(" DELETE "))
end

.parse(message, _base_data) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cloudwatch_query/parsers/rails/sub_parsers.rb', line 36

def self.parse(message, _base_data)
  match = message.match(REQUEST_REGEX)
  return {} unless match

  {
    line_type: :request,
    http_method: match[:http_method],
    path: match[:path],
    ip_address: match[:ip_address],
    request_timestamp: match[:timestamp]
  }
end