From 2b1dda57523e9a31c057a4df3e3ac999110b12a0 Mon Sep 17 00:00:00 2001 From: Charlle Dias Date: Wed, 23 May 2018 11:02:49 -0300 Subject: [PATCH] Cleaning of the data persited in the full_data columm --- .../event_catcher/event.rb | 24 +++++++++++++++++++ .../event_catcher/stream.rb | 15 ++++++++---- .../physical_infra_manager/event_parser.rb | 14 +++++------ .../event_catcher/stream_spec.rb | 2 +- .../event_parser_spec.rb | 5 +++- 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/event.rb diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/event.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/event.rb new file mode 100644 index 0000000000..64c108cf87 --- /dev/null +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/event.rb @@ -0,0 +1,24 @@ +class ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Event + + def initialize(data) + @data = data + end + + def to_hash + { + :event_type => @data.msgID, + :ems_ref => @data.cn, + :source => "LenovoXclarity", + :message => @data.msg, + :timestamp => @data.timeStamp, + :component_id => @data.componentID, + :severity => @data.severity, + :severity_type => @data.severityText, + :sender_uuid => @data.senderUUID, + :sender_name => @data.systemName, + :sender_model => @data.systemTypeModelText, + :sender_type => @data.systemTypeText, + :type => @data.typeText + } + end +end \ No newline at end of file diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream.rb index f6d2331a89..5744c13d98 100755 --- a/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream.rb +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream.rb @@ -15,7 +15,7 @@ def stop def each_batch $log.info('Starting collect of LXCA events ...') while @collect_events - yield(events.collect { |e| ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser.event_to_hash(e, @ems.id) }) + yield(parse_events(events)) end $log.info('Stopping collect of LXCA events ...') end @@ -27,12 +27,19 @@ def filter_fields { :operation => 'NOT', :field => 'eventClass', :value => '200' }, { :operation => 'NOT', :field => 'eventClass', :value => '800' } ] - last_cn_event = get_last_cnn_from_events(@ems.id) + last_cn_event = get_last_ems_ref(@ems.id) cn_operation = { :operation => 'GT', :field => 'cn', :value => last_cn_event.to_s } fields.push(cn_operation) unless last_cn_event.nil? fields end + def parse_events(events) + events.collect do |data| + event = ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Event.new(data).to_hash + ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser.event_to_hash(event, @ems.id) + end + end + def events expression = { :filterType => 'FIELDNOTREGEXAND', :fields => filter_fields } @@ -54,7 +61,7 @@ def create_event_connection(ems) :port => ems.endpoints.first.port) end - def get_last_cnn_from_events(ems_id) - EventStream.where(:ems_id => ems_id).maximum('ems_ref') || 1 + def get_last_ems_ref(ems_id) + EventStream.where(:ems_id => ems_id).maximum('CAST(ems_ref AS int)') || 1 end end diff --git a/app/models/manageiq/providers/lenovo/physical_infra_manager/event_parser.rb b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_parser.rb index c09bd251bd..b4b1357058 100755 --- a/app/models/manageiq/providers/lenovo/physical_infra_manager/event_parser.rb +++ b/app/models/manageiq/providers/lenovo/physical_infra_manager/event_parser.rb @@ -1,13 +1,13 @@ module ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser def self.event_to_hash(event, ems_id) event_hash = { - :event_type => event.msgID, - :ems_ref => event.cn, - :source => "LenovoXclarity", - :physical_server_id => get_physical_server_id(event.componentID), - :message => event.msg, - :timestamp => event.timeStamp, - :full_data => event.to_hash, + :event_type => event[:event_type], + :ems_ref => event[:ems_ref], + :source => event[:source], + :physical_server_id => get_physical_server_id(event[:component_id]), + :message => event[:message], + :timestamp => event[:timestamp], + :full_data => event, :ems_id => ems_id } diff --git a/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream_spec.rb b/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream_spec.rb index 98573a36cb..d720877d9b 100644 --- a/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream_spec.rb +++ b/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_catcher/stream_spec.rb @@ -22,7 +22,7 @@ expect($log).to receive(:info).with(/Stopping collect of LXCA events .../) end expect(result.count).to be == 20 - expect(result.all? { |item| item[:full_data]['eventClass'] == 400 }).to be true + expect(result.all? { |item| item[:full_data]['severity'] == 200 }).to be true end end end diff --git a/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_parser_spec.rb b/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_parser_spec.rb index d3aad188d1..08d8fe05b9 100644 --- a/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_parser_spec.rb +++ b/spec/models/manageiq/providers/lenovo/physical_infra_manager/event_parser_spec.rb @@ -13,7 +13,10 @@ } end - let(:event1) { XClarityClient::Event.new(event_attrs1) } + let(:event1) do + data = XClarityClient::Event.new(event_attrs1) + ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventCatcher::Event.new(data).to_hash + end it 'will parse events' do event_hash = described_class.event_to_hash(event1, 3)