-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update event parser code to deal with amqp messages
- Loading branch information
Showing
3 changed files
with
63 additions
and
27 deletions.
There are no files selected for viewing
30 changes: 21 additions & 9 deletions
30
app/models/manageiq/providers/openstack/cloud_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,25 +1,37 @@ | ||
module ManageIQ::Providers::Openstack::CloudManager::EventParser | ||
def self.event_to_hash(event, ems_id) | ||
content = message_content(event, ems_id) | ||
event_type = content["event_type"] | ||
payload = content["payload"] | ||
|
||
log_header = "ems_id: [#{ems_id}] " unless ems_id.nil? | ||
|
||
_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]") | ||
|
||
_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug? | ||
|
||
# attributes that are common to all notifications | ||
event_hash = { | ||
:event_type => event[:content]["event_type"], | ||
:event_type => event_type, | ||
:source => "OPENSTACK", | ||
:message => event[:payload], | ||
:timestamp => event[:content]["timestamp"], | ||
:username => event[:content]["_context_user_name"], | ||
:message => payload, | ||
:timestamp => content["timestamp"], | ||
:username => content["_context_user_name"], | ||
:full_data => event, | ||
:ems_id => ems_id | ||
} | ||
|
||
payload = event[:content]["payload"] | ||
|
||
event_hash[:vm_ems_ref] = payload["instance_id"] if payload.key? "instance_id" | ||
event_hash[:host_ems_ref] = payload["host"] if payload.key? "host" | ||
event_hash[:availability_zone_ems_ref] = payload["availability_zone"] if payload.key? "availability_zone" | ||
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id" | ||
event_hash | ||
end | ||
|
||
def self.message_content(event, ems_id) | ||
unless ems_id.nil? | ||
ems = ExtManagementSystem.find_by_id(ems_id) | ||
if ems.connection_configuration_by_role("amqp") | ||
JSON.parse(event[:content]["oslo.message"]) | ||
end | ||
end | ||
event[:content] | ||
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
30 changes: 21 additions & 9 deletions
30
app/models/manageiq/providers/openstack/network_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,25 +1,37 @@ | ||
module ManageIQ::Providers::Openstack::NetworkManager::EventParser | ||
def self.event_to_hash(event, ems_id) | ||
content = message_content(event, ems_id) | ||
event_type = content["event_type"] | ||
payload = content["payload"] | ||
|
||
log_header = "ems_id: [#{ems_id}] " unless ems_id.nil? | ||
|
||
_log.debug("#{log_header}event: [#{event[:content]["event_type"]}]") | ||
|
||
_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug? | ||
|
||
# attributes that are common to all notifications | ||
event_hash = { | ||
:event_type => event[:content]["event_type"], | ||
:event_type => event_type, | ||
:source => "OPENSTACK", | ||
:message => event[:payload], | ||
:timestamp => event[:content]["timestamp"], | ||
:username => event[:content]["_context_user_name"], | ||
:message => payload, | ||
:timestamp => content["timestamp"], | ||
:username => content["_context_user_name"], | ||
:full_data => event, | ||
:ems_id => ems_id | ||
} | ||
|
||
payload = event[:content]["payload"] | ||
|
||
event_hash[:vm_ems_ref] = payload["instance_id"] if payload.key? "instance_id" | ||
event_hash[:host_ems_ref] = payload["host"] if payload.key? "host" | ||
event_hash[:availability_zone_ems_ref] = payload["availability_zone"] if payload.key? "availability_zone" | ||
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id" | ||
event_hash | ||
end | ||
|
||
def self.message_content(event, ems_id) | ||
unless ems_id.nil? | ||
ems = ExtManagementSystem.find_by_id(ems_id) | ||
if ems.connection_configuration_by_role("amqp") | ||
JSON.parse(event[:content]["oslo.message"]) | ||
end | ||
end | ||
event[:content] | ||
end | ||
end |