class LogEntry
Constants
- TIME_FORMAT
Attributes
ip[R]
resp_code[R]
time[R]
Public Class Methods
new(attrs)
click to toggle source
# File lib/log_entry.rb, line 8 def initialize(attrs) @ip, @resp_code, @time = attrs[:ip], attrs[:resp_code], attrs[:time] end
parse(line)
click to toggle source
Format here is definitely for nginx logs, but easily adaptable
192.168.0.128 - - [25/Jan/2019:06:57:32 +0000] "GET / HTTP/1.1" 200 708 "-" "Awsome Browser"
# File lib/log_entry.rb, line 14 def self.parse(line) ip_r = '(\d+\.\d+\.\d+\.\d+)' date_r = '\[(.*?)\]' str_r = '"(.*?)"' num_r = '(\d+)' regex = /#{ip_r} - - #{date_r} #{str_r} #{num_r} #{num_r} #{str_r} #{str_r}/ if(line =~ regex) ip, time, req, resp_code, bytes, _, agent = IP.new($1), $2, $3, $4, $5, $6, $7 time = Time.strptime(time, TIME_FORMAT) { ip: ip, resp_code: resp_code, time: time } end end
Public Instance Methods
redirect?()
click to toggle source
# File lib/log_entry.rb, line 29 def redirect? @resp_code == '301' end