i2x 0.0.5 → 0.0.6

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: 5ae96c687e670ea870c7ee230796a996d6948450
4
- data.tar.gz: cf2653409419ae955fb4b3b5f5c04a18011c28a2
3
+ metadata.gz: 26fd09f69c0d5d4b13e61b03967aa14cab2a8e6c
4
+ data.tar.gz: 4815f6636f51e5e36a4e12fcd65b7a5c5b6a753d
5
5
  SHA512:
6
- metadata.gz: 25fcfd7a5936da1ae93be656b7855409f119e550d5cce7c60dd631b6ba001007d85b092bcd5808bf9c5df856ee2e0fa1f6aee1105f9d2320c20a77fe770565e6
7
- data.tar.gz: 3d8f44e8e692b2ede996ed044c1c2f7110cbc817e6a03369fae9b2592dd98782aa2b3cd30791627b43ff89d648ccbe4a9b8e8484e202711ff0dc1ce98e24c588
6
+ metadata.gz: a498ad01e5da2665f87369cbb4ca689d45cc860cee12d6556eb283f91eb93de62ab098c9f55da2a82e77045fafcf46b78c88fc16e6deea18ce6a1d0af7a0c6dd
7
+ data.tar.gz: da7c085b0b8fb25b64193d43203b399374ed3af04ea507bdac75c22c1e9c22d1fed4e18b7c8684d81b1ad2caeb7c121733e6820e249fe82de15a4c507ca1b767
data/lib/i2x.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require 'i2x/cashier'
2
3
  require 'i2x/helper'
3
4
  require 'i2x/detector'
@@ -12,6 +13,10 @@ require 'i2x/client'
12
13
  module I2X
13
14
  class Config
14
15
 
16
+ def self.set_log log
17
+ @@log = log
18
+ end
19
+
15
20
  def self.set_host host
16
21
  host << '/' unless host.end_with?('/')
17
22
  @@host = host
@@ -21,6 +26,10 @@ module I2X
21
26
  @@access_token = api_key
22
27
  end
23
28
 
29
+ def self.log
30
+ @@log
31
+ end
32
+
24
33
  def self.host
25
34
  @@host
26
35
  end
data/lib/i2x/agent.rb CHANGED
@@ -1,8 +1,4 @@
1
- #require 'detector'
2
- #require 'csvdetector'
3
- #require 'jsondetector'
4
- #require 'xmldetector'
5
- #require 'sqldetector'
1
+ require 'rest_client'
6
2
 
7
3
  module I2X
8
4
  class Agent
@@ -49,7 +45,7 @@ module I2X
49
45
  @d = I2X::XMLDetector.new(self)
50
46
  rescue Exception => e
51
47
  @response = {:status => 400, :error => e}
52
- p "[i2x] error: #{e}"
48
+ p "[i2x] error: #{e}"
53
49
  end
54
50
  when 'json'
55
51
  begin
@@ -76,6 +72,8 @@ module I2X
76
72
  @d.objects.each do |object|
77
73
  @d.detect object
78
74
  end
75
+
76
+ @checkup[:templates] = @d.templates.uniq
79
77
  rescue Exception => e
80
78
  p "[i2x] error: #{e}"
81
79
  end
@@ -96,7 +94,24 @@ module I2X
96
94
  # => Process agent checks.
97
95
  #
98
96
  def process checkup
99
- p checkup
97
+ begin
98
+ checkup[:templates].each do |template|
99
+ p "[i2x][Agent] Processing #{template}"
100
+ checkup[:payload].each do |payload|
101
+ puts "\t[i2x][Agent] Processing #{payload}"
102
+ response = RestClient.post "#{I2X::Config.host}postman/deliver/#{template}.js", payload
103
+ case response.code
104
+ when 200
105
+
106
+ else
107
+ puts "[i2x][Agent] unable to deliver \"#{payload}\" to \"#{template}\""
108
+ end
109
+ end
110
+ end
111
+ rescue Exception => e
112
+ p "[i2x][Agent] error: #{e}"
113
+ end
114
+
100
115
  end
101
116
  end
102
117
 
data/lib/i2x/cashier.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  require 'rest_client'
2
- require 'open-uri'
3
-
4
2
 
5
3
  module I2X
6
4
  class Cashier
7
-
8
-
9
5
  public
10
6
 
11
7
  ##
@@ -23,9 +19,8 @@ module I2X
23
19
  begin
24
20
  response = RestClient.post "#{I2X::Config.host}fluxcapacitor/verify.json", {:access_token => I2X::Config.access_token, :agent => agent[:identifier], :cache => cache, :payload => payload, :seed => seed}
25
21
  rescue Exception => e
26
- response = {:status => 400}
22
+ response = {:status => 400, :error => e}
27
23
  end
28
- p response
29
24
  response
30
25
  end
31
26
  end
data/lib/i2x/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rest_client'
2
+ require 'logger'
2
3
 
3
4
  module I2X
4
5
  class Client
@@ -6,14 +7,16 @@ module I2X
6
7
  ##
7
8
  # => Load configuration properties from client/script code
8
9
  #
