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,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'File Info' do
4
+
5
+ let(:data) {
6
+ [
7
+ 'I, [2014-05-01T18:48:17.532019 #13186] INFO -- : Total Number of records received: 3',
8
+ 'W, [2014-05-01T18:48:17.584228 #13186] WARN -- : Failed to bulk load 3 records',
9
+ 'W, [2014-05-01T18:48:17.584287 #13186] WARN -- : PG::NotNullViolation: ERROR: null value in column "scout_id" violates not-null constraint',
10
+ ': INSERT INTO "posts" ("author", "body", "created_at", "enterprise_id", "label", "ldate", "leadprob", "lid", "loadstamp", "notleadprob", "scout_id", "sentiment", "source", "state", "updated_at", "url", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"',
11
+ 'W, [2014-05-01T18:48:17.584322 #13186] WARN -- : ["/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `get_last_result\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `exec_cache\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:184:in `exec_insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/relation.rb:76:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:509:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:78:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:306:in `block in create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__1901135813518085503__create__callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:306:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/timestamp.rb:57:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:477:in `create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `block in create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:413:in `_run__1901135813518085503__save__callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:106:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/validations.rb:51:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:32:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:270:in `block (2 levels) in save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:209:in `transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:323:in `with_transaction_returning_status\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:270:in `block in save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:281:in `rollback_active_record_state!\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:269:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:37:in `create\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `block in create\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `collect\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `create\'", "/home/noxaos/pipeline/lib/pipeline/prediction_loader.rb:187:in `bulk_load\'", "/home/noxaos/pipeline/lib/pipeline/prediction_loader.rb:299:in `run\'", "/home/noxaos/pipeline/bin/prediction_loader_server:55:in `<main>\'"]',
12
+ 'I, [2014-05-01T18:48:17.585436 #13186] INFO -- : Prediction loader waiting for scores ...',
13
+ 'D, [2014-05-01T18:48:17.585480 #13186] DEBUG -- : Reading from queue: scores:/queue/scores'
14
+ ]
15
+ }
16
+
17
+ let (:a_line) { 'D, [2014-05-01T18:48:17.585480 #13186] DEBUG -- : Reading from queue: scores:/queue/scores'}
18
+ let (:diff_line) { 'D, [2014-05-01T19:48:17.585480 #13186] DEBUG -- : Reading from queue: scores:/queue/scores'}
19
+
20
+ let(:file) { File.expand_path('../support/log/snoop_log_2.test', __FILE__) }
21
+
22
+ it 'initialize with file' do
23
+ fi = FileInfo.new file
24
+ expect(fi.size).to be == 0
25
+ expect(fi.line_no).to be == 0
26
+ expect(fi.offset).to be == 0
27
+ expect(fi.mtime).to be nil
28
+ end
29
+
30
+ it 'initialize with NO file' do
31
+ fi = FileInfo.new
32
+ expect(fi.size).to be == 0
33
+ expect(fi.line_no).to be == 0
34
+ expect(fi.offset).to be == 0
35
+ expect(fi.mtime).to be nil
36
+ end
37
+
38
+ context 'File Change' do
39
+
40
+ let(:file_dup) { File.expand_path('../support/log/snoop_log_3.test', __FILE__) }
41
+
42
+ before(:each) {
43
+ duplicate
44
+ }
45
+
46
+ after(:each) {
47
+ File.delete file_dup
48
+ }
49
+
50
+ def duplicate
51
+ File.copy_stream(file, file_dup)
52
+ end
53
+
54
+ it 'append to log creating increase in log size indicating change' do
55
+ fi = FileInfo.new file_dup
56
+ fh = File.open file_dup, 'a+'
57
+ data.each do |d|
58
+ fh.write d
59
+ end
60
+ fh.close
61
+ fh = File.open file_dup
62
+ updated = fi.updated? fh
63
+ stat = File.stat file_dup
64
+ expect(updated).to be true
65
+ expect(fi.size).to be == stat.size
66
+ expect(fi.mtime).to be == stat.mtime
67
+ end
68
+
69
+ it 'smaller file change' do
70
+ fi = FileInfo.new file_dup
71
+ fh = File.open file_dup, 'w'
72
+ data.each do |d|
73
+ fh.write d
74
+ end
75
+ fh.close
76
+ fh = File.open file_dup
77
+ updated = fi.updated? fh
78
+ stat = File.stat file_dup
79
+ expect(updated).to be true
80
+ expect(fi.size).to be == stat.size
81
+ expect(fi.mtime).to be == stat.mtime
82
+ end
83
+
84
+ it 'get last line' do
85
+ begin
86
+ fi = FileInfo.new file_dup
87
+ fh = File.open file_dup, 'w+'
88
+ data.each do |d|
89
+ fi.line_no += 1
90
+ fi.last_line = d
91
+ fh.write d
92
+ end
93
+ ll = fi.get_last_line fh
94
+ expect(ll).to be == fi.last_line
95
+ ensure
96
+ fh.close
97
+ end
98
+ end
99
+
100
+ def prime_file_info(fi, fh)
101
+ data.each do |d|
102
+ fi.line_no += 1
103
+ fi.last_line = d
104
+ fh.write d
105
+ end
106
+ end
107
+
108
+ it 'size is same but last but mtime is different' do
109
+ fi = FileInfo.new file_dup
110
+ fh = File.open file_dup, 'w+'
111
+ prime_file_info(fi, fh)
112
+ fi.line_no += 1
113
+ fi.last_line = a_line
114
+ fh.write a_line
115
+ fh.close
116
+ fs = File.stat file_dup
117
+ fi.size = fs.size
118
+ fi.mtime = fs.mtime
119
+ sleep 1
120
+ fh = File.open file_dup, 'w+'
121
+ data.each do |d|
122
+ fh.write d
123
+ end
124
+ fh.write diff_line
125
+ stat = File.stat file_dup
126
+ expect(fi.updated?(fh)).to be true
127
+ fh.close
128
+ expect(fi.size).to be == stat.size
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'File Tracker' do
4
+
5
+ let(:file) { File.expand_path('../support/log/snoop_log_2.test', __FILE__) }
6
+
7
+ let(:append_data) {
8
+ [
9
+ 'I, [2014-05-01T18:48:17.532019 #13186] INFO -- : Total Number of records received: 3',
10
+ 'W, [2014-05-01T18:48:17.584228 #13186] WARN -- : Failed to bulk load 3 records',
11
+ 'W, [2014-05-01T18:48:17.584287 #13186] WARN -- : PG::NotNullViolation: ERROR: null value in column "scout_id" violates not-null constraint',
12
+ ': INSERT INTO "posts" ("author", "body", "created_at", "enterprise_id", "label", "ldate", "leadprob", "lid", "loadstamp", "notleadprob", "scout_id", "sentiment", "source", "state", "updated_at", "url", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"',
13
+ 'W, [2014-05-01T18:48:17.584322 #13186] WARN -- : ["/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `get_last_result\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:786:in `exec_cache\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:184:in `exec_insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/relation.rb:76:in `insert\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:509:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:78:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:306:in `block in create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__1901135813518085503__create__callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:306:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/timestamp.rb:57:in `create_record\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:477:in `create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `block in create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:413:in `_run__1901135813518085503__save__callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/callbacks.rb:302:in `create_or_update\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:106:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/validations.rb:51:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/attribute_methods/dirty.rb:32:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:270:in `block (2 levels) in save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:209:in `transaction\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:323:in `with_transaction_returning_status\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:270:in `block in save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:281:in `rollback_active_record_state!\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/transactions.rb:269:in `save\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:37:in `create\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `block in create\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `collect\'", "/usr/local/rvm/gems/ruby-2.0.0-p195@sociallens/gems/activerecord-4.0.3/lib/active_record/persistence.rb:34:in `create\'", "/home/noxaos/pipeline/lib/pipeline/prediction_loader.rb:187:in `bulk_load\'", "/home/noxaos/pipeline/lib/pipeline/prediction_loader.rb:299:in `run\'", "/home/noxaos/pipeline/bin/prediction_loader_server:55:in `<main>\'"]',
14
+ 'I, [2014-05-01T18:48:17.585436 #13186] INFO -- : Prediction loader waiting for scores ...',
15
+ 'D, [2014-05-01T18:48:17.585480 #13186] DEBUG -- : Reading from queue: scores:/queue/scores'
16
+ ]
17
+ }
18
+
19
+ let(:file_dup) { File.expand_path('../support/log/snoop_log_3.test', __FILE__) }
20
+
21
+ before(:each) {
22
+ duplicate
23
+ }
24
+
25
+ after(:each) {
26
+ File.delete file_dup
27
+ }
28
+
29
+ def duplicate
30
+ File.copy_stream(file, file_dup)
31
+ end
32
+
33
+ context 'no database' do
34
+
35
+ before(:each) do
36
+ #Snoopit.logger.level = Logger::DEBUG
37
+ @ft = FileTracker.new nil
38
+ end
39
+
40
+ def read_init(file, data)
41
+ @ft.foreach file do |line, line_no |
42
+ data << line
43
+ end
44
+ end
45
+
46
+ it 'initially reads a new file' do
47
+ data = []
48
+ read_init file_dup, data
49
+ fi2 = @ft.get_file file_dup
50
+ expect(data.size).to be == fi2.line_no
51
+ end
52
+
53
+ it 'reads an appended file' do
54
+ data = []
55
+ read_init file_dup, data
56
+ fh = File.open file_dup, 'a'
57
+ append_data.each do |line|
58
+ fh.puts "#{line}"
59
+ end
60
+ fh.close
61
+ appended = []
62
+ @ft.foreach file_dup do |line, line_no|
63
+ appended << line
64
+ end
65
+ expect(appended.size).to be == append_data.size
66
+ (0...append_data.size).each do |i|
67
+ expect(append_data[i]).to be == appended[i].chop
68
+ end
69
+ end
70
+
71
+ it 'reads a new version of file file' do
72
+ data = []
73
+ read_init file_dup, data
74
+ old_size = @ft.get_file(file_dup).size
75
+ fh = File.open file_dup, 'w'
76
+ append_data.each do |line|
77
+ fh.puts "#{line}"
78
+ end
79
+ fh.close
80
+ new_data = []
81
+ @ft.foreach file_dup do |line, line_no|
82
+ new_data << line
83
+ end
84
+ expect(append_data.size).to be == new_data.size
85
+ expect(old_size).to_not be == new_data.size
86
+ (0...append_data.size).each do |i|
87
+ expect(append_data[i]).to be == new_data[i].chop
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ context 'with log database' do
94
+
95
+ before(:each) do
96
+ file_path = File.expand_path('../support/db/snoop_db.json', __FILE__)
97
+ Dir.mkdir './spec/support/db' unless Dir.exist? './spec/support/db'
98
+ #Snoopit.logger.level = Logger::DEBUG
99
+ @db_file = file_path
100
+ File.delete @db_file if File.exist? @db_file
101
+ @ft = FileTracker.new @db_file
102
+ end
103
+
104
+ def read_init(file, data)
105
+ @ft.foreach file do |line, line_no |
106
+ data << line
107
+ end
108
+ end
109
+
110
+ it 'initially reads a new file save to db validate db save and load' do
111
+ data = []
112
+ read_init file_dup, data
113
+ dup = @ft.get_file file_dup
114
+ expect(data.size).to be == dup.line_no
115
+ @ft2 = FileTracker.new @db_file
116
+ ft_json_read = @ft2.get_file file_dup
117
+ expect(ft_json_read.size).to be == dup.size
118
+ expect(ft_json_read.mtime.to_i).to be == dup.mtime.to_i
119
+ expect(ft_json_read.line_no).to be == dup.line_no
120
+ expect(ft_json_read.file).to be == dup.file
121
+ expect(ft_json_read.offset).to be == dup.offset
122
+ end
123
+
124
+ it 'read db ans sees appended file' do
125
+ data = []
126
+ read_init file_dup, data
127
+ dup = @ft.get_file file_dup
128
+ expect(data.size).to be == dup.line_no
129
+ fh = File.open file_dup, 'a'
130
+ append_data.each do |line|
131
+ fh.puts "#{line}"
132
+ end
133
+ fh.close
134
+ appended = []
135
+ @ft2 = FileTracker.new @db_file
136
+ @ft2.foreach file_dup do |line, line_no|
137
+ appended << line
138
+ end
139
+ expect(appended.size).to be == append_data.size
140
+ (0...append_data.size).each do |i|
141
+ expect(append_data[i]).to be == appended[i].chop
142
+ end
143
+ fi2 = @ft2.get_file file_dup
144
+ stat = File.stat file_dup
145
+ expect(fi2.size).to be == stat.size
146
+ expect(fi2.mtime).to be == stat.mtime
147
+ end
148
+
149
+ it 'reads db sees a new version of file' do
150
+ data = []
151
+ read_init file_dup, data
152
+ old_size = @ft.get_file(file_dup).size
153
+ fh = File.open file_dup, 'w'
154
+ append_data.each do |line|
155
+ fh.puts "#{line}"
156
+ end
157
+ fh.close
158
+ new_data = []
159
+ @ft2 = FileTracker.new @db_file
160
+ @ft2.foreach file_dup do |line, line_no|
161
+ new_data << line
162
+ end
163
+ expect(append_data.size).to be == new_data.size
164
+ expect(old_size).to_not be == new_data.size
165
+ (0...append_data.size).each do |i|
166
+ expect(append_data[i]).to be == new_data[i].chop
167
+ end
168
+ end
169
+
170
+ end
171
+
172
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Notification Manager' do
4
+
5
+ before(:each) do
6
+ @file = File.expand_path('../support/snoopies.json', __FILE__)
7
+ @json = IO.read(@file)
8
+ @json_hash = JSON.parse(@json)
9
+ end
10
+
11
+ context 'Config' do
12
+
13
+ def config_check(nm)
14
+ nm.config.should include 'email'
15
+ nm.config['email'].should include 'smtp-server'
16
+ nm.config['email'].should include 'port'
17
+ end
18
+
19
+ it 'load valid config on new' do
20
+ nm = NotificationManager.new @json_hash['notifiers']
21
+ config_check nm
22
+ end
23
+
24
+ it 'load valid config' do
25
+ nm = NotificationManager.new
26
+ nm.load_notifier_config @json_hash['notifiers']
27
+ config_check nm
28
+ end
29
+
30
+ it 'loads email notifier' do
31
+ nm = NotificationManager.new
32
+ nm.load_notifier_config @json_hash['notifiers']
33
+ nm.active.should include 'email'
34
+ email = nm.active['email']
35
+ email.smtp_server.should eq 'smtp.gmail.com'
36
+ email.port.should eq 587
37
+ end
38
+
39
+ end
40
+
41
+ context 'Notifiers' do
42
+
43
+ before(:each) do
44
+ @nm = NotificationManager.new
45
+ @nm.load_notifier_config @json_hash['notifiers']
46
+ @snooper = Snooper.new false
47
+ @snooper.load_file File.expand_path('../support/snoopies.json', __FILE__)
48
+ @tn = TestNotifier.new
49
+ @nm.register @tn
50
+ end
51
+
52
+ it 'unregister notifier' do
53
+ n = @nm.unregister @tn
54
+ expect(n).to eq @tn
55
+ nn = @nm.get_notifier @tn.name
56
+ expect(nn).to be nil
57
+ nnn = @nm.unregister @tn
58
+ expect(nnn).to be nil
59
+ end
60
+
61
+ it 'get notifier' do
62
+ n = @nm.get_notifier @tn.name
63
+ expect(n).to eq @tn
64
+ end
65
+
66
+ it 'receives messages' do
67
+ #Snoopit.logger.level = ::Logger::DEBUG
68
+ snoopies = @snooper.snoop
69
+ @nm.notify snoopies
70
+ expect(@tn.config).to eq nil
71
+ expect(@tn.params['param1']).to eq 'value1'
72
+ expect(@tn.params['param2']).to eq 'value2'
73
+ expect(@tn.found.size).to eq 122
74
+ end
75
+
76
+ end
77
+
78
+ context 'Config load Notifiers' do
79
+
80
+ before(:each) do
81
+ #Snoopit.logger.level = ::Logger::DEBUG
82
+ @nm = NotificationManager.new
83
+ @nm.load_notifier_config @json_hash['notifiers']
84
+ @snooper = Snooper.new false
85
+ @notifier_name ='Test Notifier Load'
86
+ @snooper.load_snoopers @json_hash
87
+ end
88
+
89
+ it 'load notifier from snoopies.json config load section' do
90
+ expect(@nm.active).to include @notifier_name
91
+ snoopies = @snooper.snoop
92
+ @nm.notify snoopies
93
+ tnl = @nm.get_notifier @notifier_name
94
+ expect(tnl.config['c_param1']).to eq 'value1'
95
+ expect(tnl.config['c_param2']).to eq 'value2'
96
+ expect(tnl.params['param1']).to eq 'value1'
97
+ expect(tnl.params['param2']).to eq 'value2'
98
+ expect(tnl.found.size).to eq 94
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Email 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
+ @json_hash['notifiers'].delete 'http'
10
+ @json_hash['notifiers'].delete 'https'
11
+ @json_hash['notifiers'].delete 'stomp'
12
+ @snooper = Snooper.new false
13
+ @nm = NotificationManager.new
14
+ @snooper.load_snoopers @json_hash
15
+ @nm.load_notifier_config @json_hash['notifiers']
16
+ @nm.unregister_by_name 'http'
17
+ end
18
+
19
+ it 'email stub' do
20
+ emn = @nm.get_notifier 'email'
21
+ expect(emn.name).to eq 'email'
22
+ snoopies = @snooper.snoop
23
+ e = @nm.get_notifier 'email'
24
+ e.stub(:notify)
25
+ @nm.notify(snoopies)
26
+ end
27
+
28
+ it 'email', :skip do
29
+ emn = @nm.get_notifier 'email'
30
+ expect(emn.name).to eq 'email'
31
+ snoopies = @snooper.snoop
32
+ @nm.notify(snoopies)
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'HTTP 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
+ @json_hash['notifiers'].delete 'stomp'
10
+ @json_hash['notifiers'].delete 'https'
11
+ @json_hash['notifiers'].delete 'email'
12
+ @snooper = Snooper.new false
13
+ @nm = NotificationManager.new
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 'http stub notify' do
20
+ http = @nm.get_notifier 'http'
21
+ expect(http.name).to eq 'http'
22
+ snoopies = @snooper.snoop
23
+ h = @nm.get_notifier 'http'
24
+ n = h.stub(:notify)
25
+ @nm.notify(snoopies)
26
+ end
27
+
28
+ it 'http notify', :skip do
29
+ http = @nm.get_notifier 'http'
30
+ expect(http.name).to eq 'http'
31
+ snoopies = @snooper.snoop
32
+ @nm.notify(snoopies)
33
+ end
34
+
35
+
36
+
37
+ end