From 9363c64c91acf6736870fa8bc95d25fb37425ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Kopp?= Date: Wed, 10 Nov 2021 19:46:55 +0100 Subject: [PATCH] fix copy command and timestamp (#34) --- scripts/log2sql.pl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/log2sql.pl b/scripts/log2sql.pl index 405ee71..dffe705 100755 --- a/scripts/log2sql.pl +++ b/scripts/log2sql.pl @@ -84,8 +84,8 @@ while(my $line = ){ $lines_read++; $line =~ s/\n$//; - my ($remote_addr,$time_local, $remote_user, $method, $request, $protocol, $status, $body_bytes_sent,$http_referer, $http_user_agent, $unit) = - $line =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) - ([^\s]+) \[(\d{2})\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} \+\d{4}\] +"([A-Z]+) ([^" ]*) ([^" ]*)" (2\d\d) ([-\d]*) "([^"]*)" "([^"]*)" [^\s]* [^\s]* [^\s](?: .*billing:infclen=(\d+))?/; + my ($remote_addr, $remote_user, $time_local, $method, $request, $protocol, $status, $body_bytes_sent,$http_referer, $http_user_agent, $unit) = + $line =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) - ([^\s]+) \[(\d{2}\/\w{3}\/\d{4}:\d{2}:\d{2}:\d{2} \+\d{4})\] +"([A-Z]+) ([^" ]*) ([^" ]*)" (2\d\d) ([-\d]*) "([^"]*)" "([^"]*)" [^\s]* [^\s]* [^\s](?: .*billing:infclen=(\d+))?/; $unit //=0; if($status && $request !~ /$ignore/){ $last_read_line_checksum = Digest::MD5::md5_hex($line); @@ -112,10 +112,7 @@ INTO log_files(file_id, file_name, first_line_checksum, last_read_line_checksum, lines_read, lines_valid, tail) VALUES($file_id,'$log_file','$first_line_checksum', '$last_read_line_checksum', $lines_read, $lines_valid,FALSE); -COPY log_file_entries(file_id, service_id, line_number, line_checksum, remote_addr, remote_user, time_local, method, request, protocol, status, body_bytes_sent, http_referer, http_user_agent, unit) -FROM '$dump_file' -WITH - DELIMITER AS '\\t'; +\\copy log_file_entries(file_id, service_id, line_number, line_checksum, remote_addr, remote_user, time_local, method, request, protocol, status, body_bytes_sent, http_referer, http_user_agent, unit) from '$dump_file' "; close FILE; }