9
- def initialize config
10
+ def initialize config, log
10
11
  begin
11
12
  @config = config
12
- I2X::Config.set_access_token @config[:server][:api_key]
13
- I2X::Config.set_host @config[:server][:host]
14
- p '[i2x] loaded configuration'
13
+ I2X::Config.set_access_token config[:server][:api_key]
14
+ I2X::Config.set_host config[:server][:host]
15
+ I2X::Config.set_log log
16
+
17
+ I2X::Config.log.info(self.class.name) {'Configuration loaded successfully.'}
15
18
  rescue Exception => e
16
- puts "[i2x] Failed to load configuration: #{e}"
19
+ I2X::Config.log.error(self.class.name) {"Failed to load configuration: #{e}"}
17
20
  end
18
21
 
19
22
  end
@@ -23,11 +26,12 @@ module I2X
23
26
  #
24
27
  def validate
25
28
  begin
26
- p '[i2x] launching validation.'
29
+ I2X::Config.log.info(self.class.name) {'Launching validation.'}
30
+
27
31
  out = RestClient.post "#{I2X::Config.host}fluxcapacitor/validate_key.json", {:access_token => I2X::Config.access_token}
28
32
  response = {:status => 100, :response => out.to_str}
29
33
  rescue Exception => e
30
- p "[i2x] Failed validation: #{e}"
34
+ I2X::Config.log.error(self.class.name) {"Failed validation: #{e}"}
31
35
  end
32
36
  response
33
37
  end
@@ -36,13 +40,14 @@ module I2X
36
40
  # => Start processing agents from configuration properties.
37
41
  #
38
42
  def process
43
+ I2X::Config.log.info(self.class.name) {'Starting agent processing.'}
39
44
  begin
40
45
  @config[:agents].each do |agent|
41
46
  a = I2X::Agent.new agent
42
47
  a.execute
43
48
  end
44
- rescue Exception => e
45
- p "[i2x] Failed agent processing: #{e}"
49
+ rescue Exception => e
50
+ I2X::Config.log.error(self.class.name) {"Failed agent processing: #{e}"}
46
51
  end
47
52
  end
48
53
  end
@@ -35,7 +35,9 @@ module I2X
35
35
  begin
36
36
 
37
37
  @cache = JSON.parse(@response, {:symbolize_names => true})
38
- @templates = @cache[:templates]
38
+ @cache[:templates].each do |t|
39
+ @templates.push t
40
+ end
39
41
  # The actual processing
40
42
  #
41
43
  if @cache[:cache][:status] == 100 then
@@ -55,6 +57,7 @@ module I2X
55
57
  rescue Exception => e
56
58
  p "[i2x][CSVDetector] processing error: #{e.inspect}"
57
59
  end
60
+ @cache[:templates]
58
61
  end
59
62
  end
60
63
  end
data/lib/i2x/detector.rb CHANGED
@@ -21,10 +21,9 @@ module I2X
21
21
  @payloads = Array.new
22
22
  @objects = Array.new
23
23
  @help = I2X::Helper.new
24
- @templates = {}
25
24
  puts "Loaded new detector: #{agent.identifier}"
26
25
  rescue Exception => e
27
-
26
+ p "[i2x] error: #{e}"
28
27
  end
29
28
  end
30
29
 
@@ -47,25 +46,25 @@ module I2X
47
46
  begin
48
47
  @sr = I2X::CSVSeedReader.new(@agent, seed)
49
48
  rescue Exception => e
50
-
49
+ p "[i2x] error: #{e}"
51
50
  end
52
51
  when 'sql'
53
52
  begin
54
53
  @sr = I2X::SQLSeedReader.new(@agent, seed)
55
54
  rescue Exception => e
56
-
55
+ p "[i2x] error: #{e}"
57
56
  end
58
57
  when 'xml'
59
58
  begin
60
59
  @sr = I2X::XMLSeedReader.new(@agent, seed)
61
60
  rescue Exception => e
62
-
61
+ p "[i2x] error: #{e}"
63
62
  end
64
63
  when 'json'
65
64
  begin
66
65
  @sr = I2X::JSONSeedReader.new(@agent, seed)
67
66
  rescue Exception => e
68
-
67
+ p "[i2x] error: #{e}"
69
68
  end
70
69
  end
71
70
  begin
@@ -87,7 +86,7 @@ module I2X
87
86
  object[:seed] = object[:identifier]
88
87
  object[:selectors] = @agent.selectors
89
88
  p "\n\tSelectors: #{object[:selectors]}"
90
- unless self.content.nil? then
89
+ unless self.content.nil? then
91
90
  object[:content] = self.content
92
91
  end
93
92
  @objects.push object
@@ -99,7 +98,9 @@ module I2X
99
98
 
100
99
  begin
101
100
  # increase detected events count
102
-
101
+
102
+
103
+ @templates = Array.new
103
104
  @response = { :payload => @payloads, :templates => @templates, :status => 100}
104
105
  rescue Exception => e
105
106
  @response = {:status => 404, :message => "[i2x][Detector] failed to process queries, #{e}"}
data/lib/i2x/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module I2X
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i2x
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Lopes