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,51 @@
1
+ module Snoopit
2
+ class Sniffer
3
+
4
+ attr :pre_before, :before, :after, :comment, :regexp, :sniffed, :notifiers
5
+
6
+ def initialize(sniffer_params)
7
+ @before = sniffer_params['lines']['before'].nil? ? 2 : sniffer_params['lines']['before']
8
+ @pre_before = Register.new @before
9
+ @after = sniffer_params['lines']['after'].nil? ? 2 : sniffer_params['lines']['after']
10
+ @comment = sniffer_params['comment']
11
+ @regexp = Regexp.new sniffer_params['regexp']
12
+ @notifiers = {}
13
+ setup_notifiers sniffer_params
14
+ @sniffed = []
15
+ end
16
+
17
+ def setup_notifiers(params)
18
+ @notifiers = params['notify'] unless params['notify'].nil?
19
+ end
20
+
21
+ def track(file, line_no, line)
22
+ matched = @regexp.match(line) do |m|
23
+ @sniffed << Detected.new(@comment, @pre_before, @after, line, file, line_no)
24
+ end
25
+ @pre_before.push_front line if matched.nil?
26
+ tracking line
27
+ end
28
+
29
+ def tracking(line)
30
+ @sniffed.each do |detected|
31
+ detected.track line unless detected.finished?
32
+ end
33
+ end
34
+
35
+ def as_json(options=nil)
36
+ {
37
+ before: @before,
38
+ after: @after,
39
+ comment: @comment,
40
+ regexp: @regexp.to_json,
41
+ sniffed: @sniffed,
42
+ notifiers: @notifiers
43
+ }
44
+ end
45
+
46
+ def to_json(*a)
47
+ as_json.to_json(*a)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,149 @@
1
+ require 'json'
2
+ module Snoopit
3
+ class Snooper
4
+
5
+ attr_accessor :snoopies, :notifier, :file_tracker
6
+
7
+ # Snoopies are the list of available named snoopers
8
+ # Snoopers are the current active invocations of selected snoopies
9
+ def initialize(notifications=true, db_file=nil, logger=nil, log_level=::Logger::INFO)
10
+ @snoopies = { }
11
+ @file_tracker = FileTracker.new db_file unless db_file.nil?
12
+ @notifier = NotificationManager.new if notifications
13
+ Snoopit::Logging.create_logger(logger) unless logger.nil?
14
+ Snoopit.logger.level = log_level
15
+ end
16
+
17
+ # Load the configuration from a file
18
+ # Calls <code>load_snoopers(json_hash)</code> and <code>load_notifiers(json_hash)</code> and
19
+ # @param snoopies_file [String] path to file
20
+ def load_file(snoopies_file)
21
+ raise ArgumentError.new "Invalid Snooper JSON File: #{snoopies_file}" if (snoopies_file.nil?) || (! File.exist? snoopies_file)
22
+ json_hash = JSON.parse(IO.read(snoopies_file))
23
+ load_snoopers json_hash
24
+ load_notifiers json_hash
25
+ end
26
+
27
+ # Load the configuration from a file
28
+ # @param json [String] json string
29
+ def load_json(json)
30
+ json_hash = JSON.parse(json)
31
+ load_snoopers json_hash
32
+ load_notifiers json_hash
33
+ end
34
+
35
+ # Load the configuration from a file
36
+ # @param json_hash [Hash]
37
+ def load_snoopers(json_hash)
38
+ snoopies_json = json_hash['snoopers']
39
+ snoopies_json.each do |name, snooper|
40
+ @snoopies[name] = Snoopy.new(name, snooper)
41
+ end
42
+ raise ArgumentError.new 'There are no Snoopies in the JSON Snooper ' if @snoopies.size == 0
43
+ end
44
+
45
+ def load_notifiers(json_hash)
46
+ @notifier.load_notifier_config json_hash['notifiers'] unless @notifier.nil?
47
+ end
48
+
49
+ def register_notifier(notifier)
50
+ @notifier.register notifier
51
+ end
52
+
53
+ def unregister_notifier(notifier)
54
+ @notifier.unregister notifier
55
+ end
56
+
57
+ # Use the snoopies and start snooping
58
+ def snoop(names=[])
59
+ snoopers = get_snoopers names
60
+ snoopers.each do |snoopy|
61
+ if (!snoopy.dir.nil?) && (snoopy.dir?)
62
+ snoop_dir snoopy
63
+ else
64
+ snoop_file snoopy
65
+ end
66
+ end
67
+ @notifier.notify snoopers unless @notifier.nil?
68
+ snoopers
69
+ end
70
+
71
+ def get_snoopers(names=[])
72
+ snoopers = []
73
+ use_names = (names.size == 0 ? false : true)
74
+ snoopies.each do |key, snooper|
75
+ if use_names
76
+ snoopers << snooper if names.include? key
77
+ else
78
+ snoopers << snooper
79
+ end
80
+ end
81
+ snoopers
82
+ end
83
+
84
+ def snoop_dir(snoopy)
85
+ Snoopit.logger.debug "Snooping directory: #{snoopy.dir}"
86
+ get_files(snoopy).each do |file|
87
+ next if File.directory? file
88
+ sniff_it snoopy, "#{snoopy.dir}/#{file}"
89
+ end
90
+ end
91
+
92
+ def get_files(snoopy)
93
+ if snoopy.glob?
94
+ files = get_glob_list snoopy
95
+ else
96
+ files = get_file_list snoopy
97
+ end
98
+ files
99
+ end
100
+
101
+ def get_glob_list(snoopy)
102
+ Snoopit.logger.debug "Snooping glob: #{snoopy.glob}"
103
+ cwd = Dir.getwd
104
+ begin
105
+ Dir.chdir snoopy.dir
106
+ files = Dir.glob snoopy.glob
107
+ ensure
108
+ Dir.chdir cwd
109
+ end
110
+ files
111
+ end
112
+
113
+ def get_file_list(snoopy)
114
+ Snoopit.logger.debug "Snooper directory: #{snoopy.dir}"
115
+ Dir.entries snoopy.dir
116
+ end
117
+
118
+ def snoop_file(snoopy)
119
+ raise ArgumentError.new "Could find file #{snoopy.input}" unless File.exist? snoopy.input
120
+ Snoopit.logger.debug "Snooping file: #{snoopy.input} with snoopy: #{snoopy.name}"
121
+ sniff_it snoopy, snoopy.input
122
+ end
123
+
124
+ def sniff_it(snoopy, file_name)
125
+ Snoopit.logger.debug "Sniffing file: #{file_name} with snoopy: #{snoopy.name}"
126
+ unless @file_tracker.nil?
127
+ file_track_read(snoopy, file_name)
128
+ else
129
+ file_read(snoopy, file_name)
130
+ end
131
+ end
132
+
133
+ def file_track_read(snoopy, file_name)
134
+ @file_tracker.foreach file_name do |line, line_no|
135
+ snoopy.sniff snoopy.input, line_no, line
136
+ end
137
+ end
138
+
139
+ def file_read(snoopy, file_name)
140
+ line_no = 0
141
+ File.foreach file_name do |line|
142
+ snoopy.sniff snoopy.input, line_no, line
143
+ line_no += 1
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ end
@@ -0,0 +1,67 @@
1
+ module Snoopit
2
+ class Snoopy
3
+
4
+ attr :name, :input, :output, :dir, :glob, :sniffers
5
+
6
+ def initialize(name, params)
7
+ @name = name
8
+ @output = params['output']
9
+ setup_input params
10
+ setup_dir params unless params['dir'].nil?
11
+ input_check?
12
+ setup_sniffers params
13
+ end
14
+
15
+ def setup_input(params)
16
+ @input = params['snoop']
17
+ end
18
+
19
+ def setup_dir(params)
20
+ @dir = params['dir']['path']
21
+ @glob = params['dir']['glob']
22
+ end
23
+
24
+ def input_check?
25
+ return true unless @input.nil?
26
+ return true unless @dir.nil?
27
+ raise ArgumentError.new('Snooper JSON must contain either an input or dir parameter')
28
+ end
29
+
30
+ def setup_sniffers(params)
31
+ raise ArgumentError.new('Snooper JSON missing sniffers array') if params['sniffers'].nil?
32
+ @sniffers = []
33
+ params['sniffers'].each do |sniffer|
34
+ @sniffers << Sniffer.new(sniffer)
35
+ end
36
+ end
37
+
38
+ def dir?
39
+ ! @dir.nil?
40
+ end
41
+
42
+ def glob?
43
+ ! @glob.nil?
44
+ end
45
+
46
+ def sniff(file, line_no, line)
47
+ @sniffers.each do |sniffer|
48
+ sniffer.track file, line_no, line
49
+ end
50
+ end
51
+
52
+ def as_json(options=nil)
53
+ {
54
+ name: @name,
55
+ input: @input,
56
+ dir: @dir,
57
+ glob: @glob,
58
+ sniffers: @sniffers
59
+ }
60
+ end
61
+
62
+ def to_json(*a)
63
+ as_json.to_json(*a)
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Snoopit
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'snoopit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'snoopit'
8
+ spec.version = Snoopit::VERSION
9
+ spec.authors = ['Robert Birch']
10
+ spec.email = ['robdbirch@gmail.com']
11
+ spec.description = %q{Snoops files for specified information via a simple configuration file}
12
+ spec.summary = %q{Using regular expressions snoops files or directories for specific information. Sends events and tracks repeated invocations as not to send repeat events}
13
+ spec.homepage = 'https://github.com/robdbirch/snoopit/blob/master/README.md'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'awesome_print', '~> 1.2'
22
+ spec.add_runtime_dependency 'stomp', '~> 1.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake', '10.1'
26
+ spec.add_development_dependency 'rspec', '2.14'
27
+ end
@@ -0,0 +1,258 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Snoopit' do
4
+
5
+ # *** Note ***
6
+ # used :skip on some tests due to captured stdout during coverage showing rvm environment only in the ide,
7
+ def capture_stdout(cmd)
8
+ IO.popen cmd, 'r+' do |pipe|
9
+ pipe.close_write
10
+ output = pipe.read
11
+ pipe.close_read
12
+ output
13
+ end
14
+ end
15
+
16
+ def cmd
17
+ lib = File.expand_path '../../../lib', __FILE__
18
+ 'ruby -I ' + lib + ' ' + File.expand_path('../../../bin/snoopit', __FILE__)
19
+ end
20
+
21
+ context 'command line options' do
22
+
23
+ it '--help' do
24
+ output = capture_stdout cmd + ' --help'
25
+ expect(output).to match(/Usage: snoopit \[options\]/)
26
+ expect(output).to match(/--help/)
27
+ expect(output).to match(/-h/)
28
+ expect(output).to match(/-v/)
29
+ expect(output).to match(/-verbose/)
30
+ end
31
+
32
+ it '-h print help message' do
33
+ output = capture_stdout cmd + ' --help'
34
+ expect(output).to match(/Usage: snoopit \[options\]/)
35
+ expect(output).to match(/--help/)
36
+ expect(output).to match(/-h/)
37
+ expect(output).to match(/-v/)
38
+ expect(output).to match(/-verbose/)
39
+ end
40
+
41
+ # use :skip with coverage
42
+ it '-t print a snoopers template to standard out' do
43
+ output = capture_stdout cmd + ' -t'
44
+ jo = JSON.parse output
45
+ notifiers = jo['notifiers']
46
+ expect(notifiers['load'].size).to eq 1
47
+ expect(notifiers['load']['Notifier Identifier']['file']).to eq '/path/to/mynotifier'
48
+ expect(notifiers).to include 'email'
49
+ expect(notifiers).to include 'stomp'
50
+ expect(notifiers).to include 'http'
51
+ expect(notifiers).to include 'https'
52
+ end
53
+
54
+ it '--snoopers file.json load specified snoopers file' do
55
+ file = File.expand_path '../../support/snoopies.json', __FILE__
56
+ output = capture_stdout cmd + ' --snoopers ' + file
57
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
58
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
59
+ expect(output).to include 'Non OK Status'
60
+ expect(output).to include 'Total Number of records'
61
+ end
62
+
63
+ it '-s file.json load specified snoopers file' do
64
+ file = File.expand_path '../../support/snoopies.json', __FILE__
65
+ output = capture_stdout cmd + ' -s ' + file
66
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
67
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
68
+ expect(output).to match /Non OK Status from AI Core\:/
69
+ expect(output).to include 'Non OK Status'
70
+ expect(output).to include 'Total Number of records'
71
+ expect(output).to include 'Failed to bulk load'
72
+ end
73
+
74
+ it '-S snooper only use the specified snooper from the snoopers file' do
75
+ file = File.expand_path '../../support/snoopies.json', __FILE__
76
+ output = capture_stdout cmd + ' -s ' + file + ' -S AppServer2'
77
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
78
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
79
+ expect(output).to match /Non OK Status from AI Core:/
80
+ expect(output).to include 'Non OK Status'
81
+ expect(output).not_to include 'Total Number of records'
82
+ expect(output).not_to include 'Failed to bulk load'
83
+ end
84
+
85
+ it '--snooper snooper only user the specified snooper from the snoopers file' do
86
+ file = File.expand_path '../../support/snoopies.json', __FILE__
87
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2'
88
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
89
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
90
+ expect(output).to match /Non OK Status from AI Core:/
91
+ expect(output).to include 'Non OK Status'
92
+ expect(output).not_to include 'Total Number of records'
93
+ expect(output).not_to include 'Failed to bulk load'
94
+ end
95
+
96
+ # use :skip with coverage
97
+ it '--json generate json output' do
98
+ file = File.expand_path '../../support/snoopies.json', __FILE__
99
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 --json'
100
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
101
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
102
+ expect(output).to match /Non OK Status from AI Core:/
103
+ expect(output).to include 'Non OK Status'
104
+ expect(output).not_to include 'Total Number of records'
105
+ expect(output).not_to include 'Failed to bulk load'
106
+ jo = JSON.parse output
107
+ expect(jo.size).to eq 1
108
+ app2 = jo[0]
109
+ expect(app2['name']).to eq 'AppServer2'
110
+ sniffers = app2['sniffers'][0]
111
+ expect(sniffers['before']).to eq 2
112
+ expect(sniffers['after']).to eq 2
113
+ sniffed = sniffers['sniffed']
114
+ expect(sniffed.size).to eq 120
115
+ end
116
+
117
+ # use :skip with coverage
118
+ it '-j generate json output' do
119
+ file = File.expand_path '../../support/snoopies.json', __FILE__
120
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 -j'
121
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
122
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
123
+ expect(output).to match /Non OK Status from AI Core:/
124
+ expect(output).to include 'Non OK Status'
125
+ expect(output).not_to include 'Total Number of records'
126
+ expect(output).not_to include 'Failed to bulk load'
127
+ jo = JSON.parse output
128
+ expect(jo.size).to eq 1
129
+ app2 = jo[0]
130
+ expect(app2['name']).to eq 'AppServer2'
131
+ sniffers = app2['sniffers'][0]
132
+ expect(sniffers['before']).to eq 2
133
+ expect(sniffers['after']).to eq 2
134
+ sniffed = sniffers['sniffed']
135
+ expect(sniffed.size).to eq 120
136
+ end
137
+
138
+ # use :skip with coverage
139
+ it '2 snoopers' do
140
+ file = File.expand_path '../../support/snoopies.json', __FILE__
141
+ ap file
142
+ output = capture_stdout cmd + ' -s ' + file + ' -S AppServer2 -S SnoopTest -j'
143
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
144
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
145
+ expect(output).to include 'Non OK Status'
146
+ expect(output).to include 'Total Number of records'
147
+ expect(output).to include 'Failed to bulk load'
148
+ jo = JSON.parse output
149
+ expect(jo.size).to eq 2
150
+ app = jo[0]
151
+ names = []
152
+ names << app['name']
153
+ sniffers = app['sniffers'][0]
154
+ expect(sniffers['before']).to eq 2
155
+ expect(sniffers['after']).to eq 2
156
+ sniffed = sniffers['sniffed']
157
+ expect(sniffed.size).to eq 120
158
+ app2 = jo[1]
159
+ names << app2['name']
160
+ expect(names.size).to eq 2
161
+ expect(names).to include 'SnoopTest'
162
+ expect(names).to include 'AppServer2'
163
+ sniffers = app2['sniffers'][0]
164
+ expect(sniffers['before']).to eq 2
165
+ expect(sniffers['after']).to eq 2
166
+ sniffed = sniffers['sniffed']
167
+ expect(sniffed.size).to eq 120
168
+ end
169
+
170
+ it '-T enable file tracking' do
171
+ db_file = File.expand_path '../../../snoopit_db.json', __FILE__
172
+ File.delete db_file if File.exist? db_file
173
+ file = File.expand_path '../../support/snoopies.json', __FILE__
174
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 -T'
175
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
176
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
177
+ expect(output).to match /Non OK Status from AI Core:/
178
+ expect(output).to include 'Non OK Status'
179
+ expect(output).not_to include 'Total Number of records'
180
+ expect(output).not_to include 'Failed to bulk load'
181
+ expect(File.exist?(db_file)).to eq true
182
+ expect(File.size(db_file)).to be > 0
183
+ tracked = File.read db_file
184
+ expect(tracked).to include './spec/support/log/snoop_log.test'
185
+ expect(tracked).to include './spec/support/log/snoop_log_2.test'
186
+ #ap JSON.parse tracked
187
+ File.delete db_file if File.exist? db_file
188
+ end
189
+
190
+ it '--tracking enable file tracking' do
191
+ db_file = File.expand_path '../../../snoopit_db.json', __FILE__
192
+ ap db_file
193
+ File.delete db_file if File.exist? db_file
194
+ file = File.expand_path '../../support/snoopies.json', __FILE__
195
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 --tracking'
196
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
197
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
198
+ expect(output).to match /Non OK Status from AI Core:/
199
+ expect(output).to include 'Non OK Status'
200
+ expect(output).not_to include 'Total Number of records'
201
+ expect(output).not_to include 'Failed to bulk load'
202
+ expect(File.exist?(db_file)).to eq true
203
+ expect(File.size(db_file)).to be > 0
204
+ tracked = File.read db_file
205
+ expect(tracked).to include './spec/support/log/snoop_log.test'
206
+ expect(tracked).to include './spec/support/log/snoop_log_2.test'
207
+ #ap JSON.parse tracked
208
+ File.delete db_file if File.exist? db_file
209
+ end
210
+
211
+ it '-f filename use a different named tracking file' do
212
+ tmp_dir = File.expand_path '../../../tmp', __FILE__
213
+ Dir.mkdir tmp_dir unless Dir.exist?(tmp_dir)
214
+ db_file = File.expand_path '../../../tmp/snoopit_db.json', __FILE__
215
+ File.delete db_file if File.exist? db_file
216
+ file = File.expand_path '../../support/snoopies.json', __FILE__
217
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 -f ' + db_file
218
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
219
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
220
+ expect(output).to match /Non OK Status from AI Core:/
221
+ expect(output).to include 'Non OK Status'
222
+ expect(output).not_to include 'Total Number of records'
223
+ expect(output).not_to include 'Failed to bulk load'
224
+ expect(File.exist?(db_file)).to eq true
225
+ expect(File.size(db_file)).to be > 0
226
+ tracked = File.read db_file
227
+ expect(tracked).to include './spec/support/log/snoop_log.test'
228
+ expect(tracked).to include './spec/support/log/snoop_log_2.test'
229
+ #ap JSON.parse tracked
230
+ File.delete db_file if File.exist? db_file
231
+ end
232
+
233
+ it '--tracking-file filename use a different named tracking file' do
234
+ tmp_dir = File.expand_path '../../../tmp', __FILE__
235
+ Dir.mkdir tmp_dir unless Dir.exist?(tmp_dir)
236
+ db_file = File.expand_path '../../../tmp/snoopit_db.json', __FILE__
237
+ File.delete db_file if File.exist? db_file
238
+ file = File.expand_path '../../support/snoopies.json', __FILE__
239
+ output = capture_stdout cmd + ' -s ' + file + ' --snooper AppServer2 --tracking-file ' + db_file
240
+ expect(output).to match /Reading from queue: scores\:\/queue\/scores/
241
+ expect(output).to match /Prediction loader waiting for scores \.\.\./
242
+ expect(output).to match /Non OK Status from AI Core:/
243
+ expect(output).to include 'Non OK Status'
244
+ expect(output).not_to include 'Total Number of records'
245
+ expect(output).not_to include 'Failed to bulk load'
246
+ expect(File.exist?(db_file)).to eq true
247
+ expect(File.size(db_file)).to be > 0
248
+ tracked = File.read db_file
249
+ expect(tracked).to include './spec/support/log/snoop_log.test'
250
+ expect(tracked).to include './spec/support/log/snoop_log_2.test'
251
+ #ap JSON.parse tracked
252
+ File.delete db_file if File.exist? db_file
253
+ end
254
+
255
+ end
256
+
257
+
258
+ end