nfagent 0.9.30 → 0.9.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +0,0 @@
1
- client_key = 1234
2
- dump_dir = sandbox/dumps
3
- log_file = sandbox/debug
4
- pid_file = sandbox/nfagent.pid
5
- plugin_directory = test/plugins/
@@ -1,18 +0,0 @@
1
- class MyMapper
2
- def initialize
3
- @hash = {
4
- 'dan' => 'acme',
5
- 'paul' => 'jetson',
6
- 'mike' => 'acme'
7
- }
8
- end
9
-
10
- def before_shutdown
11
- # Put any cleanup code in here
12
- end
13
-
14
- def find_account_id(username, client_ip)
15
- raise NFAgent::IgnoreLine if username == 'andrew'
16
- @hash[username]
17
- end
18
- end
@@ -1,79 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestChunk < ActiveSupport::TestCase
5
- setup do
6
- NFAgent::Config.config_file = "test/config"
7
- NFAgent::Config.init
8
- @logline = "1253604221 19 127.0.0.1 TCP_MISS/200 562 GET http://www.gravatar.com/blavatar/e81cfb9068d04d1cfd598533bb380e1f?s=16&d=http://s.wordpress.com/favicon.ico - NONE/- text/html"
9
- end
10
-
11
- test "initialize" do
12
- chunk = NFAgent::Chunk.new
13
- assert_equal 500, chunk.max_size
14
- chunk = NFAgent::Chunk.new(600)
15
- assert_equal 600, chunk.max_size
16
- end
17
-
18
- test "full" do
19
- chunk = NFAgent::Chunk.new(20)
20
- 19.times do
21
- chunk << @logline
22
- end
23
- assert !chunk.full?
24
- chunk << @logline
25
- assert chunk.full?
26
- assert_raises(NFAgent::ChunkFull) { chunk << @logline }
27
- end
28
-
29
- test "won't expire if empty" do
30
- NFAgent::Config.chunk_time_out = 1
31
- chunk = NFAgent::Chunk.new
32
- assert !chunk.expired?
33
- Timecop.freeze(Time.now + 61) do
34
- assert !chunk.expired?
35
- end
36
- end
37
-
38
- test "expired" do
39
- chunk = NFAgent::Chunk.new
40
- chunk << @logline
41
- assert !chunk.expired?
42
- Timecop.freeze(Time.now + 61) do
43
- assert chunk.expired?
44
- assert_raises(NFAgent::ChunkExpired) { chunk << @logline }
45
- end
46
- end
47
-
48
- test "day boundary" do
49
- d = Date.today
50
- Timecop.travel(Time.local(2011, 1, 10, 23, 59, 58)) do
51
- chunk = NFAgent::Chunk.new
52
- Timecop.travel(Time.local(2011, 1, 11, 0, 0, 10)) do
53
- assert_raises(NFAgent::DayBoundary) { chunk << @logline }
54
- end
55
- end
56
- end
57
-
58
- test "submit" do
59
- EM.expects(:defer)
60
- chunk = NFAgent::Chunk.new
61
- chunk.submit
62
- end
63
-
64
- test "dump" do
65
- Zlib::Deflate.expects(:deflate).returns("x\234\313\316*/\314HO-\312N\317(J\005\000&~\005u").times(2)
66
- chunk = NFAgent::Chunk.new
67
- chunk << @logline
68
- payload = chunk.dump
69
- assert_equal 1, payload.line_count
70
- assert_instance_of String, payload.data
71
- # Dump with key
72
- payload = chunk.dump('acme')
73
- assert_equal 'acme', payload.key
74
- end
75
-
76
- test "dump from LogLine" do
77
- flunk
78
- end
79
- end
@@ -1,131 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestChunkHandler < ActiveSupport::TestCase
5
- setup do
6
- NFAgent::Config.config_file = "test/config"
7
- NFAgent::Config.init
8
- NFAgent::Config.plugin_directory = File.dirname(__FILE__) + '/../test/plugins/'
9
- NFAgent::Plugin.load_plugins
10
- @logline = "1253604221 19 127.0.0.1 TCP_MISS/200 562 GET http://www.gravatar.com/blavatar/e81cfb9068d04d1cfd598533bb380e1f?s=16&d=http://s.wordpress.com/favicon.ico dan NONE/- text/html"
11
- @logline2 = "1253604221 19 127.0.0.1 TCP_MISS/200 562 GET http://www.gravatar.com/blavatar/e81cfb9068d04d1cfd598533bb380e1f?s=16&d=http://s.wordpress.com/favicon.ico paul NONE/- text/html"
12
- @ignored_logline = "1253604221 19 127.0.0.1 TCP_MISS/200 562 GET http://www.gravatar.com/blavatar/e81cfb9068d04d1cfd598533bb380e1f?s=16&d=http://s.wordpress.com/favicon.ico andrew NONE/- text/html"
13
- end
14
-
15
- test "append line" do
16
- chunk_handler = NFAgent::ChunkHandler.new
17
- chunk_handler.append(@logline)
18
- assert_equal 1, chunk_handler.chunk_group['all'].size
19
- assert_instance_of String, chunk_handler.chunk_group['all'][-1]
20
- end
21
-
22
- test "append with local parsing" do
23
- NFAgent::Config.parse = 'locally'
24
- chunk_handler = NFAgent::ChunkHandler.new
25
- chunk_handler.append(@logline)
26
- assert_equal 1, chunk_handler.chunk_group['all'].size
27
- assert_instance_of Squiggle::LogLine, chunk_handler.chunk_group['all'][-1]
28
- end
29
-
30
- test "append with multi" do
31
- NFAgent::Config.parse = 'locally'
32
- NFAgent::Config.mode = 'multi'
33
- NFAgent::Config.mapper = 'MyMapper'
34
- chunk_handler = NFAgent::ChunkHandler.new
35
- chunk_handler.append(@logline)
36
- assert chunk_handler.chunk_group.has_key?('acme')
37
- assert_equal 1, chunk_handler.chunk_group['acme'].size
38
- chunk_handler.append(@logline2)
39
- assert chunk_handler.chunk_group.has_key?('acme')
40
- assert chunk_handler.chunk_group.has_key?('jetson')
41
- assert_equal 1, chunk_handler.chunk_group['acme'].size
42
- assert_equal 1, chunk_handler.chunk_group['jetson'].size
43
- end
44
-
45
- test "mapper raises ignore line in multi mode" do
46
- NFAgent::Config.parse = 'locally'
47
- NFAgent::Config.mode = 'multi'
48
- NFAgent::Config.mapper = 'MyMapper'
49
- chunk_handler = NFAgent::ChunkHandler.new
50
- chunk_handler.append(@ignored_logline)
51
- assert !chunk_handler.chunk_group.has_key?('acme')
52
- assert !chunk_handler.chunk_group.has_key?('jetson')
53
- assert chunk_handler.chunk_group['acme'].blank?
54
- assert chunk_handler.chunk_group['jetson'].blank?
55
- end
56
-
57
- test "reset chunk after expiry in multi mode" do
58
- NFAgent::Config.parse = 'locally'
59
- NFAgent::Config.mode = 'multi'
60
- NFAgent::Config.mapper = 'MyMapper'
61
- NFAgent::Chunk.any_instance.expects(:submit).at_least_once
62
- chunk_handler = NFAgent::ChunkHandler.new
63
- chunk_handler.append(@logline)
64
- Timecop.travel(30) do
65
- chunk_handler.append(@logline2)
66
- assert_equal 1, chunk_handler.chunk_group['acme'].size
67
- assert_equal 1, chunk_handler.chunk_group['jetson'].size
68
-
69
- Timecop.travel(31) do
70
- chunk_handler.check_full_or_expired
71
- assert !chunk_handler.chunk_group.has_key?('acme')
72
- assert_equal 1, chunk_handler.chunk_group['jetson'].size
73
-
74
- Timecop.travel(31) do
75
- chunk_handler.check_full_or_expired
76
- assert !chunk_handler.chunk_group.has_key?('acme')
77
- assert !chunk_handler.chunk_group.has_key?('jestson')
78
- end
79
- end
80
- end
81
- end
82
-
83
- test "reset chunk after full with check_full_or_expired in multi mode" do
84
- NFAgent::Config.parse = 'locally'
85
- NFAgent::Config.mode = 'multi'
86
- NFAgent::Config.mapper = 'MyMapper'
87
- EM.expects(:defer).times(2)
88
- chunk_handler = NFAgent::ChunkHandler.new(:chunk_size => 10)
89
- 9.times { chunk_handler.append(@logline) }
90
- 9.times { chunk_handler.append(@logline2) }
91
- assert_equal 9, chunk_handler.chunk_group['acme'].size
92
- assert_equal 9, chunk_handler.chunk_group['jetson'].size
93
- chunk_handler.append(@logline)
94
- chunk_handler.check_full_or_expired
95
- assert !chunk_handler.chunk_group.has_key?('acme')
96
- chunk_handler.append(@logline2)
97
- chunk_handler.check_full_or_expired
98
- assert !chunk_handler.chunk_group.has_key?('jetson')
99
- end
100
-
101
- test "fail an invalid logline in local parse mode" do
102
- NFAgent::Config.parse = 'locally'
103
- chunk_handler = NFAgent::ChunkHandler.new
104
- chunk_handler.append("") # Invalid logline
105
- assert chunk_handler.chunk_group['all'].nil?
106
- end
107
-
108
- test "reset chunk is passed appropriate key in multi mode" do
109
- NFAgent::Config.parse = 'locally'
110
- NFAgent::Config.mode = 'multi'
111
- NFAgent::Config.mapper = 'MyMapper'
112
- NFAgent::Chunk.any_instance.expects(:submit).with('acme')
113
- chunk_handler = NFAgent::ChunkHandler.new
114
- chunk_handler.append(@logline)
115
- Timecop.travel(61) do
116
- chunk_handler.check_full_or_expired
117
- end
118
- end
119
-
120
- test "reset chunk is passed nil key in normal mode" do
121
- NFAgent::Config.parse = 'remotely'
122
- NFAgent::Config.mode = 'normal'
123
- NFAgent::Chunk.any_instance.expects(:submit).with(nil)
124
- chunk_handler = NFAgent::ChunkHandler.new
125
- chunk_handler.append(@logline)
126
- Timecop.travel(61) do
127
- chunk_handler.check_full_or_expired
128
- end
129
- end
130
-
131
- end
@@ -1,20 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestClient < ActiveSupport::TestCase
5
- setup do
6
- end
7
-
8
- test "post data with configured client key" do
9
- Net::HTTP::Post.any_instance.expects(:set_form_data).with({ 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false, 'key' => '1234' })
10
- hash = { 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false }
11
- NFAgent::Client.post(:collector, hash)
12
- end
13
-
14
- test "post data with key passed in data hash" do
15
- Net::HTTP::Post.any_instance.expects(:set_form_data).with({ 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false, 'key' => 'abcd' })
16
- hash = { 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false, 'key' => 'abcd' }
17
- NFAgent::Client.post(:collector, hash)
18
- end
19
-
20
- end
@@ -1,49 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestConfig < ActiveSupport::TestCase
5
- setup do
6
- NFAgent::Config.attrs.clear
7
- end
8
-
9
- test "defaults" do
10
- puts "HHHHHH"
11
- p NFAgent::Config.attrs
12
- assert_equal "normal", NFAgent::Config.mode
13
- assert_equal "remotely", NFAgent::Config.parse
14
- assert_equal 60, NFAgent::Config.chunk_timeout
15
- assert_equal 'UTC', NFAgent::Config.time_zone
16
- assert_equal '/etc/nfagent/plugins/', NFAgent::Config.plugin_directory
17
- end
18
-
19
- test "validates valid mode" do
20
- NFAgent::Config.mode = 'some stupid thing'
21
- assert_raises(RuntimeError) { NFAgent::Config.validate }
22
- end
23
-
24
- test "validates mapping with multi" do
25
- NFAgent::Config.attrs.clear
26
- NFAgent::Config.config_file = "test/config"
27
- NFAgent::Config.init
28
-
29
- NFAgent::Config.mode = 'multi'
30
- assert_raises(RuntimeError) { NFAgent::Config.validate }
31
- NFAgent::Config.mapper = 'AccountMapper'
32
- assert_raises(RuntimeError) { NFAgent::Config.validate }
33
- NFAgent::Config.parse = 'locally'
34
- assert NFAgent::Config.validate
35
- end
36
-
37
- test "validates valid parse option" do
38
- NFAgent::Config.attrs.clear
39
- NFAgent::Config.config_file = "test/config"
40
- NFAgent::Config.init
41
-
42
- NFAgent::Config.parse = 'some stupid thing'
43
- assert_raises(RuntimeError) { NFAgent::Config.validate }
44
- NFAgent::Config.parse = 'locally'
45
- assert NFAgent::Config.validate
46
- NFAgent::Config.parse = 'remotely'
47
- assert NFAgent::Config.validate
48
- end
49
- end
@@ -1,6 +0,0 @@
1
-
2
- require 'mocha'
3
- require 'timecop'
4
- require 'active_support'
5
- require File.dirname(__FILE__) + '/../lib/nfagent'
6
-
@@ -1,20 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestMapperProxy < ActiveSupport::TestCase
5
- setup do
6
- NFAgent::Config.plugin_directory = File.dirname(__FILE__) + '/../test/plugins/'
7
- end
8
-
9
- test "instantiate just once" do
10
- MyMapper.expects(:new).at_most_once
11
- NFAgent::Config.mapper = nil
12
- NFAgent::MapperProxy.instance
13
- NFAgent::MapperProxy.instance
14
- NFAgent::MapperProxy.instance
15
- end
16
-
17
- test "mapper method" do
18
- assert_equal 'acme', NFAgent::MapperProxy.find_account_id('dan', '192.168.0.10')
19
- end
20
- end
@@ -1,8 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class NFAgentTest < ActiveSupport::TestCase
5
- test "just return true" do
6
- assert true
7
- end
8
- end
@@ -1,77 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestPayload < ActiveSupport::TestCase
5
- setup do
6
- FileUtils.rm_f(Dir.glob("test/sandbox/dumps/*"))
7
- end
8
-
9
- test "to_hash" do
10
- payload = NFAgent::Payload.new do |p|
11
- p.data = "data"
12
- p.checksum = "checksum"
13
- p.line_count = 10
14
- p.chunk_expired = false
15
- end
16
- assert_equal({ 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false }, payload.to_hash)
17
- # Check key
18
- payload = NFAgent::Payload.new do |p|
19
- p.data = "data"
20
- p.checksum = "checksum"
21
- p.line_count = 10
22
- p.chunk_expired = false
23
- p.key = '1234'
24
- end
25
- assert_equal({ 'payload' => 'data', 'checksum' => 'checksum', 'line_count' => 10, 'chunk_expired' => false, 'key' => '1234' }, payload.to_hash)
26
- end
27
-
28
- test "write-to-disk" do
29
- payload = NFAgent::Payload.new do |p|
30
- p.data = "data"
31
- p.checksum = "checksum"
32
- p.line_count = 10
33
- p.chunk_expired = false
34
- end
35
- payload.write_to_disk("test/sandbox/dumps")
36
- assert File.exists?("test/sandbox/dumps/checksum-0")
37
- # And read back in
38
- payload = NFAgent::Payload.read_from_file("checksum-0", "test/sandbox/dumps/")
39
- assert_equal "data", payload.data
40
- assert_equal 0, payload.attempt
41
- assert !payload.key
42
- end
43
-
44
- test "write-to-disk with non-zero attempt number" do
45
- payload = NFAgent::Payload.new do |p|
46
- p.data = "data"
47
- p.checksum = "checksum"
48
- p.line_count = 10
49
- p.chunk_expired = false
50
- p.attempt = 10
51
- end
52
- payload.write_to_disk("test/sandbox/dumps")
53
- assert File.exists?("test/sandbox/dumps/checksum-10")
54
- # And read back in
55
- payload = NFAgent::Payload.read_from_file("checksum-10", "test/sandbox/dumps/")
56
- assert_equal "data", payload.data
57
- assert_equal 10, payload.attempt
58
- end
59
-
60
- test "write-to-disk with key" do
61
- payload = NFAgent::Payload.new do |p|
62
- p.data = "data"
63
- p.checksum = "checksum"
64
- p.line_count = 10
65
- p.chunk_expired = false
66
- p.key = '1234'
67
- end
68
- payload.write_to_disk("test/sandbox/dumps")
69
- assert File.exists?("test/sandbox/dumps/checksum-0-1234")
70
- # And read back in
71
- payload = NFAgent::Payload.read_from_file("checksum-0-1234", "test/sandbox/dumps/")
72
- assert_equal "data", payload.data
73
- assert_equal 0, payload.attempt
74
- assert_equal '1234', payload.key
75
- end
76
-
77
- end
@@ -1,13 +0,0 @@
1
-
2
- require 'test/test_helper'
3
-
4
- class TestPlugin < ActiveSupport::TestCase
5
- setup do
6
- end
7
-
8
- test "load" do
9
- assert_raise(NameError) { Object.const_get("MissingMapper") }
10
- NFAgent::Plugin.load_plugins
11
- Object.const_get("MyMapper")
12
- end
13
- end