internet_box_logger 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f69484736a27ed6581b71b29430e0076a8d4763
4
- data.tar.gz: 0b12a37fc30bea8aecf8b07e407db37804cc03c4
3
+ metadata.gz: 5b44b7b9c4985e89a6936e0a2ef501325e03cd59
4
+ data.tar.gz: e94ade0de0cc57f260d765257d5ce1fa9b85d374
5
5
  SHA512:
6
- metadata.gz: 1f35b1d29f2cf65cf1372603bb00736eca23f55435ecf3f966eca8d0db52f0e28132a1d39345e6bd516d2db02afb093c165853e1b7454ac34b880ab8dc04c18c
7
- data.tar.gz: f5731a0172a32eb356e6342f681d3b2376c1a40d0b63ee0e9f19ba8e9ac518d8d4c19c9c86379c2eef45b16e93105b6473af09e922863095f991a9b5f79ce529
6
+ metadata.gz: 3d1a3ee9fe32fcaf1cf8bc8e89857d42ceef3956b170ef9480b2a031cc0af4d799b55f22b94c35bc2df450da6b9edb0b39b5137215525217580123dc7a76d13d
7
+ data.tar.gz: b40b5c66bf3d14a13949aa60be00b3ec51051c02a877ed1b991e7188204537d3d2dde18f76568ef53daba6c989aaa57cbecc19de1c6ad5562c13da9a4265732c
@@ -20,13 +20,6 @@ module InternetBoxLogger
20
20
  end
21
21
 
22
22
  def self.remote?
23
- # res = true
24
- # return nil if Server[].nil? || Server.empty?
25
- # Server[].each do |addr|
26
- # if
27
- #
28
- # end
29
- # end
30
23
  local_path.nil?
31
24
  end
32
25
 
@@ -40,21 +33,19 @@ module InternetBoxLogger
40
33
  end
41
34
 
42
35
  def save
43
- internal_representation = []
44
- EasyAppHelper.logger.debug 'Saving measurements to ElasticSearch'
45
- self.as_es_documents.each do |document|
46
- begin
47
- EasyAppHelper.logger.debug " - #{document[:body][:name]}"
48
- internal_representation << elasticsearch_client.index(**document)
49
- rescue => e
50
- EasyAppHelper.logger.error e.message
51
- end
52
- end
53
- @internal_es_representation = internal_representation
54
- EasyAppHelper.puts_and_logs 'Your box metrics have been indexed into Elastic Search'
55
- self
56
- rescue
57
- EasyAppHelper.logger.error 'Unable to save to ElasticSearch !!'
36
+ measured_at = Time.now
37
+ index_day = sprintf '%04d%02d%02d', measured_at.year, measured_at.month, measured_at.mday
38
+
39
+ data = self.attributes.dup
40
+ data[:measured_at] = measured_at
41
+
42
+ es_document = {
43
+ index: "box_metrics-#{index_day}",
44
+ type: box_type,
45
+ body: data
46
+ }
47
+
48
+ elasticsearch_client.index es_document
58
49
  end
59
50
 
60
51
  end
@@ -4,10 +4,13 @@ module InternetBoxLogger
4
4
 
5
5
  include InternetBoxLogger::ElasticSearch
6
6
 
7
+ attr_reader :box_type
8
+
7
9
  def initialize(box_type)
8
- box_type = box_type.to_s if box_type.is_a? Symbol
9
- box_type = self.class.const_get box_type if box_type.is_a? String
10
- box_parser_module = box_type if InternetBoxLogger::Parsers[].include? box_type
10
+ @box_type = box_type
11
+ @box_type = @box_type.to_s if @box_type.is_a? Symbol
12
+ @box_type = self.class.const_get @box_type if @box_type.is_a? String
13
+ box_parser_module = @box_type if InternetBoxLogger::Parsers[].include? @box_type
11
14
  self.extend box_parser_module
12
15
  end
13
16
 
@@ -15,7 +18,5 @@ module InternetBoxLogger
15
18
  save if get_box_data
16
19
  end
17
20
 
