From 35935f5ff2f5c5e8baff5c0e6031380d6540113a Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 20 Nov 2024 12:50:56 -0500 Subject: [PATCH] Parse the event url with Regex not split --- .../infra_manager/event_target_parser.rb | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb b/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb index 97119d2b..f2a6ad98 100644 --- a/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb +++ b/app/models/manageiq/providers/ibm_power_hmc/infra_manager/event_target_parser.rb @@ -20,35 +20,35 @@ def parse case ems_event.event_type when "MODIFY_URI", "ADD_URI", "DELETE_URI" # Damien: INVALID_URI? $ibm_power_hmc_log.info("#{self.class}##{__method__} #{ems_event.event_type} #{ems_event.full_data}") - elems = elem(raw_event[:data]) - case elems[:type] + elems = raw_event[:data].match(/^.+\/rest\/api\/uom\/(ManagedSystem\/(?.+)\/)*(?.+)\/(?.+)$/).named_captures + case elems["type"] when "ManagedSystem" - new_targets << {:assoc => :hosts, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :hosts, :ems_ref => elems["uuid"]} when "LogicalPartition", "VirtualIOServer" # raw_event[:detail] contains information about the properties that # have changed (e.g. RMCState, PartitionName, PartitionState etc...) # This may be used to perform quick property REST API calls to the HMC # instead of querying the full LPAR data. - if elems[:uuid] == NO_UUID_VALUE - $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems[:type]} Missing LPAR UUID. Escalating to full refresh for EMS: [#{ems.name}], id: [#{ems.id}].") + if elems["uuid"] == NO_UUID_VALUE + $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems["type"]} Missing LPAR UUID. Escalating to full refresh for EMS: [#{ems.name}], id: [#{ems.id}].") target_collection << ems else - new_targets << {:assoc => :vms, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :vms, :ems_ref => elems["uuid"]} end when "VirtualSwitch", "VirtualNetwork" - if elems.key?(:manager_uuid) - new_targets << {:assoc => :hosts, :ems_ref => elems[:manager_uuid]} + if elems["manager_uuid"] + new_targets << {:assoc => :hosts, :ems_ref => elems["manager_uuid"]} end when "UserTask" new_targets.concat(handle_usertask(raw_event[:usertask])) when "Cluster" - new_targets << {:assoc => :storages, :ems_ref => elems[:uuid]} + new_targets << {:assoc => :storages, :ems_ref => elems["uuid"]} when "SharedProcessorPool", "SharedMemoryPool" - new_targets << {:assoc => :resource_pools, :ems_ref => "#{elems[:manager_uuid]}_#{elems[:uuid]}"} + new_targets << {:assoc => :resource_pools, :ems_ref => "#{elems["manager_uuid"]}_#{elems["uuid"]}"} end new_targets.each do |t| - $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems[:type]} uuid #{t[:ems_ref]}") + $ibm_power_hmc_log.info("#{self.class}##{__method__} #{elems["type"]} uuid #{t[:ems_ref]}") target_collection.add_target( :association => t[:assoc], :manager_ref => {:ems_ref => t[:ems_ref]} @@ -63,19 +63,6 @@ def parse private - def elem(url) - uri = URI(url) - tokens = uri.path.split('/') - elems = { - :type => tokens[-2], - :uuid => tokens[-1] - } - if tokens.length >= 4 && tokens[-4] == "ManagedSystem" - elems[:manager_uuid] = tokens[-3] - end - elems - end - def handle_usertask(usertask) return [] unless usertask["status"].eql?("Completed")