ralf 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ **.gem
2
+ tmp/**
3
+ rdoc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+ gemspec
3
+ gem 'rspec'
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ralf (1.1.1)
5
+ chronic (~> 0.9.0)
6
+ logmerge (~> 1.0.3)
7
+ right_aws (~> 3.0.4)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ ZenTest (4.8.4)
13
+ autotest (4.4.6)
14
+ ZenTest (>= 4.4.1)
15
+ chronic (0.9.0)
16
+ diff-lcs (1.1.3)
17
+ fakeweb (1.3.0)
18
+ logmerge (1.0.3)
19
+ right_aws (3.0.4)
20
+ right_http_connection (>= 1.2.5)
21
+ right_http_connection (1.3.0)
22
+ rspec (2.12.0)
23
+ rspec-core (~> 2.12.0)
24
+ rspec-expectations (~> 2.12.0)
25
+ rspec-mocks (~> 2.12.0)
26
+ rspec-core (2.12.2)
27
+ rspec-expectations (2.12.1)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.12.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ autotest (~> 4.4.6)
36
+ fakeweb (~> 1.3.0)
37
+ ralf!
38
+ rspec
@@ -1,3 +1,15 @@
1
+ Release 1.1.1 [2013-02-11 13:14]
2
+
3
+ * Update gemspec
4
+ * extract the translator in it's own class
5
+ * add option to recalculate the '206 Partial Content' issue on S3
6
+ (see https://forums.aws.amazon.com/thread.jspa?threadID=54214 for more details)
7
+
8
+ Release 1.1.0 [2011-05-08]
9
+
10
+ * Switched to Fileutils for 1.9 compatibility
11
+
12
+
1
13
  = Synopsis
2
14
 
3
15
  Download, merge and convert Amazon S3 bucket log files for a specified date or date range.
@@ -2,8 +2,11 @@ require 'rubygems'
2
2
  require 'right_aws'
3
3
  require 'logmerge'
4
4
  require 'fileutils'
5
+
6
+ require 'ralf/version'
5
7
  require 'ralf/config'
6
8
  require 'ralf/bucket'
9
+ require 'ralf/clf_translator'
7
10
  require 'chronic'
8
11
  require 'stringio'
9
12
  require 'date'
@@ -18,9 +21,6 @@ class Ralf
18
21
  ROOT_DEFAULT_CONFIG_FILE = '/etc/ralf.conf'
19
22
  USER_DEFAULT_CONFIG_FILE = '~/.ralf.conf'
20
23
 
21
- AMAZON_LOG_FORMAT = Regexp.new('([^ ]*) ([^ ]*) \[([^\]]*)\] ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) "([^"]*)" ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) "([^"]*)" "([^"]*)"')
22
- AMAZON_LOG_FORMAT_COPY = Regexp.new('([^ ]*) ([^ ]*) \[([^\]]*)\] ([^ ]*) ([^ ]*) ([^ ]*) (REST.COPY.OBJECT_GET) ([^ ]*) (-) ([^ ]*) (-) (-) ([^ ]*) (-) (-) (-) (-) (-)')
23
-
24
24
  # The current configuration.
25
25
  attr_reader :config
26
26
 
@@ -90,7 +90,7 @@ class Ralf
90
90
  Ralf.merge(merged_log, log_files)
91
91
 
92
92
  # convert to common log format
93
- Ralf.convert_to_common_log_format(merged_log, output_log)
93
+ Ralf.convert_to_common_log_format(merged_log, output_log, config.translate_options)
94
94
 
95
95
  puts "#{log_files.size} files" if config.debug?
96
96
  end
@@ -133,11 +133,11 @@ class Ralf
133
133
  end
134
134
 
135
135
  # Convert the input_log file to Apache Common Log Format into output_log
136
- def self.convert_to_common_log_format(input_log, output_log)
136
+ def self.convert_to_common_log_format(input_log, output_log, options)
137
137
  out_file = File.open(output_log, 'w')
138
138
  File.open(input_log, 'r') do |in_file|
139
139
  while (line = in_file.gets)
140
- if clf = translate_to_clf(line)
140
+ if clf = Ralf::ClfTranslator.new(line, options).to_s
141
141
  out_file.puts(clf)
142
142
  end
143
143
  end
@@ -145,18 +145,6 @@ class Ralf
145
145
  out_file.close
146
146
  end
147
147
 
148
- def self.translate_to_clf(line)
149
- if line =~ AMAZON_LOG_FORMAT
150
- # host, date, ip, acl, request, status, bytes, agent, total_time_ms = $2, $3, $4, $5, $9, $10, $12, $17, $14
151
- "%s - %s [%s] \"%s\" %s %s \"%s\" \"%s\" %d" % [$4, $5, $3, $9, $10, $12, $16, $17, ($14.to_i/1000.0).round]
152
- elsif line =~ AMAZON_LOG_FORMAT_COPY
153
- "%s - %s [%s] \"%s\" %s %s \"%s\" \"REST.COPY.OBJECT_GET\" %d" % [$4, $5, $3, "POST /#{$8} HTTP/1.1", $10, $12, $16, 0]
154
- else
155
- $stderr.puts "# ERROR: #{line}"
156
- nil
157
- end
158
- end
159
-
160
148
  def load_config(cli_config_file)
161
149
  result = nil
162
150
  if cli_config_file
@@ -0,0 +1,97 @@
1
+ class Ralf::ClfTranslator
2
+
3
+ AMAZON_LOG_FORMAT = Regexp.new('([^ ]*) ([^ ]*) \[([^\]]*)\] ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) "([^"]*)" ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) "([^"]*)" "([^"]*)"')
4
+ AMAZON_LOG_COPY_FORMAT = Regexp.new('([^ ]*) ([^ ]*) \[([^\]]*)\] ([^ ]*) ([^ ]*) ([^ ]*) (REST.COPY.OBJECT_GET) ([^ ]*) (-) ([^ ]*) (-) (-) ([^ ]*) (-) (-) (-) (-) (-)')
5
+
6
+ attr :line
7
+ attr_reader :owner, :bucket, :timestamp, :remote_ip, :request_id, :operation, :key, :request_uri, :http_status, :s3_error_code, :bytes_sent, :object_size, :total_time_in_ms, :turn_around_time_in_ms, :referrer, :user_agent, :request_version_id, :duration
8
+ attr_reader :options
9
+
10
+ # options:
11
+ # :recalculate_partial_content => false (default)
12
+ # If request is '206 Partial Content' estimate the actual bytes when apparent bandwidth has exceeded 2Mbit/sec.
13
+ # S3 caches content to edge servers with a burst which never reaches the client
14
+
15
+ def initialize(line, options = {})
16
+ @options = options
17
+ @error = false
18
+ @line = line
19
+ @translate_successfull = translate
20
+ end
21
+
22
+ def to_s
23
+ if @translate_successfull
24
+ "%s - %s [%s] \"%s\" %s %s \"%s\" \"%s\" %d" % [remote_ip, requester, timestamp, request_uri, http_status, bytes_sent, referrer, user_agent, duration]
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def requester
33
+ @requester[0..9]
34
+ end
35
+
36
+ def translate
37
+ if line =~ AMAZON_LOG_FORMAT
38
+ @owner, @bucket, @timestamp, @remote_ip, @requester, @request_id, @operation, @key, @request_uri, @http_status, @s3_error_code, @bytes_sent, @object_size, @total_time_in_ms, @turn_around_time_in_ms, @referrer, @user_agent, @request_version_id = $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18
39
+
40
+ if options[:recalculate_partial_content] && 206 == http_status.to_i && ((bytes_sent.to_i*8)/total_time_in_ms.to_i > 2000)
41
+ @bytes_sent = [ 128 * 1024 + 3 * total_time_in_ms.to_i, bytes_sent.to_i ].min # 128 K buffer + 3 bytes/msec = 3 kbytes/sec = 24 kbit/sec
42
+ end
43
+ @duration = (total_time_in_ms.to_i/1000.0).round
44
+
45
+ elsif line =~ AMAZON_LOG_COPY_FORMAT
46
+ @owner, @bucket, @timestamp, @remote_ip, @requester, @request_id, @operation, @key, @request_uri, @http_status, @s3_error_code, @bytes_sent, @object_size, @total_time_in_ms, @turn_around_time_in_ms, @referrer, @user_agent, @request_version_id = $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18
47
+ @operation == 'REST.COPY.OBJECT_GET'
48
+ @user_agent = @operation
49
+ @duration = 0
50
+ @request_uri = "POST /#{@key} HTTP/1.1"
51
+
52
+ else
53
+ $stderr.puts "# ERROR: #{line}"
54
+ false
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ # convert the format as specified in http://docs.aws.amazon.com/AmazonS3/latest/dev/LogFormat.html
61
+ #
62
+ # 1 Bucket Owner
63
+ # The canonical user id of the owner of the source bucket.
64
+ # 2 Bucket
65
+ # The name of the bucket that the request was processed against. If the system receives a malformed request and cannot determine the bucket, the request will not appear in any server access log.
66
+ # 3 Time
67
+ # The time at which the request was received. The format, using strftime() terminology, is [%d/%b/%Y:%H:%M:%S %z]
68
+ # 4 Remote IP
69
+ # The apparent Internet address of the requester. Intermediate proxies and firewalls might obscure the actual address of the machine making the request.
70
+ # 5 Requester
71
+ # The canonical user id of the requester, or the string "Anonymous" for unauthenticated requests. This identifier is the same one used for access control purposes.
72
+ # 6 Request ID
73
+ # The request ID is a string generated by Amazon S3 to uniquely identify each request.
74
+ # 7 Operation
75
+ # Either SOAP.operation, REST.HTTP_method.resource_type or WEBSITE.HTTP_method.resource_type
76
+ # 8 Key
77
+ # The "key" part of the request, URL encoded, or "-" if the operation does not take a key parameter.
78
+ # 9 Request-URI
79
+ # The Request-URI part of the HTTP request message.
80
+ # 10 HTTP status
81
+ # The numeric HTTP status code of the response.
82
+ # 11 Error Code
83
+ # The Amazon S3 Error Code, or "-" if no error occurred.
84
+ # 12 Bytes Sent
85
+ # The number of response bytes sent, excluding HTTP protocol overhead, or "-" if zero.
86
+ # 13 Object Size
87
+ # The total size of the object in question.
88
+ # 14 Total Time
89
+ # The number of milliseconds the request was in flight from the server's perspective. This value is measured from the time your request is received to the time that the last byte of the response is sent. Measurements made from the client's perspective might be longer due to network latency.
90
+ # 15 Turn-Around Time
91
+ # The number of milliseconds that Amazon S3 spent processing your request. This value is measured from the time the last byte of your request was received until the time the first byte of the response was sent.
92
+ # 16 Referrer
93
+ # The value of the HTTP Referrer header, if present. HTTP user-agents (e.g. browsers) typically set this header to the URL of the linking or embedding page when making a request.
94
+ # 17 User-Agent
95
+ # The value of the HTTP User-Agent header.
96
+ # 18 Version Id
97
+ # The version ID in the request, or "-" if the operation does not take a versionId parameter.
@@ -22,6 +22,7 @@ class Ralf::Config
22
22
  :cache_dir # reader interpolates format
23
23
 
24
24
  attr_reader :errors
25
+ attr_reader :translate_options
25
26
 
26
27
  protected
27
28
 
@@ -40,6 +41,7 @@ class Ralf::Config
40
41
  @options[:now] ||= nil
41
42
  @options[:range] ||= 'today'
42
43
  @options[:cache_dir] ||= (0 == Process.uid ? ROOT_DEFAULT_CACHE_DIR : File.expand_path(USER_DEFAULT_CACHE_DIR))
44
+ @options[:translate_options] ||= {}
43
45
 
44
46
  assign_options(@options)
45
47
  end
@@ -102,6 +104,10 @@ class Ralf::Config
102
104
  @range = range
103
105
  end
104
106
 
107
+ def translate_options=(opts)
108
+ @translate_options = {:recalculate_partial_content => false}.merge(opts)
109
+ end
110
+
105
111
  def output_file(variables)
106
112
  Ralf::Interpolation.interpolate(@output_file, variables)
107
113
  end
@@ -0,0 +1,3 @@
1
+ class Ralf #:nodoc:
2
+ VERSION = "1.1.1"
3
+ end
@@ -1,77 +1,38 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ralf/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{ralf}
8
- s.version = "1.1.0"
7
+ s.version = Ralf::VERSION
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Klaas Jan Wierenga", "Leon Berenschot"]
12
- s.date = %q{2011-05-09}
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Klaas Jan Wierenga", "Leon Berenschot"]
11
+ s.email = ["k.j.wierenga@gmail.com", "leonb@beriedata.nl"]
12
+ s.homepage = %q{http://github.com/kjwierenga/ralf}
13
+ s.summary = %q{Retrieve Amazon Log Files}
14
+ s.description = %q{ Download logfiles from Amazon S3 buckets to local disk and combine them in one Apache CLF per bucket }
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.date = %q{2013-02-06}
13
22
  s.default_executable = %q{ralf}
14
- s.description = %q{ Download logfiles from Amazon S3 buckets to local disk and combine them in one Apache CLF per bucket
15
- }
16
- s.email = ["k.j.wierenga@gmail.com", "leonb@beriedata.nl"]
17
- s.executables = ["ralf"]
18
23
  s.extra_rdoc_files = [
19
24
  "README.rdoc"
20
25
  ]
21
- s.files = [
22
- ".rvmrc",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "bin/ralf",
27
- "lib/ralf.rb",
28
- "lib/ralf/bucket.rb",
29
- "lib/ralf/config.rb",
30
- "lib/ralf/interpolation.rb",
31
- "lib/ralf/log.rb",
32
- "lib/ralf/option_parser.rb",
33
- "ralf.gemspec",
34
- "spec/fixtures/apache.log",
35
- "spec/fixtures/example_buckets.yaml",
36
- "spec/ralf/bucket_spec.rb",
37
- "spec/ralf/config_spec.rb",
38
- "spec/ralf/interpolation_spec.rb",
39
- "spec/ralf/log_spec.rb",
40
- "spec/ralf/option_parser_spec.rb",
41
- "spec/ralf_spec.rb",
42
- "spec/spec.opts",
43
- "spec/spec_helper.rb",
44
- "spec/support/fakeweb.rb"
45
- ]
46
- s.homepage = %q{http://github.com/kjwierenga/ralf}
47
- s.rdoc_options = ["--exclude", "."]
48
- s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.7}
50
- s.summary = %q{Retrieve Amazon Log Files}
51
26
 
52
- if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
- s.specification_version = 3
27
+ s.rdoc_options = ["--exclude", "."]
28
+
29
+ s.add_development_dependency "rspec", "~> 2"
30
+ s.add_development_dependency "autotest", '~> 4.4.6'
31
+ s.add_development_dependency "fakeweb", "~> 1.3.0"
32
+
33
+ s.add_runtime_dependency "right_aws", "~> 3.0.4"
34
+ s.add_runtime_dependency "logmerge", "~> 1.0.3"
35
+ s.add_runtime_dependency "chronic", "~> 0.9.0"
55
36
 
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
58
- s.add_development_dependency(%q<fakeweb>, ["~> 1.2.8"])
59
- s.add_runtime_dependency(%q<right_aws>, ["~> 1.10.0"])
60
- s.add_runtime_dependency(%q<logmerge>, ["~> 1.0.2"])
61
- s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
62
- else
63
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
64
- s.add_dependency(%q<fakeweb>, ["~> 1.2.8"])
65
- s.add_dependency(%q<right_aws>, ["~> 1.10.0"])
66
- s.add_dependency(%q<logmerge>, ["~> 1.0.2"])
67
- s.add_dependency(%q<chronic>, [">= 0.2.3"])
68
- end
69
- else
70
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
71
- s.add_dependency(%q<fakeweb>, ["~> 1.2.8"])
72
- s.add_dependency(%q<right_aws>, ["~> 1.10.0"])
73
- s.add_dependency(%q<logmerge>, ["~> 1.0.2"])
74
- s.add_dependency(%q<chronic>, [">= 0.2.3"])
75
- end
76
37
  end
77
38
 
File without changes
@@ -0,0 +1,24 @@
1
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:29 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 AE5C72112DFB80DE REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.0" 200 - 4215272 18708200 5165 47 "-" "WinampMPEG/5.56, Ultravox/2.1" -
2
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:34 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 4C59A68A6BC2D5D3 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4210177 18708200 4342 25 "-" "WinampMPEG/5.56" -
3
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:38 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 ECBB95CD19EFEDAB REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4200071 18708200 3794 20 "-" "WinampMPEG/5.56" -
4
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:42 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 58BB2C8DF33D62B5 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4233474 18708200 2803 22 "-" "WinampMPEG/5.56" -
5
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:45 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 77D288D238143DC6 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4230605 18708200 13013 16 "-" "WinampMPEG/5.56" -
6
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:58 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 74212905FEB7883D REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 3920952 18708200 3448 26 "-" "WinampMPEG/5.56" -
7
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:01 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 060140E915EE005A REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4226689 18708200 3016 14 "-" "WinampMPEG/5.56" -
8
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:04 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 C2B6BD79E706A583 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4217974 18708200 2508 23 "-" "WinampMPEG/5.56" -
9
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:07 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 C4DB180DBBE7D2C0 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4227033 18708200 2666 224 "-" "WinampMPEG/5.56" -
10
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:10 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 6822B2F51B7390BF REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4229800 18708200 6314 21 "-" "WinampMPEG/5.56" -
11
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:16 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 5802133D0E709A69 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4169752 18708200 3117 21 "-" "WinampMPEG/5.56" -
12
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:19 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 7AEA132936905D0F REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4221938 18708200 3086 23 "-" "WinampMPEG/5.56" -
13
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:22 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 CFB5E41CD315DA46 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4116176 18708200 3547 21 "-" "WinampMPEG/5.56" -
14
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:26 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 2AA4F763E5B2DB4C REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 3134615 18708200 141 41 "-" "WinampMPEG/5.56" -
15
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:33 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 E9441C619413CE17 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 2546843 18708200 266 19 "-" "WinampMPEG/5.56" -
16
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:37 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 B74D95B8EF02DA55 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 1861439 18708200 53 19 "-" "WinampMPEG/5.56" -
17
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:41 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 0B9744B24E0B5359 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 1273664 18708200 74 40 "-" "WinampMPEG/5.56" -
18
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:44 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 DA589AAA642D33D7 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 783806 18708200 38 18 "-" "WinampMPEG/5.56" -
19
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:48 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 F533853F09AC5567 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 3428645 18708200 94 34 "-" "WinampMPEG/5.56" -
20
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:51 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 69FE22F49D5F6741 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4232818 18708200 3758 43 "-" "WinampMPEG/5.56" -
21
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:58:55 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 C34AFF770557888B REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4308854 18708200 5224 20 "-" "WinampMPEG/5.56" -
22
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:59:00 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 F59924F875AC10CF REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4238246 18708200 5691 70 "-" "WinampMPEG/5.56" -
23
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:59:06 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 D612FB39D6C637D3 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4280986 18708200 3307 14 "-" "WinampMPEG/5.56" -
24
+ 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:59:09 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 D35647E03C769516 REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4205237 18708200 10806 28 "-" "WinampMPEG/5.56" -
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ require 'ralf'
4
+ require 'ralf/bucket'
5
+
6
+ describe Ralf::ClfTranslator do
7
+
8
+ it "should return nil when it's an invalid line" do
9
+ $stderr = StringIO.new
10
+ translated_object = Ralf::ClfTranslator.new('invalid_line')
11
+ translated_object.to_s.should be_nil
12
+ $stderr.string.should eql("# ERROR: invalid_line\n")
13
+ end
14
+
15
+ it "should translate a amazon logline to a Apache CombinedLogFile" do
16
+ aws_line = '2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [03/Nov/2010:15:57:29 +0000] 84.82.12.240 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 AE5C72112DFB80DE REST.GET.OBJECT 10122150/2010-10-31-0930.mp3 "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.0" 200 - 4215272 18708200 5165 47 "-" "WinampMPEG/5.56, Ultravox/2.1" -'
17
+ clf_line = '84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:29 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.0" 200 4215272 "-" "WinampMPEG/5.56, Ultravox/2.1" 5'
18
+ translated_object = Ralf::ClfTranslator.new(aws_line)
19
+ translated_object.to_s.should eql(clf_line)
20
+ end
21
+
22
+ it "should mark invalid lines with '# ERROR: '" do
23
+ $stderr = StringIO.new
24
+ invalid_line = "this is an invalid log line"
25
+ Ralf::ClfTranslator.new(invalid_line)
26
+ $stderr.string.should eql("# ERROR: #{invalid_line}\n")
27
+ end
28
+
29
+ describe "#option{:recalculate_partial_content}" do
30
+ describe "set to false (default)" do
31
+ it "should add rounded total_time in seconds" do
32
+ $stderr = StringIO.new
33
+ input_line = '2010-10-02-19-15-45-6879098C3140BE9D:2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [02/Oct/2010:18:29:16 +0000] 82.168.113.55 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 4F911681022807C6 REST.GET.OBJECT 10028050/2010-09-26-1830.mp3 "GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4194304 17537676 1600 12 "-" "VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team" -'
34
+ Ralf::ClfTranslator.new(input_line).to_s.should eql("82.168.113.55 - 2cf7e6b063 [02/Oct/2010:18:29:16 +0000] \"GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1\" 206 4194304 \"-\" \"VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team\" 2")
35
+ $stderr.string.should be_empty
36
+ end
37
+ end
38
+ describe "set to true" do
39
+ it "should add rounded total_time in seconds" do
40
+ $stderr = StringIO.new
41
+ input_line = '2010-10-02-19-15-45-6879098C3140BE9D:2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [02/Oct/2010:18:29:16 +0000] 82.168.113.55 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 4F911681022807C6 REST.GET.OBJECT 10028050/2010-09-26-1830.mp3 "GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4194304 17537676 1600 12 "-" "VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team" -'
42
+ Ralf::ClfTranslator.new(input_line, :recalculate_partial_content => true).to_s.should eql("82.168.113.55 - 2cf7e6b063 [02/Oct/2010:18:29:16 +0000] \"GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1\" 206 135872 \"-\" \"VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team\" 2")
43
+ $stderr.string.should be_empty
44
+ end
45
+ end
46
+ end
47
+
48
+ [
49
+ ['2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 assets.staging.kerkdienstgemist.nl [10/Feb/2010:07:17:01 +0000] 10.32.219.38 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 784FD457838EFF42 REST.GET.ACL - "GET /?acl HTTP/1.1" 200 - 1384 - 399 - "-" "Jakarta Commons-HttpClient/3.0" -',
50
+ '10.32.219.38 - 3272ee65a9 [10/Feb/2010:07:17:01 +0000] "GET /?acl HTTP/1.1" 200 1384 "-" "Jakarta Commons-HttpClient/3.0" 0'],
51
+ ['2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 assets.staging.kerkdienstgemist.nl [10/Feb/2010:07:17:02 +0000] 10.32.219.38 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 6E239BC5A4AC757C SOAP.PUT.OBJECT logs/2010-02-10-07-17-02-F6EFD00DAB9A08B6 "POST /soap/ HTTP/1.1" 200 - 797 686 63 31 "-" "Axis/1.3" -',
52
+ '10.32.219.38 - 3272ee65a9 [10/Feb/2010:07:17:02 +0000] "POST /soap/ HTTP/1.1" 200 797 "-" "Axis/1.3" 0'],
53
+ ['2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 assets.staging.kerkdienstgemist.nl [10/Feb/2010:07:24:40 +0000] 10.217.37.15 - 0B76C90B3634290B REST.GET.ACL - "GET /?acl HTTP/1.1" 307 TemporaryRedirect 488 - 7 - "-" "Jakarta Commons-HttpClient/3.0" -',
54
+ '10.217.37.15 - - [10/Feb/2010:07:24:40 +0000] "GET /?acl HTTP/1.1" 307 488 "-" "Jakarta Commons-HttpClient/3.0" 0'],
55
+ ['2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.staging.kerkdienstgemist.nl [17/Sep/2010:13:38:36 +0000] 85.113.244.146 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 71F7D2AAA93B0A05 REST.COPY.OBJECT_GET 10010150/2010-08-29-0930.mp3 - 200 - - 13538337 - - - - -',
56
+ '85.113.244.146 - 2cf7e6b063 [17/Sep/2010:13:38:36 +0000] "POST /10010150/2010-08-29-0930.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0'],
57
+ ['2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.staging.kerkdienstgemist.nl [17/Sep/2010:13:38:37 +0000] 85.113.244.146 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 7CC5E3D09AE78CAE REST.COPY.OBJECT_GET 10010150/2010-09-05-1000.mp3 - 200 - - 9860402 - - - - -',
58
+ '85.113.244.146 - 2cf7e6b063 [17/Sep/2010:13:38:37 +0000] "POST /10010150/2010-09-05-1000.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0'],
59
+ ].each do |aws_line,clf_line|
60
+ it "converts #{aws_line} into #{clf_line}" do
61
+ Ralf::ClfTranslator.new(aws_line).to_s.should eql(clf_line)
62
+ end
63
+ end
64
+ end
@@ -128,4 +128,15 @@ describe Ralf::Config do
128
128
  $stdout.string.should eql("Warning: invalid configuration variable: unknown_variable\n")
129
129
  end
130
130
 
131
+ describe "#translate_options" do
132
+ it "sets {:recalculate_partial_content => false} by default" do
133
+ config = Ralf::Config.new
134
+ config.translate_options.should eql({:recalculate_partial_content => false})
135
+ end
136
+ it "sets {:recalculate_partial_content => true}" do
137
+ config = Ralf::Config.new(:translate_options => {:recalculate_partial_content => true})
138
+ config.translate_options.should eql({:recalculate_partial_content => true})
139
+ end
140
+ end
141
+
131
142
  end
@@ -52,14 +52,13 @@ describe Ralf do
52
52
  :cache_dir => '/var/log/amazon/ralf_cache/:year/:month/:bucket',
53
53
  }.merge(@aws_credentials)
54
54
 
55
- # File = mock('File')
55
+ end
56
+
57
+ before(:each) do
56
58
  @s3_mock = mock('s3_mock')
57
59
  Ralf::Bucket.s3 = @s3_mock
58
-
59
60
  @example_buckets = load_example_bucket_mocks
60
- end
61
61
 
62
- before(:each) do
63
62
  RightAws::S3.should_receive(:new).any_number_of_times.and_return(@s3_mock)
64
63
  end
65
64
 
@@ -283,7 +282,7 @@ describe Ralf do
283
282
  end
284
283
 
285
284
  Ralf.should_receive(:convert_to_common_log_format).with(
286
- "/var/log/s3/test1.log.alf", "/var/log/s3/test1.log")
285
+ "/var/log/s3/test1.log.alf", "/var/log/s3/test1.log", {:recalculate_partial_content => false})
287
286
 
288
287
  LogMerge::Merger.should_receive(:merge).with(alfio,
289
288
  *@example_buckets['test1'].keys.map{|k| "/var/log/s3/cache/test1/#{k.name.gsub('logs/', '')}"})
@@ -324,11 +323,11 @@ describe Ralf do
324
323
  EOF_INPUT
325
324
 
326
325
  clf_log =<<EOF_OUTPUT
327
- 10.32.219.38 - 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 [10/Feb/2010:07:17:01 +0000] "GET /?acl HTTP/1.1" 200 1384 "-" "Jakarta Commons-HttpClient/3.0" 0
328
- 10.32.219.38 - 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 [10/Feb/2010:07:17:02 +0000] "POST /soap/ HTTP/1.1" 200 797 "-" "Axis/1.3" 0
326
+ 10.32.219.38 - 3272ee65a9 [10/Feb/2010:07:17:01 +0000] "GET /?acl HTTP/1.1" 200 1384 "-" "Jakarta Commons-HttpClient/3.0" 0
327
+ 10.32.219.38 - 3272ee65a9 [10/Feb/2010:07:17:02 +0000] "POST /soap/ HTTP/1.1" 200 797 "-" "Axis/1.3" 0
329
328
  10.217.37.15 - - [10/Feb/2010:07:24:40 +0000] "GET /?acl HTTP/1.1" 307 488 "-" "Jakarta Commons-HttpClient/3.0" 0
330
- 85.113.244.146 - 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 [17/Sep/2010:13:38:36 +0000] "POST /10010150/2010-08-29-0930.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0
331
- 85.113.244.146 - 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 [17/Sep/2010:13:38:37 +0000] "POST /10010150/2010-09-05-1000.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0
329
+ 85.113.244.146 - 2cf7e6b063 [17/Sep/2010:13:38:36 +0000] "POST /10010150/2010-08-29-0930.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0
330
+ 85.113.244.146 - 2cf7e6b063 [17/Sep/2010:13:38:37 +0000] "POST /10010150/2010-09-05-1000.mp3 HTTP/1.1" 200 - "-" "REST.COPY.OBJECT_GET" 0
332
331
  EOF_OUTPUT
333
332
 
334
333
  output_log = StringIO.new
@@ -339,22 +338,48 @@ EOF_OUTPUT
339
338
  # $stderr.should_receive(:puts).with("# ERROR: 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.staging.kerkdienstgemist.nl [17/Sep/2010:13:38:36 +0000] 85.113.244.146 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 71F7D2AAA93B0A05 REST.COPY.OBJECT_GET 10010150/2010-08-29-0930.mp3 - 200 - - 13538337 - - - - -\n")
340
339
  # $stderr.should_receive(:puts).with("# ERROR: 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.staging.kerkdienstgemist.nl [17/Sep/2010:13:38:37 +0000] 85.113.244.146 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 7CC5E3D09AE78CAE REST.COPY.OBJECT_GET 10010150/2010-09-05-1000.mp3 - 200 - - 9860402 - - - - -\n")
341
340
 
342
- Ralf.convert_to_common_log_format('input_file', 'output_file')
341
+ Ralf.convert_to_common_log_format('input_file', 'output_file', {})
343
342
  output_log.string.should eql(clf_log)
344
343
  end
345
344
 
346
- it "should mark invalid lines with '# ERROR: '" do
347
- $stderr = StringIO.new
348
- invalid_line = "this is an invalid log line"
349
- Ralf.translate_to_clf(invalid_line)
350
- $stderr.string.should eql("# ERROR: #{invalid_line}\n")
351
- end
345
+ it "should estimate Actual Bytes Sent of transfers from Bytes Sent and Total Time" do
346
+ output_log = StringIO.new
347
+ winamp_log = File.open(File.join(File.dirname(__FILE__), 'fixtures', 'winamp.txt'), 'r')
348
+
349
+ File.should_receive(:open).with('output_file', 'w').and_return(output_log)
350
+ File.should_receive(:open).with('input_file', 'r').and_yield(winamp_log)
351
+
352
+ Ralf.convert_to_common_log_format('input_file', 'output_file', {:recalculate_partial_content => true})
353
+
354
+ expected_clf_log =<<EOF_OUTPUT
355
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:29 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.0" 200 4215272 "-" "WinampMPEG/5.56, Ultravox/2.1" 5
356
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:34 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 144098 "-" "WinampMPEG/5.56" 4
357
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:38 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 142454 "-" "WinampMPEG/5.56" 4
358
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:42 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 139481 "-" "WinampMPEG/5.56" 3
359
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:45 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 170111 "-" "WinampMPEG/5.56" 13
360
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:57:58 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 141416 "-" "WinampMPEG/5.56" 3
361
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:01 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 140120 "-" "WinampMPEG/5.56" 3
362
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:04 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 138596 "-" "WinampMPEG/5.56" 3
363
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:07 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 139070 "-" "WinampMPEG/5.56" 3
364
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:10 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 150014 "-" "WinampMPEG/5.56" 6
365
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:16 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 140423 "-" "WinampMPEG/5.56" 3
366
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:19 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 140330 "-" "WinampMPEG/5.56" 3
367
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:22 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 141713 "-" "WinampMPEG/5.56" 4
368
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:26 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131495 "-" "WinampMPEG/5.56" 0
369
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:33 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131870 "-" "WinampMPEG/5.56" 0
370
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:37 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131231 "-" "WinampMPEG/5.56" 0
371
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:41 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131294 "-" "WinampMPEG/5.56" 0
372
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:44 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131186 "-" "WinampMPEG/5.56" 0
373
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:48 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 131354 "-" "WinampMPEG/5.56" 0
374
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:51 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 142346 "-" "WinampMPEG/5.56" 4
375
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:58:55 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 146744 "-" "WinampMPEG/5.56" 5
376
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:59:00 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 148145 "-" "WinampMPEG/5.56" 6
377
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:59:06 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 140993 "-" "WinampMPEG/5.56" 3
378
+ 84.82.12.240 - 2cf7e6b063 [03/Nov/2010:15:59:09 +0000] "GET /10122150/2010-10-31-0930.mp3?Signature=5n2%2B8hrDvgSbP6OJRP1vVav42uU%3D&Expires=1288807041&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 163490 "-" "WinampMPEG/5.56" 11
379
+ EOF_OUTPUT
352
380
 
353
- it "should add rounded total_time in seconds" do
354
- $stderr = StringIO.new
355
- input_line = '2010-10-02-19-15-45-6879098C3140BE9D:2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 media.kerkdienstgemist.nl [02/Oct/2010:18:29:16 +0000] 82.168.113.55 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 4F911681022807C6 REST.GET.OBJECT 10028050/2010-09-26-1830.mp3 "GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1" 206 - 4194304 17537676 1600 12 "-" "VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team" -'
356
- Ralf.translate_to_clf(input_line).should eql("82.168.113.55 - 2cf7e6b06335c0689c6d29163df5bb001c96870cd78609e3845f1ed76a632621 [02/Oct/2010:18:29:16 +0000] \"GET /10028050/2010-09-26-1830.mp3?Signature=E3ehd6nkXjNg7vr%2F4b3LtxCWads%3D&Expires=1286051333&AWSAccessKeyId=AKIAI3XHXJPFSJW2UQAQ HTTP/1.1\" 206 4194304 \"-\" \"VLC media player - version 1.0.5 Goldeneye - (c) 1996-2010 the VideoLAN team\" 2")
357
- $stderr.string.should be_empty
381
+ output_log.string.should == expected_clf_log
382
+ winamp_log.close
358
383
  end
359
384
 
360
385
  end
@@ -1,14 +1,11 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
3
+
2
4
  require 'right_aws' # load RightHttpConnection before FakeWeb otherwise we get buggy
3
5
  require 'fakeweb'
4
6
 
5
- require 'spec/autorun'
7
+ RSpec.configure do |config|
6
8
 
7
- Spec::Runner.configure do |config|
8
- # == Notes
9
- #
10
- # For more information take a look at Spec::Runner::Configuration and Spec::Runner
11
-
12
9
  def load_example_bucket_mocks
13
10
  buckets = YAML.load(File.open(File.join(File.dirname(__FILE__), 'fixtures', 'example_buckets.yaml')))
14
11
  buckets = buckets.inject({}) do |memo, info|
@@ -20,5 +17,5 @@ Spec::Runner.configure do |config|
20
17
  end
21
18
  buckets
22
19
  end
23
- end
24
20
 
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ralf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Klaas Jan Wierenga
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-09 00:00:00 +02:00
20
- default_executable: ralf
19
+ date: 2013-02-06 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: rspec
@@ -27,79 +26,93 @@ dependencies:
27
26
  requirements:
28
27
  - - ~>
29
28
  - !ruby/object:Gem::Version
30
- hash: 27
29
+ hash: 7
31
30
  segments:
32
- - 1
33
- - 3
34
- - 0
35
- version: 1.3.0
31
+ - 2
32
+ version: "2"
36
33
  type: :development
37
34
  version_requirements: *id001
38
35
  - !ruby/object:Gem::Dependency
39
- name: fakeweb
36
+ name: autotest
40
37
  prerelease: false
41
38
  requirement: &id002 !ruby/object:Gem::Requirement
42
39
  none: false
43
40
  requirements:
44
41
  - - ~>
45
42
  - !ruby/object:Gem::Version
46
- hash: 15
43
+ hash: 35
47
44
  segments:
48
- - 1
49
- - 2
50
- - 8
51
- version: 1.2.8
45
+ - 4
46
+ - 4
47
+ - 6
48
+ version: 4.4.6
52
49
  type: :development
53
50
  version_requirements: *id002
54
51
  - !ruby/object:Gem::Dependency
55
- name: right_aws
52
+ name: fakeweb
56
53
  prerelease: false
57
54
  requirement: &id003 !ruby/object:Gem::Requirement
58
55
  none: false
59
56
  requirements:
60
57
  - - ~>
61
58
  - !ruby/object:Gem::Version
62
- hash: 63
59
+ hash: 27
63
60
  segments:
64
61
  - 1
65
- - 10
62
+ - 3
66
63
  - 0
67
- version: 1.10.0
68
- type: :runtime
64
+ version: 1.3.0
65
+ type: :development
69
66
  version_requirements: *id003
70
67
  - !ruby/object:Gem::Dependency
71
- name: logmerge
68
+ name: right_aws
72
69
  prerelease: false
73
70
  requirement: &id004 !ruby/object:Gem::Requirement
74
71
  none: false
75
72
  requirements:
76
73
  - - ~>
77
74
  - !ruby/object:Gem::Version
78
- hash: 19
75
+ hash: 15
79
76
  segments:
80
- - 1
77
+ - 3
81
78
  - 0
82
- - 2
83
- version: 1.0.2
79
+ - 4
80
+ version: 3.0.4
84
81
  type: :runtime
85
82
  version_requirements: *id004
86
83
  - !ruby/object:Gem::Dependency
87
- name: chronic
84
+ name: logmerge
88
85
  prerelease: false
89
86
  requirement: &id005 !ruby/object:Gem::Requirement
90
87
  none: false
91
88
  requirements:
92
- - - ">="
89
+ - - ~>
93
90
  - !ruby/object:Gem::Version
94
91
  hash: 17
95
92
  segments:
93
+ - 1
96
94
  - 0
97
- - 2
98
95
  - 3
99
- version: 0.2.3
96
+ version: 1.0.3
100
97
  type: :runtime
101
98
  version_requirements: *id005
102
- description: " Download logfiles from Amazon S3 buckets to local disk and combine them in one Apache CLF per bucket\n"
99
+ - !ruby/object:Gem::Dependency
100
+ name: chronic
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ hash: 59
108
+ segments:
109
+ - 0
110
+ - 9
111
+ - 0
112
+ version: 0.9.0
113
+ type: :runtime
114
+ version_requirements: *id006
115
+ description: " Download logfiles from Amazon S3 buckets to local disk and combine them in one Apache CLF per bucket "
103
116
  email:
104
117
  - k.j.wierenga@gmail.com
105
118
  - leonb@beriedata.nl
@@ -110,21 +123,28 @@ extensions: []
110
123
  extra_rdoc_files:
111
124
  - README.rdoc
112
125
  files:
126
+ - .gitignore
127
+ - .rspec
113
128
  - .rvmrc
129
+ - Gemfile
130
+ - Gemfile.lock
114
131
  - README.rdoc
115
132
  - Rakefile
116
- - VERSION
117
133
  - bin/ralf
118
134
  - lib/ralf.rb
119
135
  - lib/ralf/bucket.rb
136
+ - lib/ralf/clf_translator.rb
120
137
  - lib/ralf/config.rb
121
138
  - lib/ralf/interpolation.rb
122
139
  - lib/ralf/log.rb
123
140
  - lib/ralf/option_parser.rb
141
+ - lib/ralf/version.rb
124
142
  - ralf.gemspec
125
- - spec/fixtures/apache.log
143
+ - spec/fixtures/apache.txt
126
144
  - spec/fixtures/example_buckets.yaml
145
+ - spec/fixtures/winamp.txt
127
146
  - spec/ralf/bucket_spec.rb
147
+ - spec/ralf/clf_translator_spec.rb
128
148
  - spec/ralf/config_spec.rb
129
149
  - spec/ralf/interpolation_spec.rb
130
150
  - spec/ralf/log_spec.rb
@@ -133,7 +153,6 @@ files:
133
153
  - spec/spec.opts
134
154
  - spec/spec_helper.rb
135
155
  - spec/support/fakeweb.rb
136
- has_rdoc: true
137
156
  homepage: http://github.com/kjwierenga/ralf
138
157
  licenses: []
139
158
 
@@ -164,9 +183,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
183
  requirements: []
165
184
 
166
185
  rubyforge_project:
167
- rubygems_version: 1.3.7
186
+ rubygems_version: 1.8.25
168
187
  signing_key:
169
188
  specification_version: 3
170
189
  summary: Retrieve Amazon Log Files
171
- test_files: []
172
-
190
+ test_files:
191
+ - spec/fixtures/apache.txt
192
+ - spec/fixtures/example_buckets.yaml
193
+ - spec/fixtures/winamp.txt
194
+ - spec/ralf/bucket_spec.rb
195
+ - spec/ralf/clf_translator_spec.rb
196
+ - spec/ralf/config_spec.rb
197
+ - spec/ralf/interpolation_spec.rb
198
+ - spec/ralf/log_spec.rb
199
+ - spec/ralf/option_parser_spec.rb
200
+ - spec/ralf_spec.rb
201
+ - spec/spec.opts
202
+ - spec/spec_helper.rb
203
+ - spec/support/fakeweb.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0