Skip to content

Commit

Permalink
Merge pull request #127 from tzumainn/amqp-message-support
Browse files Browse the repository at this point in the history
update event parser code to deal with amqp messages
  • Loading branch information
mansam authored Oct 24, 2017
2 parents a263778 + 29c4339 commit 3692df0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 30 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)
log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]")
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"]
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?
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]") if $log && $log.debug?
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)
log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"]

_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]")
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"]
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
Expand Up @@ -2,7 +2,7 @@
context ".event_to_hash" do
it "with a compute.instance.create.end event" do
event = YAML.load_file(File.join(data_dir, 'compute_instance_create_end.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "compute.instance.create.end",
Expand All @@ -20,7 +20,7 @@

it "with a compute.instance.create.error event" do
event = YAML.load_file(File.join(data_dir, 'compute_instance_create_error.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "compute.instance.create.error",
Expand All @@ -40,7 +40,7 @@

it "with an orchestration.stack.create.end event" do
event = YAML.load_file(File.join(data_dir, 'orchestration_stack_create_end.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "orchestration.stack.create.end",
Expand All @@ -54,7 +54,7 @@

it "with an orchestration.stack.update.end event" do
event = YAML.load_file(File.join(data_dir, 'orchestration_stack_update_end.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "orchestration.stack.update.end",
Expand All @@ -68,11 +68,11 @@

it "with a port.create.end event" do
event = YAML.load_file(File.join(data_dir, 'port_create_end.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "port.create.end",
:timestamp => "2015-05-12 07:22:37.008738"
:timestamp => "2015-05-12 07:22:37.008738",
)

expect(data).to have_attributes(expected_attributes)
Expand All @@ -82,7 +82,7 @@

it "with a port.update.end event" do
event = YAML.load_file(File.join(data_dir, 'port_update_end.yml'))
data = described_class.event_to_hash(event, 123)
data = described_class.event_to_hash(event, nil)

expected_attributes = common_attributes(event).merge(
:event_type => "port.update.end",
Expand All @@ -105,10 +105,9 @@ def common_attributes(event)
:chain_id => nil,
:is_task => nil,
:source => "OPENSTACK",
:message => nil,
:timestamp => nil,
:full_data => event,
:ems_id => 123,
:ems_id => nil,
:username => nil,
:vm_ems_ref => nil,
:vm_name => nil,
Expand Down

0 comments on commit 3692df0

Please sign in to comment.