|
|
@@ -21,7 +21,7 @@ class Agent < ActiveRecord::Base
|
21
|
21
|
|
22
|
22
|
EVENT_RETENTION_SCHEDULES = [["Forever", 0], ["1 day", 1], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n] })]
|
23
|
23
|
|
24
|
|
- attr_accessible :options, :memory, :name, :type, :schedule, :source_ids, :keep_events_for, :propagate_immediately
|
|
24
|
+ attr_accessible :options, :memory, :name, :type, :schedule, :disabled, :source_ids, :keep_events_for, :propagate_immediately
|
25
|
25
|
|
26
|
26
|
json_serialize :options, :memory
|
27
|
27
|
|
|
|
@@ -97,8 +97,8 @@ class Agent < ActiveRecord::Base
|
97
|
97
|
|
98
|
98
|
def create_event(attrs)
|
99
|
99
|
if can_create_events?
|
100
|
|
- events.create!({
|
101
|
|
- :user => user,
|
|
100
|
+ events.create!({
|
|
101
|
+ :user => user,
|
102
|
102
|
:expires_at => new_event_expiration_date
|
103
|
103
|
}.merge(attrs))
|
104
|
104
|
else
|
|
|
@@ -128,7 +128,7 @@ class Agent < ActiveRecord::Base
|
128
|
128
|
if keep_events_for == 0
|
129
|
129
|
events.update_all :expires_at => nil
|
130
|
130
|
else
|
131
|
|
- events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
|
131
|
+ events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
132
|
132
|
end
|
133
|
133
|
end
|
134
|
134
|
|
|
|
@@ -257,11 +257,11 @@ class Agent < ActiveRecord::Base
|
257
|
257
|
joins("JOIN links ON (links.receiver_id = agents.id)").
|
258
|
258
|
joins("JOIN agents AS sources ON (links.source_id = sources.id)").
|
259
|
259
|
joins("JOIN events ON (events.agent_id = sources.id AND events.id > links.event_id_at_creation)").
|
260
|
|
- where("agents.last_checked_event_id IS NULL OR events.id > agents.last_checked_event_id")
|
|
260
|
+ where("NOT agents.disabled AND (agents.last_checked_event_id IS NULL OR events.id > agents.last_checked_event_id)")
|
261
|
261
|
if options[:only_receivers].present?
|
262
|
262
|
scope = scope.where("agents.id in (?)", options[:only_receivers])
|
263
|
263
|
end
|
264
|
|
-
|
|
264
|
+
|
265
|
265
|
sql = scope.to_sql()
|
266
|
266
|
|
267
|
267
|
agents_to_events = {}
|
|
|
@@ -292,6 +292,7 @@ class Agent < ActiveRecord::Base
|
292
|
292
|
def async_receive(agent_id, event_ids)
|
293
|
293
|
agent = Agent.find(agent_id)
|
294
|
294
|
begin
|
|
295
|
+ return if agent.disabled?
|
295
|
296
|
agent.receive(Event.where(:id => event_ids))
|
296
|
297
|
agent.last_receive_at = Time.now
|
297
|
298
|
agent.save!
|
|
|
@@ -316,7 +317,8 @@ class Agent < ActiveRecord::Base
|
316
|
317
|
# per type of agent, so you can override this to define custom bulk check behavior for your custom Agent type.
|
317
|
318
|
def bulk_check(schedule)
|
318
|
319
|
raise "Call #bulk_check on the appropriate subclass of Agent" if self == Agent
|
319
|
|
- where(:schedule => schedule).pluck("agents.id").each do |agent_id|
|
|
320
|
+ where(:schedule => schedule).pluck("agents.id", "agents.disabled").each do |agent_id, agent_disabled|
|
|
321
|
+ return if agent_disabled
|
320
|
322
|
async_check(agent_id)
|
321
|
323
|
end
|
322
|
324
|
end
|
|
|
@@ -329,6 +331,7 @@ class Agent < ActiveRecord::Base
|
329
|
331
|
def async_check(agent_id)
|
330
|
332
|
agent = Agent.find(agent_id)
|
331
|
333
|
begin
|
|
334
|
+ return if agent.disabled?
|
332
|
335
|
agent.check
|
333
|
336
|
agent.last_check_at = Time.now
|
334
|
337
|
agent.save!
|