diff --git a/app/models/manageiq/providers/openstack/cloud_manager/event_parser.rb b/app/models/manageiq/providers/openstack/cloud_manager/event_parser.rb index 1c558d6da..ebb4e8294 100644 --- a/app/models/manageiq/providers/openstack/cloud_manager/event_parser.rb +++ b/app/models/manageiq/providers/openstack/cloud_manager/event_parser.rb @@ -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 diff --git a/app/models/manageiq/providers/openstack/infra_manager/event_parser.rb b/app/models/manageiq/providers/openstack/infra_manager/event_parser.rb index d17645756..6a97e2bb2 100644 --- a/app/models/manageiq/providers/openstack/infra_manager/event_parser.rb +++ b/app/models/manageiq/providers/openstack/infra_manager/event_parser.rb @@ -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 @@ -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 diff --git a/app/models/manageiq/providers/openstack/network_manager/event_parser.rb b/app/models/manageiq/providers/openstack/network_manager/event_parser.rb index 19338498c..ad88548b9 100644 --- a/app/models/manageiq/providers/openstack/network_manager/event_parser.rb +++ b/app/models/manageiq/providers/openstack/network_manager/event_parser.rb @@ -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 diff --git a/spec/models/manageiq/providers/openstack/infra_manager/event_parser_spec.rb b/spec/models/manageiq/providers/openstack/infra_manager/event_parser_spec.rb index 8d85eda7d..348f14cec 100644 --- a/spec/models/manageiq/providers/openstack/infra_manager/event_parser_spec.rb +++ b/spec/models/manageiq/providers/openstack/infra_manager/event_parser_spec.rb @@ -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", @@ -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", @@ -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", @@ -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", @@ -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) @@ -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", @@ -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,