onesnooper-server 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01f1ae82991565bbc54d357c7f56a52e01d6a493
4
- data.tar.gz: 9b0a7f57c37cc1e27070ac5c8d9c1f831fa05a67
3
+ metadata.gz: 3f95a623aeecca71c8a9cdeef948e88d977b9d6c
4
+ data.tar.gz: 7e1eda07d750ed7248570031d76549a3c3e838d0
5
5
  SHA512:
6
- metadata.gz: 01dfada0d5bde06a121d869f7c6de9ecca3c064b784479639a50601111f396b9f85d55a9c883aa0e7782def249f949bd681ce18ea8f041c16681bb1a06ddc0e1
7
- data.tar.gz: 0ca39c08ef780ea2a472d74754ec7ba6dc73c4568a5dd8c81010eeb5d622aa6b44a67c6db86cf941e8075a7e8b827e41d949122a4e8de19c53b88413e6ee8a30
6
+ metadata.gz: 33e7705f7f0f5faca48b3393ff4306d3883cbab53bee8bacca735fc5d83adf1a012ffc1a97ad0d98640b47b2a846f669207485a28e5e5bde0988124f995e2535
7
+ data.tar.gz: 07569b715d3baabc873c442bc618edb93c09ac4b67c362667cd373e0ef466d01e1180bda12f5a1e8707292d6108856b42bd679ebe7a6bee247906e3c30cadfc7
@@ -15,14 +15,6 @@ class OnesnooperServer::RequestHandler
15
15
  }
16
16
  DATAGRAMS.default = ::OnesnooperServer::Datagrams::InvalidDatagram
17
17
 
18
- # Registered allowed stores for monitoring data
19
- STORES = {
20
- "mongodb" => ::OnesnooperServer::Stores::MongodbStore,
21
- "mysql" => ::OnesnooperServer::Stores::MysqlStore,
22
- "sqlite" => ::OnesnooperServer::Stores::SqliteStore,
23
- }
24
- STORES.default = ::OnesnooperServer::Stores::InvalidStore
25
-
26
18
  # Static parsing method for identifying types of incoming datagrams
27
19
  # and choosing the right processing class for each datagram. Always
28
20
  # returns an instance responding to `run(callback)`.
@@ -30,7 +22,8 @@ class OnesnooperServer::RequestHandler
30
22
  # @param monitoring_datagram [Object] datagram payload for processing
31
23
  # @param source_ip [String] IP address of the client
32
24
  # @param source_port [String] port number of the client
33
- def self.parse(monitoring_datagram, source_ip, source_port)
25
+ # @param store_instances [Array] array of pre-initialized store instances
26
+ def self.parse(monitoring_datagram, source_ip, source_port, store_instances)
34
27
  unless valid_data?(monitoring_datagram)
35
28
  ::OnesnooperServer::Log.error "[#{self.name}] Dropping invalid monitoring data #{monitoring_datagram.inspect}"
36
29
  return DATAGRAMS.default.new
@@ -85,15 +78,4 @@ private
85
78
  false
86
79
  end
87
80
 
88
- # Retrieves a list of instances for allowed store backends.
89
- #
90
- # @return [Array] list of store instances
91
- def self.store_instances
92
- ::OnesnooperServer::Settings.store.collect do |store_name|
93
- STORES[store_name].new(
94
- ::OnesnooperServer::Settings.stores.respond_to?(store_name) ? ::OnesnooperServer::Settings.stores.send(store_name) : {}
95
- )
96
- end
97
- end
98
-
99
81
  end
@@ -4,8 +4,25 @@
4
4
  # mirrored monitoring traffic.
5
5
  class OnesnooperServer::UDPHandler < ::EventMachine::Connection
6
6
 
7
+ # Allowed datagram prefix
7
8
  DATAGRAM_PREFIX = 'MONITOR'
8
9
 
10
+ # Registered allowed stores for monitoring data
11
+ STORES = {
12
+ "mongodb" => ::OnesnooperServer::Stores::MongodbStore,
13
+ "mysql" => ::OnesnooperServer::Stores::MysqlStore,
14
+ "sqlite" => ::OnesnooperServer::Stores::SqliteStore,
15
+ }
16
+ STORES.default = ::OnesnooperServer::Stores::InvalidStore
17
+
18
+ def initialize(*args)
19
+ super
20
+ @store_instances = store_instances(
21
+ ::OnesnooperServer::Settings.store,
22
+ ::OnesnooperServer::Settings.stores
23
+ )
24
+ end
25
+
9
26
  # Receives data and triggers processing of the given
10
27
  # datagram. Main internal processing triggered from this
11
28
  # method should always happen asynchronously (i.e., using
@@ -26,7 +43,8 @@ class OnesnooperServer::UDPHandler < ::EventMachine::Connection
26
43
  ::OnesnooperServer::RequestHandler.parse(
27
44
  monitoring_datagram,
28
45
  source_ip,
29
- source_port
46
+ source_port,
47
+ @store_instances
30
48
  ).run(callback)
31
49
  end
32
50
 
@@ -47,4 +65,20 @@ private
47
65
  def_deferr
48
66
  end
49
67
 
68
+ # Retrieves a list of instances for allowed store backends.
69
+ #
70
+ # @param enabled_stores [Hash] hash-like list of enabled stores
71
+ # @param store_configs [Hash] hash-like set of store configurations
72
+ # @return [Array] list of store instances
73
+ def store_instances(enabled_stores, store_configs)
74
+ fail "No stores have been enabled, see configuration file" if enabled_stores.blank?
75
+ fail "No store configuration present, see configuration file" if store_configs.blank?
76
+
77
+ enabled_stores.collect do |store_name|
78
+ STORES[store_name].new(
79
+ store_configs.respond_to?(store_name) ? store_configs.send(store_name) : {}
80
+ )
81
+ end
82
+ end
83
+
50
84
  end
@@ -1,4 +1,4 @@
1
1
  module OnesnooperServer
2
2
  # Static version information
3
- VERSION = "0.0.3" unless defined?(::OnesnooperServer::VERSION)
3
+ VERSION = "0.0.4" unless defined?(::OnesnooperServer::VERSION)
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onesnooper-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler