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 +4 -4
- data/lib/internet_box_logger/elastic_search.rb +13 -22
- data/lib/internet_box_logger/generic_box.rb +6 -5
- data/lib/internet_box_logger/parsers/freebox_v5_parser.rb +0 -39
- data/lib/internet_box_logger/version.rb +1 -1
- data/spec/elastic_search_spec.rb +7 -0
- data/spec/parsers_spec.rb +25 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b44b7b9c4985e89a6936e0a2ef501325e03cd59
|
4
|
+
data.tar.gz: e94ade0de0cc57f260d765257d5ce1fa9b85d374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
9
|
-
box_type =
|
10
|
-
|
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
|
data/spec/elastic_search_spec.rb
CHANGED
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
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|