Skip to content

Commit

Permalink
update event parser code to deal with amqp messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tzumainn committed Oct 23, 2017
1 parent 70f054c commit e449d86
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
module ManageIQ::Providers::Openstack::CloudManager::EventParser
def self.event_to_hash(event, ems_id)
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]")

_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug?

# attributes that are common to all notifications
event_hash = {
:event_type => event[:content]["event_type"],
:event_type => event_type,
:source => "OPENSTACK",
:message => event[:payload],
:timestamp => event[:content]["timestamp"],
:username => event[:content]["_context_user_name"],
:message => payload,
:timestamp => content["timestamp"],
:username => content["_context_user_name"],
:full_data => event,
:ems_id => ems_id
}

payload = event[:content]["payload"]

event_hash[:vm_ems_ref] = payload["instance_id"] if payload.key? "instance_id"
event_hash[:host_ems_ref] = payload["host"] if payload.key? "host"
event_hash[:availability_zone_ems_ref] = payload["availability_zone"] if payload.key? "availability_zone"
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id"
event_hash
end

def self.message_content(event, ems_id)
unless ems_id.nil?
ems = ExtManagementSystem.find_by_id(ems_id)
if ems.connection_configuration_by_role("amqp")
JSON.parse(event[:content]["oslo.message"])
end
end
event[:content]
end
end
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
module ManageIQ::Providers::Openstack::InfraManager::EventParser
def self.event_to_hash(event, ems_id)
log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]") if $log && $log.debug?
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?
_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug?

# attributes that are common to all notifications
event_hash = {
:event_type => event[:content]["event_type"],
:event_type => event_type,
:source => "OPENSTACK",
:message => event[:payload],
:timestamp => event[:content]["timestamp"],
:username => event[:content]["_context_user_name"],
:message => payload,
:timestamp => content["timestamp"],
:username => content["_context_user_name"],
:full_data => event,
:ems_id => ems_id
}

payload = event[:content]["payload"]

if payload.key? "instance_id"
event_hash[:host_id] = Host.find_by("ems_ref_obj" => YAML.dump(payload["instance_id"])).try(:id)
end
Expand All @@ -25,4 +27,14 @@ def self.event_to_hash(event, ems_id)
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id"
event_hash
end

def self.message_content(event, ems_id)
unless ems_id.nil?
ems = ExtManagementSystem.find_by_id(ems_id)
if ems.connection_configuration_by_role("amqp")
JSON.parse(event[:content]["oslo.message"])
end
end
event[:content]
end
end
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
module ManageIQ::Providers::Openstack::NetworkManager::EventParser
def self.event_to_hash(event, ems_id)
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]")

_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug?

# attributes that are common to all notifications
event_hash = {
:event_type => event[:content]["event_type"],
:event_type => event_type,
:source => "OPENSTACK",
:message => event[:payload],
:timestamp => event[:content]["timestamp"],
:username => event[:content]["_context_user_name"],
:message => payload,
:timestamp => content["timestamp"],
:username => content["_context_user_name"],
:full_data => event,
:ems_id => ems_id
}

payload = event[:content]["payload"]

event_hash[:vm_ems_ref] = payload["instance_id"] if payload.key? "instance_id"
event_hash[:host_ems_ref] = payload["host"] if payload.key? "host"
event_hash[:availability_zone_ems_ref] = payload["availability_zone"] if payload.key? "availability_zone"
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id"
event_hash
end

def self.message_content(event, ems_id)
unless ems_id.nil?
ems = ExtManagementSystem.find_by_id(ems_id)
if ems.connection_configuration_by_role("amqp")
JSON.parse(event[:content]["oslo.message"])
end
end
event[:content]
end
end

0 comments on commit e449d86

Please sign in to comment.