18
-
19
-
20
21
  end
21
22
  end
@@ -121,45 +121,6 @@ module InternetBoxLogger
121
121
  self.send FIELD_POST_PROCESSING[field_name], field_name, match_data[field_name]
122
122
  end
123
123
 
124
- def as_es_documents(created_at=Time.now)
125
- res = []
126
- self.up_down_reports.each_pair do |measurement, name|
127
- %w(up down).each do |measurement_type|
128
- data_name = "#{measurement}_#{measurement_type}"
129
- es_object = {
130
- index: "#{self.class.name.underscore.tr('/', '_')}_#{measurement}",
131
- type: measurement_type
132
- }
133
- data = {
134
- created_at: created_at,
135
- name: data_name,
136
- description: name,
137
- value: attributes[data_name.to_sym]
138
- }
139
- es_object[:body] = data
140
- res << es_object
141
- end
142
- end
143
- generic_info = {}
144
-
145
- attributes.each do |attr_name, content|
146
- # Tries to remove data that are up/down measurements already covered by previous collection
147
- data_key = attr_name.to_s.gsub(/_(up|down)$/, '').to_sym
148
- next if attr_name.length > 3 && self.up_down_reports.keys.include?(data_key)
149
- # Else adds info to generic info
150
- generic_info[attr_name] = content
151
- end
152
- generic_info[:name] = 'generic'
153
- generic_info[:created_at] = created_at
154
-
155
- res << {
156
- index: "#{self.class.name.underscore.tr('/', '_')}_generic",
157
- type: :info.to_s,
158
- body: generic_info
159
- }
160
-
161
- res
162
- end
163
124
 
164
125
  end
165
126
  end
@@ -1,3 +1,3 @@
1
1
  module InternetBoxLogger
2
- VERSION = '0.2.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -2,5 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe InternetBoxLogger::ElasticSearch do
4
4
 
5
+ subject {InternetBoxLogger::GenericBox.new InternetBoxLogger::Parsers::FreeboxV5Parser}
6
+
7
+ it 'should be able to save it' do
8
+ subject.get_box_data
9
+ subject.save
10
+ end
11
+
5
12
 
6
13
  end
data/spec/parsers_spec.rb CHANGED
@@ -31,31 +31,32 @@ describe InternetBoxLogger::Parsers do
31
31
  expect(subject.get_box_data).not_to be_nil
32
32
  end
33
33
 
34
- it 'should export data as an array' do
35
- subject.get_box_data
36
- expect(subject.as_es_documents is_a? Array).to be_truthy
37
- end
38
34
 
39
- it 'should have many up/down documents and one info' do
40
- subject.get_box_data
41
- docs = subject.as_es_documents
42
- up, down, info, unknown = 0, 0, 0, 0
43
- docs.each do |doc|
44
- case doc[:type]
45
- when 'up'
46
- up += 1
47
- when 'down'
48
- down += 1
49
- when 'info'
50
- info += 1
51
- else
52
- unknown += 1
53
- end
54
- end
55
- expect(up == down).to be_truthy
56
- expect(info == 1).to be_truthy
57
- expect(unknown == 0).to be_truthy
58
- end
35
+ # it 'should export data as an array' do
36
+ # subject.get_box_data
37
+ # expect(subject.as_es_documents is_a? Array).to be_truthy
38
+ # end
39
+
40
+ # it 'should have many up/down documents and one info' do
41
+ # subject.get_box_data
42
+ # docs = subject.as_es_documents
43
+ # up, down, info, unknown = 0, 0, 0, 0
44
+ # docs.each do |doc|
45
+ # case doc[:type]
46
+ # when 'up'
47
+ # up += 1
48
+ # when 'down'
49
+ # down += 1
50
+ # when 'info'
51
+ # info += 1
52
+ # else
53
+ # unknown += 1
54
+ # end
55
+ # end
56
+ # expect(up == down).to be_truthy
57
+ # expect(info == 1).to be_truthy
58
+ # expect(unknown == 0).to be_truthy
59
+ # end
59
60
 
60
61
 
61
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internet_box_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent B