forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_catcher_amazon.rb
50 lines (44 loc) · 1.38 KB
/
event_catcher_amazon.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'workers/event_catcher'
require 'json'
class EventCatcherAmazon < EventCatcher
def event_monitor_handle
require 'Amazon/events/amazon_event_monitor'
unless @event_monitor_handle
aws_access_key_id = @ems.authentication_userid
aws_secret_access_key = @ems.authentication_password
aws_region = @ems.provider_region
queue_id = @ems.guid
@event_monitor_handle = AmazonEventMonitor.new(aws_access_key_id, aws_secret_access_key, aws_region, queue_id)
end
@event_monitor_handle
end
def reset_event_monitor_handle
@event_monitor_handle = nil
end
def stop_event_monitor
@event_monitor_handle.try(:stop)
ensure
reset_event_monitor_handle
end
def monitor_events
event_monitor_handle.start
event_monitor_handle.each_batch do |events|
$log.debug("#{log_prefix} Received events #{events.collect(&:message)}") if $log.debug?
@queue.enq events
sleep_poll_normal
end
ensure
reset_event_monitor_handle
end
def process_event(event)
if filtered?(event)
$log.info "#{log_prefix} Skipping filtered Amazon event [#{event["messageId"]}]"
else
$log.info "#{log_prefix} Caught event [#{event["messageId"]}]"
EmsEvent.add_queue('add_amazon', @cfg[:ems_id], event)
end
end
def filtered?(event)
filtered_events.include?(event["messageType"])
end
end