snoopit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +39 -0
  4. data/.idea/.name +1 -0
  5. data/.idea/.rakeTasks +7 -0
  6. data/.idea/dictionaries/rbirch.xml +9 -0
  7. data/.idea/encodings.xml +5 -0
  8. data/.idea/misc.xml +5 -0
  9. data/.idea/modules.xml +9 -0
  10. data/.idea/scopes/scope_settings.xml +5 -0
  11. data/.idea/snoopit.iml +233 -0
  12. data/.idea/vcs.xml +7 -0
  13. data/.rspec +2 -0
  14. data/.travis.yml +7 -0
  15. data/Gemfile +15 -0
  16. data/LICENSE.txt +22 -0
  17. data/README.md +411 -0
  18. data/Rakefile +1 -0
  19. data/bin/snoopit +173 -0
  20. data/lib/snoopit.rb +22 -0
  21. data/lib/snoopit/detected.rb +50 -0
  22. data/lib/snoopit/file_info.rb +104 -0
  23. data/lib/snoopit/file_tracker.rb +83 -0
  24. data/lib/snoopit/logger.rb +30 -0
  25. data/lib/snoopit/notification_manager.rb +123 -0
  26. data/lib/snoopit/notifier.rb +25 -0
  27. data/lib/snoopit/notifiers/email.rb +61 -0
  28. data/lib/snoopit/notifiers/http.rb +85 -0
  29. data/lib/snoopit/notifiers/https.rb +21 -0
  30. data/lib/snoopit/notifiers/stomp.rb +59 -0
  31. data/lib/snoopit/register.rb +69 -0
  32. data/lib/snoopit/sniffer.rb +51 -0
  33. data/lib/snoopit/snooper.rb +149 -0
  34. data/lib/snoopit/snoopy.rb +67 -0
  35. data/lib/snoopit/version.rb +3 -0
  36. data/snoopit.gemspec +27 -0
  37. data/spec/bin/snoopit_spec.rb +258 -0
  38. data/spec/file_info_spec.rb +131 -0
  39. data/spec/file_tracker_spec.rb +172 -0
  40. data/spec/notification_manager_spec.rb +103 -0
  41. data/spec/notifiers/email_spec.rb +36 -0
  42. data/spec/notifiers/http_spec.rb +37 -0
  43. data/spec/notifiers/https_spec.rb +38 -0
  44. data/spec/notifiers/stomp_spec.rb +34 -0
  45. data/spec/register_spec.rb +105 -0
  46. data/spec/snooper_spec.rb +538 -0
  47. data/spec/spec_helper.rb +24 -0
  48. data/spec/support/log/snoop_log.test +593 -0
  49. data/spec/support/log/snoop_log_2.test +593 -0
  50. data/spec/support/multiple_snoopies.json +82 -0
  51. data/spec/support/regexp_tester.rb +10 -0
  52. data/spec/support/snoopies.json +93 -0
  53. data/spec/support/snoopies_notifiers.json +66 -0
  54. data/spec/support/test_notifier.rb +18 -0
  55. data/spec/support/test_notifier_load.rb +18 -0
  56. data/support/snoopies.json +110 -0
  57. metadata +190 -0
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'awesome_print'
3
+
4
+ describe 'HTTPS Notifier' do
5
+
6
+ before(:each) do
7
+ @file = File.expand_path('../../support/snoopies_notifiers.json', __FILE__)
8
+ @json = IO.read(@file)
9
+ @json_hash = JSON.parse(@json)
10
+ @json_hash['notifiers'].delete 'http'
11
+ @json_hash['notifiers'].delete 'stomp'
12
+ @json_hash['notifiers'].delete 'email'
13
+ @snooper = Snooper.new false
14
+ @nm = NotificationManager.new
15
+ @snooper.load_snoopers @json_hash
16
+ @nm.load_notifier_config @json_hash['notifiers']
17
+ @nm.unregister_by_name 'email'
18
+ end
19
+
20
+ it 'http stub notify' do
21
+ http = @nm.get_notifier 'https'
22
+ expect(http.name).to eq 'https'
23
+ snoopies = @snooper.snoop
24
+ h = @nm.get_notifier 'https'
25
+ h.stub(:notify)
26
+ @nm.notify(snoopies)
27
+ end
28
+
29
+ it 'http notify', :skip do
30
+ http = @nm.get_notifier 'https'
31
+ expect(http.name).to eq 'https'
32
+ snoopies = @snooper.snoop
33
+ @nm.notify(snoopies)
34
+ end
35
+
36
+
37
+
38
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Stomp Notifier' do
4
+
5
+ before(:each) do
6
+ @file = File.expand_path('../../support/snoopies_notifiers.json', __FILE__)
7
+ @json = IO.read(@file)
8
+ @json_hash = JSON.parse(@json)
9
+ @snooper = Snooper.new false
10
+ @nm = NotificationManager.new
11
+ @json_hash['notifiers'].delete 'http'
12
+ @json_hash['notifiers'].delete 'https'
13
+ @json_hash['notifiers'].delete 'email'
14
+ @snooper.load_snoopers @json_hash
15
+ @nm.load_notifier_config @json_hash['notifiers']
16
+ @nm.unregister_by_name 'email'
17
+ end
18
+
19
+ it 'stomp stub notify' do
20
+ stomp = @nm.get_notifier 'stomp'
21
+ expect(stomp.name).to eq 'stomp'
22
+ snoopies = @snooper.snoop
23
+ h = @nm.get_notifier 'stomp'
24
+ n = h.stub(:notify)
25
+ @nm.notify(snoopies)
26
+ end
27
+
28
+ it 'stomp notify', :skip do
29
+ stomp = @nm.get_notifier 'stomp'
30
+ expect(stomp.name).to eq 'stomp'
31
+ snoopies = @snooper.snoop
32
+ @nm.notify(snoopies)
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Register' do
4
+
5
+ it 'Register size 4 push_front' do
6
+ register = Register.new 4
7
+ register.size.should == 4
8
+ register.push_front 1
9
+ register.size.should == 4
10
+ register[0].should == 1
11
+ register[1].should == nil
12
+ register[2].should == nil
13
+ register[3].should == nil
14
+ register.push_front 2
15
+ register.size.should == 4
16
+ register.push_front 3
17
+ register.size.should == 4
18
+ register.push_front 4
19
+ register.size.should == 4
20
+ register[0].should == 4
21
+ register[1].should == 3
22
+ register[2].should == 2
23
+ register[3].should == 1
24
+ register.push_front 5
25
+ register[0].should == 5
26
+ register[1].should == 4
27
+ register[2].should == 3
28
+ register[3].should == 2
29
+ register[5].should eq nil
30
+ end
31
+
32
+ it 'Register size 1 push_front' do
33
+ register = Register.new 1
34
+ register.size.should == 1
35
+ register.push_front 1
36
+ register.size.should == 1
37
+ register[0].should == 1
38
+ register.size.should == 1
39
+ register.push_front 2
40
+ register.size.should == 1
41
+ register[0].should == 2
42
+ end
43
+
44
+ it 'Register size 0 push_front' do
45
+ register = Register.new 0
46
+ register.size.should == 0
47
+ register.push_front 1
48
+ register.size.should == 0
49
+ register.push_front 'test'
50
+ register.size.should == 0
51
+ register[0].should eq nil
52
+ register[99].should eq nil
53
+ end
54
+
55
+ it 'Register size 4 push_back' do
56
+ register = Register.new 4
57
+ register.size.should == 4
58
+ register.push_back 1
59
+ register.size.should == 4
60
+ register[0].should == nil
61
+ register[1].should == nil
62
+ register[2].should == nil
63
+ register[3].should == 1
64
+ register.push_back 2
65
+ register.size.should == 4
66
+ register.push_back 3
67
+ register.size.should == 4
68
+ register.push_back 4
69
+ register.size.should == 4
70
+ register[0].should == 1
71
+ register[1].should == 2
72
+ register[2].should == 3
73
+ register[3].should == 4
74
+ register.push_back 5
75
+ register.size.should == 4
76
+ register[0].should == 2
77
+ register[1].should == 3
78
+ register[2].should == 4
79
+ register[3].should == 5
80
+ end
81
+
82
+ it 'Register size 0 push_back' do
83
+ register = Register.new 0
84
+ register.size.should == 0
85
+ register.push_back 1
86
+ register.size.should == 0
87
+ register.push_back 'test'
88
+ register.size.should == 0
89
+ register[0].should eq nil
90
+ register[99].should eq nil
91
+ end
92
+
93
+ it 'Test Register array assignment' do
94
+ register = Register.new 5
95
+ register[0] = 'foo'
96
+ register[0].should eq 'foo'
97
+ end
98
+
99
+ it 'test enumerable' do
100
+ rtest = [1,2,3,4,5]
101
+ register = Register.new 5, rtest
102
+ register.each_with_index { |r, i| r.should eq rtest[i] }
103
+ end
104
+
105
+ end
@@ -0,0 +1,538 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Snooper' do
4
+
5
+ context 'base functionality' do
6
+
7
+ before(:each) do
8
+ Snoopit.logger.level = ::Logger::DEBUG
9
+ @file = File.expand_path('../support/snoopies.json', __FILE__)
10
+ @json = IO.read(@file)
11
+ @jhash = JSON.parse(@json)
12
+ @jsnoopy = @jhash['snoopers']['SnoopTest']
13
+ @jsnoopy2 = @jhash['snoopers']['AppServer2']
14
+ @snooper = Snooper.new
15
+ end
16
+
17
+ def test_snooper(snooper)
18
+ snooper.snoopies.size.should eq 2
19
+ snoopy = snooper.snoopies['SnoopTest']
20
+ snoopy.input.should eq @jsnoopy['snoop']
21
+ snoopy.dir.should eq @jsnoopy['dir']['path']
22
+ snoopy.glob.should eq @jsnoopy['dir']['glob']
23
+ snoopy.input_check?.should == true
24
+ end
25
+
26
+ context 'snooper initialization' do
27
+
28
+ it 'loads a regexp configuration file and validates input and dir via file' do
29
+ @snooper.load_file @file
30
+ test_snooper @snooper
31
+ end
32
+
33
+ it 'loads a regexp configuration and validates input and dir via json string' do
34
+ @snooper.load_json @json
35
+ test_snooper @snooper
36
+ end
37
+
38
+ it 'loads a regexp configuration and validates input and dir via array of snoopies' do
39
+ @snooper.load_snoopers @jhash
40
+ test_snooper @snooper
41
+ end
42
+
43
+ it 'loads a regexp configuration and with invalid input file' do
44
+ expect { @snooper.load_file(nil) }.to raise_error ArgumentError
45
+ end
46
+
47
+ it 'loads a regexp configuration and with no snoopies via empty hash' do
48
+ expect { @snooper.load_snoopers ({ 'snoopers' => [] }) }.to raise_error ArgumentError
49
+ end
50
+
51
+ end
52
+
53
+ context 'file tests' do
54
+
55
+ before(:each) do
56
+ @jsnoopy['dir'] = nil
57
+ @jsnoopy2['dir'] = nil
58
+ end
59
+
60
+ it 'loads a regexp configuration and with invalid input and dir via hash' do
61
+ @jsnoopy['snoop'] = nil
62
+ expect { @snooper.load_snoopers @jhash }.to raise_error ArgumentError
63
+ end
64
+
65
+ it 'loads a snoopies json file and sniffs out a log file' do
66
+ #Snoopit.logger.level = ::Logger::DEBUG
67
+ @snooper.load_snoopers @jhash
68
+ @snooper.snoopies.size.should == 2
69
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
70
+ @snooper.snoopies['AppServer2'].sniffers.size.should == 1
71
+ snoopies = @snooper.snoop
72
+ snoopies.each do |snoopy|
73
+ snoopy.sniffers.each do |sniffer|
74
+ if sniffer.regexp.source == 'Non OK Status'
75
+ sniffer.sniffed.size.should eq 60
76
+ sniffer.sniffed.each do |sniffed|
77
+ sniffed.before.size.should eq 2
78
+ sniffed.after.size.should eq 2
79
+ end
80
+ elsif sniffer.regexp.source == 'Failed to bulk load'
81
+ sniffer.sniffed.size.should eq 1
82
+ sniffer.sniffed.each do |sniffed|
83
+ sniffed.before.size.should eq 2
84
+ sniffed.after.size.should eq 2
85
+ end
86
+ elsif sniffer.regexp.source == 'Total Number of records:'
87
+ sniffer.sniffed.size.should eq 47
88
+ sniffer.sniffed.each do |sniffed|
89
+ sniffed.before.size.should eq 1
90
+ sniffed.after.size.should eq 1
91
+ end
92
+ else
93
+ # This should not happen
94
+ true.should eq false
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ it 'loads a snoopies json file and sniffs out a log file zero before zero after' do
101
+ @jsnoopy['sniffers'].each do |sniffer|
102
+ sniffer['lines']['before'] = 0
103
+ sniffer['lines']['after'] = 0
104
+ end
105
+ @jsnoopy2['sniffers'].each do |sniffer|
106
+ sniffer['lines']['before'] = 0
107
+ sniffer['lines']['after'] = 0
108
+ end
109
+ @snooper.load_snoopers @jhash
110
+ @snooper.snoopies.size.should == 2
111
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
112
+ snoopies = @snooper.snoop
113
+ snoopies.each do |snoopy|
114
+ snoopy.sniffers.each do |sniffer|
115
+ if sniffer.regexp.source == 'Non OK Status'
116
+ sniffer.sniffed.size.should eq 60
117
+ sniffer.sniffed.each do |sniffed|
118
+ sniffed.before.size.should eq 0
119
+ sniffed.after.size.should eq 0
120
+ end
121
+ elsif sniffer.regexp.source == 'Failed to bulk load'
122
+ sniffer.sniffed.size.should eq 1
123
+ sniffer.sniffed.each do |sniffed|
124
+ sniffed.before.size.should eq 0
125
+ sniffed.after.size.should eq 0
126
+ end
127
+ elsif sniffer.regexp.source == 'Total Number of records:'
128
+ sniffer.sniffed.size.should eq 47
129
+ sniffer.sniffed.each do |sniffed|
130
+ sniffed.before.size.should eq 0
131
+ sniffed.after.size.should eq 0
132
+ end
133
+ else
134
+ # This should not happen
135
+ true.should eq false
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+
142
+ it 'loads a snoopies json file and sniffs out a log file 0 before 1 after' do
143
+ @jsnoopy['sniffers'].each do |sniffer|
144
+ sniffer['lines']['before'] = 0
145
+ sniffer['lines']['after'] = 1
146
+ end
147
+ @jsnoopy2['sniffers'].each do |sniffer|
148
+ sniffer['lines']['before'] = 0
149
+ sniffer['lines']['after'] = 1
150
+ end
151
+ @snooper.load_snoopers @jhash
152
+ @snooper.snoopies.size.should == 2
153
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
154
+ @snooper.snoopies['AppServer2'].sniffers.size.should == 1
155
+ snoopies = @snooper.snoop
156
+ snoopies.each do |snoopy|
157
+ snoopy.sniffers.each do |sniffer|
158
+ if sniffer.regexp.source == 'Non OK Status'
159
+ sniffer.sniffed.size.should eq 60
160
+ sniffer.sniffed.each do |sniffed|
161
+ sniffed.before.size.should eq 0
162
+ sniffed.after.size.should eq 1
163
+ end
164
+ elsif sniffer.regexp.source == 'Failed to bulk load'
165
+ sniffer.sniffed.size.should eq 1
166
+ sniffer.sniffed.each do |sniffed|
167
+ sniffed.before.size.should eq 0
168
+ sniffed.after.size.should eq 1
169
+ end
170
+ elsif sniffer.regexp.source == 'Total Number of records:'
171
+ sniffer.sniffed.size.should eq 47
172
+ sniffer.sniffed.each do |sniffed|
173
+ sniffed.before.size.should eq 0
174
+ sniffed.after.size.should eq 1
175
+ end
176
+ else
177
+ # This should not happen
178
+ true.should eq false
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+
185
+ it 'loads a snoopies json file and sniffs out a log file 1 before 0 after' do
186
+ @jsnoopy['sniffers'].each do |sniffer|
187
+ sniffer['lines']['before'] = 1
188
+ sniffer['lines']['after'] = 0
189
+ end
190
+ @jsnoopy2['sniffers'].each do |sniffer|
191
+ sniffer['lines']['before'] = 1
192
+ sniffer['lines']['after'] = 0
193
+ end
194
+ @snooper.load_snoopers @jhash
195
+ @snooper.snoopies.size.should == 2
196
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
197
+ snoopies = @snooper.snoop
198
+ snoopies.each do |snoopy|
199
+ snoopy.sniffers.each do |sniffer|
200
+ if sniffer.regexp.source == 'Non OK Status'
201
+ sniffer.sniffed.size.should eq 60
202
+ sniffer.sniffed.each do |sniffed|
203
+ sniffed.before.size.should eq 1
204
+ sniffed.after.size.should eq 0
205
+ end
206
+ elsif sniffer.regexp.source == 'Failed to bulk load'
207
+ sniffer.sniffed.size.should eq 1
208
+ sniffer.sniffed.each do |sniffed|
209
+ sniffed.before.size.should eq 1
210
+ sniffed.after.size.should eq 0
211
+ end
212
+ elsif sniffer.regexp.source == 'Total Number of records:'
213
+ sniffer.sniffed.size.should eq 47
214
+ sniffer.sniffed.each do |sniffed|
215
+ sniffed.before.size.should eq 1
216
+ sniffed.after.size.should eq 0
217
+ end
218
+ else
219
+ # This should not happen
220
+ true.should eq false
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ it 'Dump trace' do
227
+ #dump_it
228
+ end
229
+
230
+ def dump_it
231
+ @snooper.load_snoopers [ @jsnoopy ]
232
+ #Snoopit.logger.level = ::Logger::DEBUG
233
+ tracked = @snooper.snoop
234
+ puts "Number of snoopies with found data: #{tracked.size}"
235
+ tracked.each do |snoopy|
236
+ puts "Number of snoopy sniffers with found data: #{snoopy.sniffers.size}"
237
+ snoopy.sniffers.each do |sniffer|
238
+ puts "Number of snoopy sniffers with sniffed out data: #{sniffer.sniffed.size}"
239
+ sniffer.sniffed.each do |sniffed|
240
+ puts ''
241
+ sniffed.before.register.each {|b| puts "Before: #{b}" unless b.nil? }
242
+ puts "Matched: #{sniffed.match}"
243
+ sniffed.after.register.each {|a| puts "After: #{a}" unless a.nil? }
244
+ puts "Before register size: #{sniffed.before.register.size}"
245
+ puts "After register size: #{sniffed.after.register.size}"
246
+ puts "File: #{sniffed.file}"
247
+ puts "Line No: #{sniffed.line_no}"
248
+ puts ''
249
+ end
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ context 'directory testing' do
256
+
257
+ before(:each) do
258
+ #Snoopit.logger.level = ::Logger::DEBUG
259
+ end
260
+
261
+ it 'loads a snoopies json file and sniffs out a directory' do
262
+ @jsnoopy['dir']['glob'] = nil
263
+ @snooper.load_snoopers @jhash
264
+ @snooper.snoopies.size.should == 2
265
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
266
+ snoopies = @snooper.snoop
267
+ snoopies.each do |snoopy|
268
+ snoopy.sniffers.each do |sniffer|
269
+ if sniffer.regexp.source == 'Non OK Status'
270
+ sniffer.sniffed.size.should eq 120
271
+ sniffer.sniffed.each do |sniffed|
272
+ sniffed.before.size.should eq 2
273
+ sniffed.after.size.should eq 2
274
+ end
275
+ elsif sniffer.regexp.source == 'Failed to bulk load'
276
+ sniffer.sniffed.size.should eq 2
277
+ sniffer.sniffed.each do |sniffed|
278
+ sniffed.before.size.should eq 2
279
+ sniffed.after.size.should eq 2
280
+ end
281
+ elsif sniffer.regexp.source == 'Total Number of records:'
282
+ sniffer.sniffed.size.should eq 94
283
+ sniffer.sniffed.each do |sniffed|
284
+ sniffed.before.size.should eq 1
285
+ sniffed.after.size.should eq 1
286
+ end
287
+ else
288
+ # This should not happen
289
+ true.should eq false
290
+ end
291
+ end
292
+ end
293
+ end
294
+
295
+ it 'loads a snoopies json file and sniffs out a glob directory' do
296
+ @snooper.load_snoopers @jhash
297
+ @snooper.snoopies.size.should == 2
298
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 3
299
+ snoopies = @snooper.snoop
300
+ snoopies.each do |snoopy|
301
+ snoopy.sniffers.each do |sniffer|
302
+ if sniffer.regexp.source == 'Non OK Status'
303
+ sniffer.sniffed.size.should eq 120
304
+ sniffer.sniffed.each do |sniffed|
305
+ sniffed.before.size.should eq 2
306
+ sniffed.after.size.should eq 2
307
+ end
308
+ elsif sniffer.regexp.source == 'Failed to bulk load'
309
+ sniffer.sniffed.size.should eq 2
310
+ sniffer.sniffed.each do |sniffed|
311
+ sniffed.before.size.should eq 2
312
+ sniffed.after.size.should eq 2
313
+ end
314
+ elsif sniffer.regexp.source == 'Total Number of records:'
315
+ sniffer.sniffed.size.should eq 94
316
+ sniffer.sniffed.each do |sniffed|
317
+ sniffed.before.size.should eq 1
318
+ sniffed.after.size.should eq 1
319
+ end
320
+ else
321
+ # This should not happen
322
+ true.should eq false
323
+ end
324
+ end
325
+ end
326
+ end
327
+ end
328
+
329
+ context 'notifiers' do
330
+
331
+ it 'check notifiers' do
332
+ @snooper.load_snoopers @jhash
333
+ snoopies = @snooper.snoop
334
+ snoopies.each do |snoopy|
335
+ snoopy.sniffers.each do |sniffer|
336
+ sniffer.notifiers.size.should eq 1 unless sniffer.notifiers.size == 0
337
+ sniffer.notifiers.each do |notifier|
338
+ next if notifier.nil?
339
+ if sniffer.comment.include? 'Data gathered to generate a statistics report'
340
+ expect(notifier).to include 'Test Notifier Load'
341
+ else
342
+ expect(notifier).to include 'Test Notifier'
343
+ end
344
+ end
345
+ end
346
+ end
347
+ end
348
+ end
349
+ end
350
+
351
+
352
+ context 'multiple snoopers' do
353
+
354
+ before(:each) do
355
+ @file = File.expand_path('../support/multiple_snoopies.json', __FILE__)
356
+ @json = IO.read(@file)
357
+ @jhash = JSON.parse(@json)
358
+ @jsnoopy = @jhash['snoopers']
359
+ @snooper = Snooper.new
360
+ end
361
+
362
+ it 'loads a snoopies json file and sniffs out a log file' do
363
+ @jhash['snoopers'].each do |key, snoop|
364
+ snoop['dir'] = nil
365
+ end
366
+ @snooper.load_snoopers @jhash
367
+ @snooper.snoopies.size.should == 2
368
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
369
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
370
+ snoopies = @snooper.snoop
371
+ @snooper.snoopies.size.should == 2
372
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
373
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
374
+ process_snoopies = []
375
+ snoopies.each do |snoopy|
376
+ process_snoopies << snoopy.name
377
+ snoopy.sniffers.each do |sniffer|
378
+
379
+ if sniffer.regexp.source == 'Non OK Status'
380
+ sniffer.sniffed.size.should eq 60
381
+ sniffer.sniffed.each do |sniffed|
382
+ sniffed.before.size.should eq 2
383
+ sniffed.after.size.should eq 2
384
+ end
385
+ elsif sniffer.regexp.source == 'Failed to bulk load'
386
+ sniffer.sniffed.size.should eq 1
387
+ sniffer.sniffed.each do |sniffed|
388
+ sniffed.before.size.should eq 2
389
+ sniffed.after.size.should eq 2
390
+ end
391
+ elsif sniffer.regexp.source == 'Total Number of records:'
392
+ sniffer.sniffed.size.should eq 47
393
+ sniffer.sniffed.each do |sniffed|
394
+ sniffed.before.size.should eq 1
395
+ sniffed.after.size.should eq 1
396
+ end
397
+ else
398
+ # This should not happen
399
+ true.should eq false
400
+ end
401
+ end
402
+ end
403
+ expect(process_snoopies).to include 'SnoopTest'
404
+ expect(process_snoopies).to include 'SnoopTest2'
405
+ end
406
+
407
+
408
+ it 'loads a snoopies json file and sniffs out a directory of log files' do
409
+ @snooper.load_snoopers @jhash
410
+ @snooper.snoopies.size.should == 2
411
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
412
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
413
+ snoopies = @snooper.snoop
414
+ @snooper.snoopies.size.should == 2
415
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
416
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
417
+ process_snoopies = []
418
+ snoopies.each do |snoopy|
419
+ process_snoopies << snoopy.name
420
+ snoopy.sniffers.each do |sniffer|
421
+ if sniffer.regexp.source == 'Non OK Status'
422
+ sniffer.sniffed.size.should eq 120
423
+ sniffer.sniffed.each do |sniffed|
424
+ sniffed.before.size.should eq 2
425
+ sniffed.after.size.should eq 2
426
+ end
427
+ elsif sniffer.regexp.source == 'Failed to bulk load'
428
+ sniffer.sniffed.size.should eq 2
429
+ sniffer.sniffed.each do |sniffed|
430
+ sniffed.before.size.should eq 2
431
+ sniffed.after.size.should eq 2
432
+ end
433
+ elsif sniffer.regexp.source == 'Total Number of records:'
434
+ sniffer.sniffed.size.should eq 94
435
+ sniffer.sniffed.each do |sniffed|
436
+ sniffed.before.size.should eq 1
437
+ sniffed.after.size.should eq 1
438
+ end
439
+ else
440
+ # This should not happen
441
+ true.should eq false
442
+ end
443
+ end
444
+ end
445
+ expect(process_snoopies).to include 'SnoopTest'
446
+ expect(process_snoopies).to include 'SnoopTest2'
447
+ end
448
+
449
+
450
+ it 'loads a snoopies json file and sniffs out a log file with a specified 1 snooper' do
451
+ @jhash['snoopers'].each do |key, snoop|
452
+ snoop['dir'] = nil
453
+ end
454
+ @snooper.load_snoopers @jhash
455
+ @snooper.snoopies.size.should == 2
456
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
457
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
458
+ snoopies = @snooper.snoop ['SnoopTest']
459
+ snoopies.size.should == 1
460
+ snoopies[0].sniffers.size.should == 2
461
+ process_snoopies = []
462
+ snoopies.each do |snoopy|
463
+ process_snoopies << snoopy.name
464
+ snoopy.sniffers.each do |sniffer|
465
+ if sniffer.regexp.source == 'Non OK Status'
466
+ sniffer.sniffed.size.should eq 60
467
+ sniffer.sniffed.each do |sniffed|
468
+ sniffed.before.size.should eq 2
469
+ sniffed.after.size.should eq 2
470
+ end
471
+ elsif sniffer.regexp.source == 'Failed to bulk load'
472
+ sniffer.sniffed.size.should eq 1
473
+ sniffer.sniffed.each do |sniffed|
474
+ sniffed.before.size.should eq 2
475
+ sniffed.after.size.should eq 2
476
+ end
477
+ elsif sniffer.regexp.source == 'Total Number of records:'
478
+ sniffer.sniffed.size.should eq 47
479
+ sniffer.sniffed.each do |sniffed|
480
+ sniffed.before.size.should eq 1
481
+ sniffed.after.size.should eq 1
482
+ end
483
+ else
484
+ # This should not happen
485
+ true.should eq false
486
+ end
487
+ end
488
+ end
489
+ expect(process_snoopies).to include 'SnoopTest'
490
+ expect(process_snoopies).not_to include 'SnoopTest2'
491
+ end
492
+
493
+ it 'loads a snoopies json file and sniffs out a log file with 2 specified snoopers' do
494
+ @jhash['snoopers'].each do |key, snoop|
495
+ snoop['dir'] = nil
496
+ end
497
+ @snooper.load_snoopers @jhash
498
+ @snooper.snoopies.size.should == 2
499
+ @snooper.snoopies['SnoopTest'].sniffers.size.should == 2
500
+ @snooper.snoopies['SnoopTest2'].sniffers.size.should == 1
501
+ snoopies = @snooper.snoop ['SnoopTest', 'SnoopTest2']
502
+ snoopies.size.should == 2
503
+ process_snoopies = []
504
+ snoopies.each do |snoopy|
505
+ process_snoopies << snoopy.name
506
+ snoopy.sniffers.each do |sniffer|
507
+ if sniffer.regexp.source == 'Non OK Status'
508
+ sniffer.sniffed.size.should eq 60
509
+ sniffer.sniffed.each do |sniffed|
510
+ sniffed.before.size.should eq 2
511
+ sniffed.after.size.should eq 2
512
+ end
513
+ elsif sniffer.regexp.source == 'Failed to bulk load'
514
+ sniffer.sniffed.size.should eq 1
515
+ sniffer.sniffed.each do |sniffed|
516
+ sniffed.before.size.should eq 2
517
+ sniffed.after.size.should eq 2
518
+ end
519
+ elsif sniffer.regexp.source == 'Total Number of records:'
520
+ sniffer.sniffed.size.should eq 47
521
+ sniffer.sniffed.each do |sniffed|
522
+ sniffed.before.size.should eq 1
523
+ sniffed.after.size.should eq 1
524
+ end
525
+ else
526
+ # This should not happen
527
+ true.should eq false
528
+ end
529
+ end
530
+ end
531
+ expect(process_snoopies).to include 'SnoopTest'
532
+ expect(process_snoopies).to include 'SnoopTest2'
533
+ end
534
+
535
+ end
536
+
537
+
538
+ end