New logic

This commit is contained in:
Miguel Nogueira 2024-05-17 12:56:03 +01:00
parent ec07527653
commit 7ace0f471d
2 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,7 @@
require 'date' require 'date'
require_relative 'utils/http_codes' require_relative 'utils/http_codes'
require_relative 'utils/date_for_humans'
logfile = File.open("teambuilder.pt.log") logfile = File.open("teambuilder.pt.log")
data = logfile.read data = logfile.read
@ -19,6 +20,7 @@ def get_line_date(line)
pattern = /\[(.*?)\]/ pattern = /\[(.*?)\]/
match = line.match(pattern)[0] if line.match(pattern) match = line.match(pattern)[0] if line.match(pattern)
# [12/Apr/2023:13:56:41 +0100] -> 12/Apr/2023:13:56:41 +0100
Date.parse(match.gsub("[", "").gsub("]", "")) Date.parse(match.gsub("[", "").gsub("]", ""))
end end
@ -85,7 +87,6 @@ lines.each do |line|
code = get_line_code(line) code = get_line_code(line)
ua = get_line_ua(line) ua = get_line_ua(line)
#if code.to_i >= 400 && code.to_i < 500
if is_client_err?(code.to_i) if is_client_err?(code.to_i)
if client_errors[ip] if client_errors[ip]
client_errors[ip] += 1 client_errors[ip] += 1

12
utils/date_for_humans.rb Normal file
View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
# array with list of months in portuguese
# @return [Array] list of months in portuguese
def months
%w[janeiro fevereiro março abril maio junho julho agosto setembro outubro novembro dezembro]
end
# Returns the month in portuguese
def month_for_humans(month)
months[month - 1]
end