From e0a5d203295751e9126748bf09f4a83b45479bcb Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Fri, 15 May 2020 10:44:03 -0400 Subject: [PATCH] Add ems_uid and ems_type to event payload The Event payload already containes the ems_id, we can add the ems_type and ems_uid to assist in identifying the source provider without having to hit the MIQ API Fixes https://github.com/ManageIQ/manageiq/issues/20178 --- app/models/ems_event.rb | 26 ++++++++++++++++++-------- spec/models/ems_event_spec.rb | 10 ++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/models/ems_event.rb b/app/models/ems_event.rb index 560e34a05db..f6b94ff9417 100644 --- a/app/models/ems_event.rb +++ b/app/models/ems_event.rb @@ -25,14 +25,7 @@ def self.bottleneck_event_groups end def self.add_queue(meth, ems_id, event) - unless MiqQueue.messaging_type == "miq_queue" - MiqQueue.messaging_client('event_handler')&.publish_topic( - :service => "manageiq.ems-events", - :sender => ems_id, - :event => event[:event_type], - :payload => event - ) - end + publish_event(ems_id, event) MiqQueue.submit_job( :service => "event", @@ -258,6 +251,23 @@ def self.create_completed_event(event, orig_task = nil) private_class_method :create_completed_event + def self.publish_event(ems_id, event) + return if MiqQueue.messaging_type == "miq_queue" + + ems = ExtManagementSystem.find(ems_id) + event[:ems_uid] = ems&.uid_ems + event[:ems_type] = ems&.class&.ems_type + + MiqQueue.messaging_client('event_handler')&.publish_topic( + :service => "manageiq.ems-events", + :sender => ems_id, + :event => event[:event_type], + :payload => event + ) + end + + private_class_method :publish_event + def get_refresh_target(target_type) m = "#{target_type}_refresh_target" try(m) diff --git a/spec/models/ems_event_spec.rb b/spec/models/ems_event_spec.rb index 7a09e754aa2..926b36f8669 100644 --- a/spec/models/ems_event_spec.rb +++ b/spec/models/ems_event_spec.rb @@ -130,7 +130,10 @@ :service => "manageiq.ems-events", :sender => ems.id, :event => event_hash[:event_type], - :payload => event_hash, + :payload => event_hash.merge( + :ems_type => ems.class.ems_type, + :ems_uid => ems.uid_ems + ) } expect(messaging_client).to receive(:publish_topic).with(expected_queue_payload) @@ -150,7 +153,10 @@ :service => "manageiq.ems-events", :sender => ems.id, :event => event_hash[:event_type], - :payload => event_hash, + :payload => event_hash.merge( + :ems_type => ems.class.ems_type, + :ems_uid => ems.uid_ems + ) } expect(messaging_client).to receive(:publish_topic).with(expected_queue_payload)