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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/patronus_fati/message_processor.rb', line 70
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
report_recently_seen
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
93
94
95
96
|
# File 'lib/patronus_fati/message_processor.rb', line 93
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/patronus_fati/message_processor.rb', line 98
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.active?
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.active?
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
|
.report_recently_seen ⇒ void
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/patronus_fati/message_processor.rb', line 44
def self.report_recently_seen
@next_recent_msg ||= Time.now.to_i + 240
if @next_recent_msg <= Time.now.to_i
@next_recent_msg = Time.now.to_i + 240
cutoff_time = Time.now.to_i - 300
aps = DataModels::AccessPoint.instances.map do |bssid, ap|
next unless ap.active? && ap.presence.visible_since?(cutoff_time)
bssid
end.compact
clients = DataModels::Client.instances.map do |mac, client|
next unless client.active? && client.presence.visible_since?(cutoff_time)
mac
end.compact
return if clients.empty? && aps.empty?
PatronusFati.event_handler.event(
:sync,
:recent,
{ access_points: aps, clients: clients }
)
end
end
|