Skip to content

Commit

Permalink
Use Host#uid_ems to link host records to ems_events
Browse files Browse the repository at this point in the history
If we are unable to find the host by ems_ref attempt to use the
host_uid_ems attribute
  • Loading branch information
agrare committed Jul 9, 2020
1 parent bd464aa commit dc7c10e
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
@@ -90,7 +90,17 @@ def self.process_vm_in_event!(event, options = {})
end

def self.process_host_in_event!(event, options = {})
uid_ems = event.delete(:host_uid_ems)
process_object_in_event!(Host, event, options)

if event[:host_id].nil? && uid_ems.present?
# Attempt to find a host in the current EMS first, then fallback to archived hosts
host = Host.find_by(:ems_id => event[:ems_id], :uid_ems => uid_ems) || Host.find_by(:ems_id => nil, :uid_ems => uid_ems)
unless host.nil?
event[:host_id] = host.id
event[:host_name] ||= host.name
end
end
end

def self.process_container_entities_in_event!(event, _options = {})
28 changes: 28 additions & 0 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
@@ -275,6 +275,34 @@
end
end
end

context "with a host" do
let(:event) do
{
:ems_id => ems.id,
:event_type => "HostAddEvent",
:host_uid_ems => host.uid_ems
}
end

context "with an active host" do
let(:host) { FactoryBot.create(:host, :uid_ems => "6f3fa3f1-bbe0-4aab-9a69-5d652324357f", :ext_management_system => ems) }

it "should link the event to the host" do
ems_event = described_class.add(ems.id, event)
expect(ems_event.host).to eq(host)
end
end

context "with an archived host" do
let(:host) { FactoryBot.create(:host, :uid_ems => "6f3fa3f1-bbe0-4aab-9a69-5d652324357f") }

it "should link the event to the host" do
ems_event = described_class.add(ems.id, event)
expect(ems_event.host).to eq(host)
end
end
end
end

context '.event_groups' do

0 comments on commit dc7c10e

Please sign in to comment.