37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/sqspoller/handlers/puppetsdb.rb', line 37
def process(queue_name, msg, conf)
@queue_name = queue_name
domain = conf['domain']
template_map = conf['template_map']
begin
sns_msg = msg.as_sns_message
sns_msg_data = sns_msg.to_h
sns_msg_body = JSON.load(sns_msg_data[:body])
rescue
SQSPoller.warn("#{@queue_name}: Message is not a properly formatted SNS message")
return
end
msg_id = sns_msg.message_id
instance_id = sns_msg_body['EC2InstanceId']
event_type = sns_msg_body['Event']
autoscale_name = sns_msg_body['AutoScalingGroupName']
reference_node = template_map[autoscale_name]
SQSPoller.debug("#{@queue_name}: Found message '#{msg_id}'")
SQSPoller.debug("#{@queue_name}: Processing event '#{event_type}' for autoscaling group '#{autoscale_name}' and instance-id #{instance_id}")
(SQSPoller.warn("#{@queue_name}: Unregistered autoscaling group: #{autoscale_name}"); return) if reference_node.nil?
@puppet_enc = PuppetSDB::PuppetSDB.new(:domain => domain)
case event_type
when "autoscaling:EC2_INSTANCE_LAUNCH"
add_node_from_ref(reference_node, instance_id, autoscale_name)
when "autoscaling:EC2_INSTANCE_TERMINATE"
del_node(instance_id, autoscale_name)
end
end
|