ralf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/spec/ralf_spec.rb +175 -0
- metadata +76 -0
data/spec/ralf_spec.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
require 'ralf'
|
4
|
+
|
5
|
+
describe Ralf do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@default_params = {:config => File.dirname(__FILE__) + '/fixtures/config.yaml', :date => '2010-02-10'}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should initialize properly" do
|
12
|
+
ralf = Ralf.new(@default_params)
|
13
|
+
ralf.class.should eql(Ralf)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Preferences" do
|
17
|
+
|
18
|
+
it "should raise an error when an nonexistent config file is given" do
|
19
|
+
lambda {
|
20
|
+
ralf = Ralf.new(:config => '~/a_non_existen_file.yaml')
|
21
|
+
}.should raise_error(Ralf::NoConfigFile)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the preferences" do
|
25
|
+
ralf = Ralf.new(@default_params)
|
26
|
+
ralf.config[:aws_access_key_id].should eql('access_key')
|
27
|
+
ralf.config[:aws_secret_access_key].should eql('secret')
|
28
|
+
ralf.config[:out_path].should eql('/Users/berl/S3')
|
29
|
+
# ralf.config.should eql({:aws_access_key_id => 'access_key', :aws_secret_access_key => 'secret'})
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should look for default configurations" do
|
33
|
+
File.should_receive(:expand_path).once.with('~/.ralf.yaml').and_return('/Users/berl/.ralf.yaml')
|
34
|
+
File.should_receive(:expand_path).twice.with('/Users/berl/.ralf.yaml').and_return('/Users/berl/.ralf.yaml')
|
35
|
+
File.should_receive(:expand_path).once.with('/etc/ralf.yaml').and_return('/etc/ralf.yaml')
|
36
|
+
File.should_receive(:exists?).once.with('/etc/ralf.yaml').and_return(false)
|
37
|
+
File.should_receive(:exists?).twice.with('/Users/berl/.ralf.yaml').and_return(true)
|
38
|
+
YAML.should_receive(:load_file).with('/Users/berl/.ralf.yaml').and_return({
|
39
|
+
:aws_access_key_id => 'access_key',
|
40
|
+
:aws_secret_access_key => 'secret',
|
41
|
+
:out_path => '/Users/berl/S3',
|
42
|
+
:out_prefix => 's3_combined'
|
43
|
+
})
|
44
|
+
|
45
|
+
ralf = Ralf.new()
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should use AWS credentials provided in ENV" do
|
49
|
+
ENV['AWS_ACCESS_KEY_ID'] = 'access_key'
|
50
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = 'secret'
|
51
|
+
File.should_receive(:exists?).once.with('/etc/ralf.yaml').and_return(false)
|
52
|
+
File.should_receive(:exists?).once.with('/Users/berl/.ralf.yaml').and_return(false)
|
53
|
+
|
54
|
+
lambda {
|
55
|
+
Ralf.new(:out_path => '/Users/berl/S3')
|
56
|
+
}.should_not raise_error(Ralf::ConfigIncomplete)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "Date handling" do
|
63
|
+
|
64
|
+
it "should set the date to today" do
|
65
|
+
ralf = Ralf.new(@default_params)
|
66
|
+
date = Date.today
|
67
|
+
ralf.date.should eql("%4d-%02d-%02d" % [date.year, date.month, date.day])
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the date to the date given" do
|
71
|
+
ralf = Ralf.new(@default_params.merge(:date => '2010-02-01'))
|
72
|
+
ralf.date.should eql('2010-02-01')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise error when invalid date given" do
|
76
|
+
lambda {
|
77
|
+
ralf = Ralf.new(@default_params.merge(:date => 'now'))
|
78
|
+
ralf.date.should be_nil
|
79
|
+
}.should raise_error(ArgumentError, "invalid date")
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "Handle Buckets" do
|
85
|
+
|
86
|
+
before(:each) do
|
87
|
+
@ralf = Ralf.new(@default_params)
|
88
|
+
@bucket1 = {:name => 'bucket1'}
|
89
|
+
@bucket1.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => true, :targetprefix => "log/" })
|
90
|
+
@bucket1.should_receive(:name).any_number_of_times.and_return('media.kerdienstgemist.nl')
|
91
|
+
@bucket2 = {:name => 'bucket2'}
|
92
|
+
@bucket2.should_receive(:logging_info).any_number_of_times.and_return({ :enabled => false, :targetprefix => "log/" })
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should find buckets with logging enabled" do
|
96
|
+
@ralf.s3.should_receive(:buckets).once.and_return([@bucket1, @bucket2])
|
97
|
+
|
98
|
+
@ralf.find_buckets_with_logging.should eql([@bucket1, @bucket2])
|
99
|
+
@ralf.buckets_with_logging.should eql([@bucket1])
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should save logging to disk" do
|
103
|
+
@key1 = {:name => 'log/2010-02-10-00-05-32-ZDRFGTCKUYVJCT', :data => 'This is content'}
|
104
|
+
@key2 = {:name => 'log/2010-02-10-00-07-28-EFREUTERGRSGDH', :data => 'This is content'}
|
105
|
+
@bucket1.should_receive(:keys).any_number_of_times.and_return([@key1, @key2])
|
106
|
+
@key1.should_receive(:name).any_number_of_times.and_return(@key1[:name])
|
107
|
+
@key2.should_receive(:name).any_number_of_times.and_return(@key2[:name])
|
108
|
+
@key1.should_receive(:data).any_number_of_times.and_return(@key1[:data])
|
109
|
+
@key2.should_receive(:data).any_number_of_times.and_return(@key2[:data])
|
110
|
+
File.should_receive(:makedirs).twice.and_return(true)
|
111
|
+
File.should_receive(:exists?).twice.and_return(false, true)
|
112
|
+
File.should_receive(:open).once.and_return(true)
|
113
|
+
|
114
|
+
@ralf.save_logging_to_disk(@bucket1).should eql([@key1, @key2])
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should merge all logs" do
|
118
|
+
out_string = StringIO.new
|
119
|
+
|
120
|
+
Dir.should_receive(:glob).with('/Users/berl/S3/media.kerdienstgemist.nl/log/2010-02-10*').and_return(
|
121
|
+
['/Users/berl/S3/media.kerdienstgemist.nl/log/2010-02-10-00-05-32-ZDRFGTCKUYVJCT',
|
122
|
+
'/Users/berl/S3/media.kerdienstgemist.nl/log/2010-02-10-00-07-28-EFREUTERGRSGDH'])
|
123
|
+
|
124
|
+
File.should_receive(:open).with('/Users/berl/S3/s3_combined_media.kerdienstgemist.nl_2010-02-10.alf', "w").and_yield(out_string)
|
125
|
+
|
126
|
+
LogMerge::Merger.should_receive(:merge).with(
|
127
|
+
out_string,
|
128
|
+
'/Users/berl/S3/media.kerdienstgemist.nl/log/2010-02-10-00-05-32-ZDRFGTCKUYVJCT',
|
129
|
+
'/Users/berl/S3/media.kerdienstgemist.nl/log/2010-02-10-00-07-28-EFREUTERGRSGDH'
|
130
|
+
)
|
131
|
+
|
132
|
+
@ralf.merge_to_combined(@bucket1)
|
133
|
+
|
134
|
+
out_string.string.should eql('')
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "Conversion" do
|
140
|
+
|
141
|
+
before(:each) do
|
142
|
+
@ralf = Ralf.new(@default_params)
|
143
|
+
@bucket1 = {:name => 'bucket1'}
|
144
|
+
@bucket1.should_receive(:name).any_number_of_times.and_return('media.kerdienstgemist.nl')
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should convert the alf to clf" do
|
148
|
+
File.should_receive(:open).once.with("/Users/berl/S3/s3_combined_media.kerdienstgemist.nl_2010-02-10.log", "w").and_return(File)
|
149
|
+
File.should_receive(:open).once.with("/Users/berl/S3/s3_combined_media.kerdienstgemist.nl_2010-02-10.alf", "r").and_return(File)
|
150
|
+
File.should_receive(:close).once.and_return(true)
|
151
|
+
@ralf.convert_alt_to_clf(@bucket1).should eql(true)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should find the proper values in a line" do
|
155
|
+
[ [
|
156
|
+
'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" - ',
|
157
|
+
'10.32.219.38 - 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 [10/Feb/2010:07:17:01 +0000] "GET /?acl HTTP/1.1" 200 1384 "-" "Jakarta Commons-HttpClient/3.0"'
|
158
|
+
],[
|
159
|
+
'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" -',
|
160
|
+
'10.32.219.38 - 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 [10/Feb/2010:07:17:02 +0000] "POST /soap/ HTTP/1.1" 200 797 "-" "Axis/1.3"'
|
161
|
+
],[
|
162
|
+
'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" - ',
|
163
|
+
'10.217.37.15 - - [10/Feb/2010:07:24:40 +0000] "GET /?acl HTTP/1.1" 307 488 "-" "Jakarta Commons-HttpClient/3.0"'
|
164
|
+
] ].each do |alf,clf|
|
165
|
+
@ralf.translate_to_clf(alf).should eql(clf)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should mark invalid lines with '# ERROR: '" do
|
170
|
+
@ralf.translate_to_clf('An invalid line in the logfile').should match(/^# ERROR/)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ralf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Klaas Jan Wierenga
|
8
|
+
- Leon Berenschot
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-02-10 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: right_aws
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.10.0
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: logmerge
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.0
|
35
|
+
version:
|
36
|
+
description: " Download logfiles from Amazon S3 buckets to local disk and combine them in one Apache CLF per bucket\n"
|
37
|
+
email:
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files: []
|
45
|
+
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://kerkdienstgemist.nl
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --exclude
|
53
|
+
- .
|
54
|
+
require_paths:
|
55
|
+
- .
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Retrieve Amazon Log Files
|
75
|
+
test_files:
|
76
|
+
- spec/ralf_spec.rb
|