Module: InternetBoxLogger::Parsers::FreeboxV5Parser
- Includes:
- Utils
- Defined in:
- lib/internet_box_logger/parsers/freebox_v5_parser.rb
Constant Summary
collapse
- DEFAULT_STATUS_URL =
'http://mafreebox.free.fr/pub/fbx_info.txt'
- EXPECTED_LINES =
[
/version du firmware\s+(?<firmware_version>[\d\.]+)\s*$/i ,
/mode de connection\s+(?<connection_mode>[[:alpha:]]+)\s*$/i ,
/temps depuis la mise en route\s+(?<up_time>.*)$/i ,
/etat\s+(?<phone_status>[[:alpha:]]+)\s*$/i ,
/etat du combiné\s+(?<phone_hanged_up>[[:alpha:]]+)\s*$/i ,
/sonnerie\s+(?<phone_ringing>[[:alpha:]]+)\s*$/i ,
/etat\s+(?<adsl_status>[[:alpha:]]+)\s*$/i ,
/protocole\s+(?<adsl_protocol>[^\s]+)\s*$/i ,
/mode\s+(?<adsl_mode>[[:alpha:]]+)\s*$/i ,
/débit atm\s+(?<adsl_atm_bandwidth_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_atm_bandwidth_up>[\d\.]+\s+[^\s]+)\s*$/i ,
/marge de bruit\s+(?<adsl_noise_margin_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_noise_margin_up>[\d\.]+\s+[^\s]+)\s*$/i ,
/atténuation\s+(?<adsl_attenuation_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_attenuation_up>[\d\.]+\s+[^\s]+)\s*$/i ,
/fec\s+(?<adsl_fec_down>\d+)\s+(?<adsl_fec_up>\d+)\s*$/i ,
/crc\s+(?<adsl_crc_down>\d+)\s+(?<adsl_crc_up>\d+)\s*$/i ,
/hec\s+(?<adsl_hec_down>\d+)\s+(?<adsl_hec_up>\d+)\s*$/i ,
/etat\s+wifi\s+(?<wifi_state>[[:alpha:]]+)\s*$/i ,
/canal\s+(?<wifi_chanel>[\d]+)\s*$/i ,
/tat du r[eé]seau\s+(?<wifi_network_state>[[:alpha:]]+)\s*$/i ,
/freewifi\s+(?<wifi_freewifi_state>[[:alpha:]]+)\s*$/i ,
/freewifi secure\s+(?<wifi_freewifi_secure_state>[[:alpha:]]+)\s*$/i ,
/adresse mac freebox\s+(?<network_mac>[\dabcdefABCDEF:]+)\s*$/i ,
/\s+(?<network_public_ipv4>[\d\.]+)\s*$/i ,
/mode routeur\s+(?<network_router>[[:alpha:]]+)\s*$/i ,
/adresse ip privée\s+(?<network_private_ipv4>[\d\.]+)\s*$/i ,
/adresse ip dmz\s+(?<network_dmz_ipv4>[\d\.]+)\s*$/i ,
/adresse ip freeplayer\s+(?<network_freeplayer_ipv4>[\d\.]+)\s*$/i ,
/réponse au ping\s+(?<network_answer_to_ping>[[:alpha:]]+)\s*$/i ,
/proxy wake on lan\s+(?<network_wake_on_lan>[[:alpha:]]+)\s*$/i ,
/serveur dhcp\s+(?<network_dhcp>[[:alpha:]]+)\s*$/i ,
/plage d'adresses dynamiques?\s+(?<network_dhcp_range>[\d\.\s-]+[^\s])\s*$/i ,
]
- FIELD_POST_PROCESSING =
{
up_time: :to_duration,
phone_status: :to_bool,
phone_hanged_up: :to_bool,
phone_ringing: :to_bool,
wifi_chanel: :to_int,
wifi_state: :to_bool,
wifi_network_state: :to_bool,
wifi_freewifi_state: :to_bool,
wifi_freewifi_secure_state: :to_bool,
network_answer_to_ping: :to_bool,
network_wake_on_lan: :to_bool,
network_dhcp: :to_bool,
network_router: :to_bool,
adsl_atm_bandwidth_up: :to_bandwidth,
adsl_atm_bandwidth_down: :to_bandwidth,
adsl_noise_margin_up: :to_db,
adsl_noise_margin_down: :to_db,
adsl_attenuation_up: :to_db,
adsl_attenuation_down: :to_db,
adsl_crc_up: :to_num,
adsl_crc_down: :to_num,
adsl_fec_up: :to_num,
adsl_fec_down: :to_num,
adsl_hec_up: :to_num,
adsl_hec_down: :to_num,
}
- UP_DOWN_REPORTS =
{
adsl_noise_margin: 'Noise Margin',
adsl_atm_bandwidth: 'ATM Bandwidth',
adsl_attenuation: 'Attenuation',
adsl_crc: 'CRC',
adsl_fec: 'FEC',
adsl_hec: 'HEC'
}
Constants included
from Utils
Utils::CONSIDERED_FALSE, Utils::CONSIDERED_TRUE
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#to_bandwidth, #to_bool, #to_db, #to_duration, #to_int, #to_num
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
81
82
83
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 81
def attributes
@attributes
end
|
#raw_data ⇒ Object
Returns the value of attribute raw_data.
81
82
83
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 81
def raw_data
@raw_data
end
|
Instance Method Details
#as_es_documents(created_at = Time.now) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 124
def as_es_documents(created_at=Time.now)
res = []
self.up_down_reports.each_pair do |measurement, name|
%w(up down).each do |measurement_type|
data_name = "#{measurement}_#{measurement_type}"
es_object = {
index: "#{self.class.name.underscore.tr('/', '_')}_#{measurement}",
type: measurement_type
}
data = {
created_at: created_at,
name: data_name,
description: name,
value: attributes[data_name.to_sym]
}
es_object[:body] = data
res << es_object
end
end
generic_info = {}
attributes.each do |attr_name, content|
data_key = attr_name.to_s.gsub(/_(up|down)$/, '').to_sym
next if attr_name.length > 3 && self.up_down_reports.keys.include?(data_key)
generic_info[attr_name] = content
end
generic_info[:name] = 'generic'
generic_info[:created_at] = created_at
res << {
index: "#{self.class.name.underscore.tr('/', '_')}_generic",
type: :info.to_s,
body: generic_info
}
res
end
|
#get_box_data ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 91
def get_box_data
regexp_list = EXPECTED_LINES.dup
current_regexp = nil
@raw_data, @attributes = [], {}
skip_parsing = false
open(get_status_url).readlines.each do |line|
@raw_data << line
next if skip_parsing
begin
current_regexp = regexp_list.shift if current_regexp.nil?
rescue
EasyAppHelper.logger.info 'Got all data. Do not parse the rest of the data.'
skip_parsing = true
end
break if current_regexp.nil?
line.encode('utf-8').match current_regexp do |md|
md.names.each do |field|
EasyAppHelper.logger.info "#{field} => #{md[field]}"
@attributes[field.to_sym] = normalize_value(field.to_sym, md)
current_regexp = nil
end
end
end
regexp_list.empty? ? self : nil
end
|
#get_status_url ⇒ Object
83
84
85
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 83
def get_status_url
EasyAppHelper.config[:freebox_alternate_url] ? EasyAppHelper.config[:freebox_alternate_url] : DEFAULT_STATUS_URL
end
|
#normalize_value(field_name, match_data) ⇒ Object
119
120
121
122
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 119
def normalize_value(field_name, match_data)
return match_data[field_name] unless FIELD_POST_PROCESSING[field_name]
self.send FIELD_POST_PROCESSING[field_name], field_name, match_data[field_name]
end
|
#up_down_reports ⇒ Object
87
88
89
|
# File 'lib/internet_box_logger/parsers/freebox_v5_parser.rb', line 87
def up_down_reports
UP_DOWN_REPORTS
end
|