-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsing physical_swtich_id and physical_chassis_id into events
- Loading branch information
Showing
2 changed files
with
115 additions
and
47 deletions.
There are no files selected for viewing
93 changes: 60 additions & 33 deletions
93
app/models/manageiq/providers/lenovo/physical_infra_manager/event_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,65 @@ | ||
module ManageIQ::Providers::Lenovo::PhysicalInfraManager::EventParser | ||
def self.event_to_hash(data, ems_id) | ||
event = filter_data(data) | ||
event_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 | ||
} | ||
event_hash | ||
end | ||
CHASSIS = 'Chassis'.freeze | ||
SERVER = %w(Node Power Processor System).freeze | ||
SWITCH = 'Switch'.freeze | ||
|
||
def self.filter_data(data) | ||
{ | ||
:component_id => data.componentID, | ||
:component_type => data.typeText, | ||
:event_type => data.msgID, | ||
:ems_ref => data.cn, | ||
:message => data.msg, | ||
:parent_uuid => data.senderUUID, | ||
:parent_name => data.systemName, | ||
:parent_model => data.systemTypeModelText, | ||
:parent_type => data.systemTypeText, | ||
:severity_id => data.severity, | ||
:severity => data.severityText, | ||
:source => 'LenovoXclarity', | ||
:timestamp => data.timeStamp, | ||
} | ||
end | ||
class << self | ||
def event_to_hash(data, ems_id) | ||
event = filter_data(data) | ||
event_hash = { | ||
:event_type => event[:event_type], | ||
:ems_ref => event[:ems_ref], | ||
:source => event[:source], | ||
:message => event[:message], | ||
:timestamp => event[:timestamp], | ||
:full_data => event, | ||
:ems_id => ems_id | ||
} | ||
|
||
event_hash.merge!(event_resources(event)) | ||
end | ||
|
||
def filter_data(data) | ||
{ | ||
:component_id => data.componentID, | ||
:component_type => data.typeText, | ||
:event_type => data.msgID, | ||
:ems_ref => data.cn, | ||
:message => data.msg, | ||
:parent_uuid => data.sourceID, | ||
:parent_name => data.systemName, | ||
:parent_model => data.systemTypeModelText, | ||
:parent_type => data.systemTypeText, | ||
:severity_id => data.severity, | ||
:severity => data.severityText, | ||
:source => 'LenovoXclarity', | ||
:timestamp => data.timeStamp, | ||
} | ||
end | ||
|
||
|
||
private | ||
|
||
def event_resources(event) | ||
event_resources = {} | ||
|
||
if event[:parent_type] == CHASSIS | ||
event_resources[:physical_chassis_id] = get_resource_id(PhysicalChassis, event[:parent_uuid]) | ||
end | ||
|
||
if event[:component_type] == SWITCH | ||
event_resources[:physical_switch_id] = get_resource_id(PhysicalSwitch, event[:component_id]) | ||
elsif SERVER.include?(event[:component_type]) | ||
event_resources[:physical_server_id] = get_resource_id(PhysicalServer, event[:component_id]) | ||
else | ||
$log.error("The event of type #{event[:component_type]} is not supported") | ||
end | ||
|
||
event_resources | ||
end | ||
|
||
def self.get_physical_server_id(ems_ref) | ||
PhysicalServer.find_by(:ems_ref => ems_ref).try(:id) | ||
def get_resource_id(resource, uid_ems) | ||
resource.find_by(:uid_ems => uid_ems).try(:id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters