Module: PatronusFati::MessageProcessor
Defined Under Namespace
Modules: Alert, Bssid, Capability, Client, Critfail, Error, Protocols, Ssid, Terminate
Class Method Summary
collapse
class_to_name, factory, ignored_types, included, registered_factories
Class Method Details
.cleanup_models ⇒ void
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/patronus_fati/message_processor.rb', line 5
def self.cleanup_models
@next_cleanup ||= Time.now.to_i + 60
if @next_cleanup <= Time.now.to_i
@next_cleanup = Time.now.to_i + 60
close_inactive_connections
offline_access_points
offline_clients
end
end
|
.close_inactive_connections ⇒ void
18
19
20
21
22
23
24
|
# File 'lib/patronus_fati/message_processor.rb', line 18
def self.close_inactive_connections
DataModels::Connection.instances.each do |_, connection|
connection.announce_changes
end
DataModels::Connection.instances.reject! { |_, conn| conn.presence.dead? }
end
|
.handle(message_obj) ⇒ void
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/patronus_fati/message_processor.rb', line 44
def self.handle(message_obj)
if !PatronusFati.past_initial_flood? && @last_msg_received && (Time.now.to_f - @last_msg_received) >= 0.8
PatronusFati.past_initial_flood!
end
@last_msg_received = Time.now.to_f
periodic_flush
result = factory(class_to_name(message_obj), message_obj)
cleanup_models
result
rescue => e
PatronusFati.logger.error('Error processing the following message object:')
PatronusFati.logger.error(message_obj.inspect)
PatronusFati.logger.error('%s: %s' % [e.class, e.message])
e.backtrace.each do |l|
PatronusFati.logger.error(l)
end
nil
end
|
.ignored_types ⇒ void
66
67
68
69
|
# File 'lib/patronus_fati/message_processor.rb', line 66
def self.ignored_types
[:ack, :battery, :bssidsrc, :channel, :clisrc, :gps, :info, :kismet,
:plugin, :source, :status, :time]
end
|
.offline_access_points ⇒ void
26
27
28
29
30
31
32
33
|
# File 'lib/patronus_fati/message_processor.rb', line 26
def self.offline_access_points
DataModels::AccessPoint.instances.each do |bssid, access_point|
access_point.cleanup_ssids
access_point.announce_changes
end
DataModels::AccessPoint.instances.reject! { |_, ap| ap.presence.dead? }
end
|
.offline_clients ⇒ void
35
36
37
38
39
40
41
42
|
# File 'lib/patronus_fati/message_processor.rb', line 35
def self.offline_clients
DataModels::Client.instances.each do |_, client|
client.cleanup_probes
client.announce_changes
end
DataModels::Client.instances.reject! { |_, ap| ap.presence.dead? }
end
|
.periodic_flush ⇒ void
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/patronus_fati/message_processor.rb', line 71
def self.periodic_flush
@next_sync ||= Time.now.to_i + 300
if @next_sync <= Time.now.to_i
@next_sync = Time.now.to_i + 84600 + rand(3600)
access_points = []
clients = []
PatronusFati::DataModels::AccessPoint.instances.each do |bssid, access_point|
next unless access_point.sync_flag?(:syncedOnline)
PatronusFati.event_handler.event(:access_point, :sync, access_point.full_state, access_point.diagnostic_data)
access_points << bssid
end
PatronusFati::DataModels::Client.instances.each do |mac, client|
next unless client.sync_flag?(:syncedOnline)
PatronusFati.event_handler.event(:client, :sync, client.full_state, client.diagnostic_data)
clients << mac
end
all_online = { access_points: access_points, clients: clients }
PatronusFati.event_handler.event(:both, :sync, all_online)
end
end
|