diff --git a/app/models/ems_event.rb b/app/models/ems_event.rb index 8a674f5a279..413da44dd52 100644 --- a/app/models/ems_event.rb +++ b/app/models/ems_event.rb @@ -25,7 +25,16 @@ def self.task_final_events end def self.event_groups - ::Settings.event_handling.event_groups.to_hash + core_event_groups = ::Settings.event_handling.event_groups.to_hash + Settings.ems.each_with_object(core_event_groups) do |(_provider_type, provider_settings), event_groups| + provider_event_groups = provider_settings.fetch_path(:event_handling, :event_groups) + next unless provider_event_groups + DeepMerge.deep_merge!( + provider_event_groups.to_hash, event_groups, + :preserve_unmergeables => false, + :overwrite_arrays => false + ) + end end def self.bottleneck_event_groups diff --git a/spec/models/ems_event_spec.rb b/spec/models/ems_event_spec.rb index 75b7d9588b9..00dcc3032a6 100644 --- a/spec/models/ems_event_spec.rb +++ b/spec/models/ems_event_spec.rb @@ -198,4 +198,39 @@ end end end + + context '.event_groups' do + let(:provider_event) { 'SomeSpecialProviderEvent' } + + it 'returns a list of groups' do + event_group_names = [ + :addition, :application, :configuration, :console, :deletion, :general, :import_export, :migration, :network, + :power, :snapshot, :status, :storage + ] + expect(described_class.event_groups.keys).to match_array(event_group_names) + expect(described_class.event_groups[:addition]).to include(:name => 'Creation/Addition') + expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent') + expect(described_class.event_groups[:addition][:critical]).not_to include(provider_event) + end + + it 'returns the provider event if configured' do + stub_settings_merge( + :ems => { + :some_provider => { + :event_handling => { + :event_groups => { + :addition => { + :critical => [provider_event] + } + } + } + } + } + ) + allow(Vmdb::Plugins.instance).to receive(:registered_provider_plugin_names).and_return([:some_provider]) + + expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent') + expect(described_class.event_groups[:addition][:critical]).to include(provider_event) + end + end end diff --git a/spec/support/settings_helper.rb b/spec/support/settings_helper.rb index 8bdb3ebcf7f..7680aee75a3 100644 --- a/spec/support/settings_helper.rb +++ b/spec/support/settings_helper.rb @@ -4,6 +4,11 @@ def stub_settings(hash) allow(Vmdb::Settings).to receive(:for_resource) { settings } end +def stub_settings_merge(hash) + hash = Settings.to_hash.deep_merge(hash) + stub_settings(hash) +end + def stub_template_settings(hash) settings = Config::Options.new.merge!(hash) allow(Vmdb::Settings).to receive(:template_settings) { settings }