Skip to content

Commit

Permalink
Cleaning of the data persited in the full_data columm
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlleDaniel committed May 23, 2018
1 parent 8a1b36d commit 412987a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }

Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 412987a

Please sign in to comment.